Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/ability.rb
Instance Method Summary collapse
- #check_for_domain_restrictions(permission, domain) ⇒ Object
-
#initialize(operator = nil, current_domain = nil) ⇒ Ability
constructor
A new instance of Ability.
- #set_ability(able, action_name, model_name, id_name = nil) ⇒ Object
- #set_child_permissions(able, action_name, model_name, id_name) ⇒ Object
- #set_permission(permission, current_domain) ⇒ Object
Constructor Details
#initialize(operator = nil, current_domain = nil) ⇒ Ability
Returns a new instance of Ability.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/ability.rb', line 6 def initialize(operator=nil,current_domain=nil) can :read, Goldencobra::Article can :read, Goldencobra::Menue can :read, Goldencobra::Widget #Rechte die alle betreffen Goldencobra::Permission.where("action IS NOT NULL").where("role_id IS NULL OR role_id = ''").each do || (,current_domain) end #Rechte, die nur bestimmte nutzerrollen betreffen if operator && operator.respond_to?(:roles) operator.roles.each do |role| role..each do || if check_for_domain_restrictions(,current_domain) if .subject_class == ":all" if .action.include?("not_") cannot .action.gsub("not_", "").to_sym, :all else can .action.to_sym, :all end else (,current_domain) end end end end end end |
Instance Method Details
#check_for_domain_restrictions(permission, domain) ⇒ Object
72 73 74 |
# File 'app/models/ability.rb', line 72 def check_for_domain_restrictions(,domain) .domain.blank? || (domain.present? && .domain.present? && .domain == domain) end |
#set_ability(able, action_name, model_name, id_name = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/ability.rb', line 56 def set_ability(able, action_name, model_name, id_name=nil) if id_name.present? send(able, action_name, model_name, id: id_name) else send(able, action_name, model_name) end end |
#set_child_permissions(able, action_name, model_name, id_name) ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/models/ability.rb', line 64 def (able, action_name, model_name,id_name) if %w(can cannot).include?(able) && model_name.new.respond_to?(:descendant_ids) && object = model_name.find_by_id(id_name) object.descendant_ids.each do |child_id| set_ability(able, action_name, model_name, child_id) end end end |
#set_permission(permission, current_domain) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/ability.rb', line 36 def (,current_domain) able = 'can' action_name = .action.to_sym model_name = .subject_class.constantize if .action.include?("not_") action_name = .action.gsub("not_", "").to_sym able = 'cannot' end if check_for_domain_restrictions(,current_domain) if .subject_id.present? set_ability(able, action_name, model_name, .subject_id.to_i) (able, action_name, model_name, .subject_id.to_i) else set_ability(able, action_name, model_name) end end end |