Introduce Booths for admin
This commit is contained in:
parent
29aee82a14
commit
f7c0b64eb5
22 changed files with 534 additions and 1 deletions
|
|
@ -120,6 +120,7 @@ class AdminAbility
|
|||
commercialable_id: conf_ids
|
||||
can :manage, Registration, conference_id: conf_ids
|
||||
can :manage, RegistrationPeriod, conference_id: conf_ids
|
||||
can :manage, Booth, conference_id: conf_ids
|
||||
can :manage, Question, conference_id: conf_ids
|
||||
can :manage, Question do |question|
|
||||
!(question.conferences.pluck(:id) & conf_ids).empty?
|
||||
|
|
@ -170,6 +171,7 @@ class AdminAbility
|
|||
conf_ids_for_cfp.include?(conf.id)
|
||||
end
|
||||
can [:index, :show, :update], Resource, conference_id: conf_ids_for_cfp
|
||||
can :manage, Booth, conference_id: conf_ids_for_cfp
|
||||
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, EventType, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, Track, program: { conference_id: conf_ids_for_cfp }
|
||||
|
|
|
|||
75
app/models/booth.rb
Normal file
75
app/models/booth.rb
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
class Booth < ActiveRecord::Base
|
||||
include ActiveRecord::Transitions
|
||||
|
||||
belongs_to :conference
|
||||
has_many :booth_requests, dependent: :destroy
|
||||
has_many :users, through: :booth_requests
|
||||
|
||||
has_one :submitter_booth_user, -> { where(role: 'submitter') }, class_name: 'BoothRequest'
|
||||
has_one :submitter, through: :submitter_booth_user, source: :user
|
||||
|
||||
has_many :responsibles_booth_user, -> { where(role: 'responsible') }, class_name: 'BoothRequest'
|
||||
has_many :responsibles, through: :responsibles_booth_user, source: :user
|
||||
|
||||
validates :title,
|
||||
uniqueness: { case_sensitive: false },
|
||||
presence: true
|
||||
|
||||
validates :description,
|
||||
:reasoning,
|
||||
:state,
|
||||
:responsibles,
|
||||
:conference_id,
|
||||
:website_url,
|
||||
:submitter_relationship,
|
||||
presence: true
|
||||
|
||||
mount_uploader :picture, PictureUploader, mount_on: :logo_link
|
||||
|
||||
state_machine initial: :new do
|
||||
state :new
|
||||
state :withdrawn
|
||||
state :to_accept
|
||||
state :accepted
|
||||
state :to_reject
|
||||
state :rejected
|
||||
state :canceled
|
||||
|
||||
event :restart do
|
||||
transitions to: :new, from: [:withdrawn, :to_accept, :to_reject, :canceled]
|
||||
end
|
||||
event :withdraw do
|
||||
transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected]
|
||||
end
|
||||
event :to_accept do
|
||||
transitions to: :to_accept, from: [:new, :to_reject]
|
||||
end
|
||||
event :to_reject do
|
||||
transitions to: :to_reject, from: [:new, :to_accept]
|
||||
end
|
||||
event :accept do
|
||||
transitions to: :accepted, from: [:new, :to_accept]
|
||||
end
|
||||
event :reject do
|
||||
transitions to: :rejected, from: [:new, :to_reject]
|
||||
end
|
||||
event :cancel do
|
||||
transitions to: :canceled, from: [:accepted, :rejected]
|
||||
end
|
||||
end
|
||||
|
||||
def transition_possible?(transition)
|
||||
self.class.state_machine.events_for(current_state).include?(transition)
|
||||
end
|
||||
|
||||
def update_state(transition, _notice)
|
||||
alert = ''
|
||||
begin
|
||||
send(transition)
|
||||
save
|
||||
rescue Transitions::InvalidTransition => e
|
||||
alert = "Update state failed. #{e.message}"
|
||||
end
|
||||
alert
|
||||
end
|
||||
end
|
||||
9
app/models/booth_request.rb
Normal file
9
app/models/booth_request.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class BoothRequest < ActiveRecord::Base
|
||||
belongs_to :booth
|
||||
belongs_to :user
|
||||
|
||||
validates :role,
|
||||
presence: true
|
||||
|
||||
ROLES = %w[submitter responsible].freeze
|
||||
end
|
||||
|
|
@ -28,6 +28,7 @@ class Conference < ActiveRecord::Base
|
|||
has_many :supporters, through: :ticket_purchases, source: :user
|
||||
has_many :tickets, dependent: :destroy
|
||||
has_many :resources, dependent: :destroy
|
||||
has_many :booths, dependent: :destroy
|
||||
|
||||
has_many :lodgings, dependent: :destroy
|
||||
has_many :registrations, dependent: :destroy
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ class User < ActiveRecord::Base
|
|||
has_many :voted_events, through: :votes, source: :events
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
has_many :tracks, foreign_key: 'submitter_id'
|
||||
has_many :booth_requests
|
||||
has_many :booth_requests, dependent: :destroy
|
||||
has_many :booths, through: :booth_requests
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
scope :admin, -> { where(is_admin: true) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue