Module: DmEvent::Concerns::Ability

Defined in:
app/models/dm_event/concerns/ability.rb

Instance Method Summary collapse

Instance Method Details

#dm_event_abilities(user) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/dm_event/concerns/ability.rb', line 14

def dm_event_abilities(user)
  if user
    # an `event_manager` gets access to all workshops, registration, and finances.
    if user.has_role?(:event_manager)
      can :manage_events, :all
      can :manage_event_registrations, :all
      can :manage_event_finances, :all
      can :access_event_section, :all
      can :list_events, :all
      # can :access_media_library, :all
      can :access_admin, :all
    elsif user.has_role?(:event_manager_alacarte)
      # allowed to access the backend event section
      can :access_event_section, :all
      can :access_admin, :all

      # can edit a workshop, including workshop prices and email templates
      # (does not include access to registrations or finances)
      manage_event_ids = @user_roles.select {|r| r.name == 'manage_event' && r.resource_type == 'Workshop'}.map(&:resource_id)
      can :manage_events, Workshop, id: manage_event_ids
      # can(:access_media_library, :all) unless manage_event_ids.empty?
      
      # can see and manage a workshops registrations
      manage_event_registration_ids = @user_roles.select {|r| r.name == 'manage_event_registration' && r.resource_type == 'Workshop'}.map(&:resource_id)
      can :manage_event_registrations, Workshop, id: manage_event_registration_ids

      # can see and manage a workshops finances
      manage_event_finance_ids = @user_roles.select {|r| r.name == 'manage_event_finance' && r.resource_type == 'Workshop'}.map(&:resource_id)
      can :manage_event_finances, Workshop, id: manage_event_finance_ids
      
      can :list_events, Workshop, id: (manage_event_ids + manage_event_registration_ids + manage_event_finance_ids).uniq
    end

  end
end