Class: ActionRole

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/action_role.rb

Class Method Summary collapse

Class Method Details

.assign_developer_accessObject



17
18
19
20
21
22
# File 'app/models/action_role.rb', line 17

def self.assign_developer_access
  developer_id = Role.developer_id
  Action.all.each do |a|
    find_or_create_by_action_id_and_role_id(a.id, developer_id)
  end if developer_id
end

.bootstrap_access_for(role) ⇒ Object



24
25
26
27
28
# File 'app/models/action_role.rb', line 24

def self.bootstrap_access_for(role)
  Action.all.each do |a|
    find_or_create_by_action_id_and_role_id(a.id, role.id)
  end
end

.permits_access_for(controller, action, role_ids) ⇒ Object

this is the key database lookup for checking permissions returns true if there is at least one of the passed-in role ids which explicitly permits (i.e. the role has action_role associations) the specified controller and action



9
10
11
12
13
14
15
# File 'app/models/action_role.rb', line 9

def self.permits_access_for(controller, action, role_ids)
  joins([:role, :action => :controller ]).
    where("roles.id" => role_ids).
          where("actions.action_name" => action).
          where("controllers.controller_name" => controller).
          exists?
end