Module: Spotlight::Ability

Includes:
CanCan::Ability
Included in:
Ability
Defined in:
app/models/spotlight/ability.rb

Instance Method Summary collapse

Instance Method Details

#initialize(user) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/spotlight/ability.rb', line 4

def initialize(user)
  user ||= ::User.new
  
  # This is the "right" way to do it. But it doesn't work in rails 4
  # until this PR is merged: https://github.com/ryanb/cancan/pull/917
  # can :create, Spotlight::Exhibit, admin_roles: { id: user.role_ids } 
  # Until then, workaround:

  # exhibit admin 
  can :manage, Spotlight::Exhibit, id: user.admin_roles.map(&:exhibit_id)
  can :manage, [Spotlight::Role], exhibit_id: user.admin_roles.map(&:exhibit_id)

  # exhibit curator
  can :manage, [
    Spotlight::Search,
    Spotlight::Page,
    Spotlight::BlacklightConfiguration,
    Spotlight::Contact,
    Spotlight::CustomField], exhibit_id: user.roles.map(&:exhibit_id)

  can [:curate, :tag], Spotlight::Exhibit, id: user.roles.map(&:exhibit_id)

  # public
  can [:read, :index], [Spotlight::Exhibit, Spotlight::Page, Spotlight::Search]

end