Class: Goldberg::Permission
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Goldberg::Permission
- Includes:
- Model
- Defined in:
- lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/permission.rb
Class Method Summary collapse
-
.find_all_for_role(role) ⇒ Object
Find all Permissions for a Role.
-
.find_for_role(role_ids) ⇒ Object
Find Permissions for a Role ID or an array of Role IDs.
-
.find_not_for_role(role_id) ⇒ Object
Find Permissions that are not already associated with the given Role ID.
Methods included from Model
Methods inherited from ActiveRecord::Base
#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?
Class Method Details
.find_all_for_role(role) ⇒ Object
Find all Permissions for a Role. This method gets the hierarchy for the given Role and uses that to get all the Permissions for the Role and its ancestors.
22 23 24 25 26 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/permission.rb', line 22 def find_all_for_role(role) roles = role.get_parents roles << role return find_for_role(roles.collect(&:id)) end |
.find_for_role(role_ids) ⇒ Object
Find Permissions for a Role ID or an array of Role IDs.
14 15 16 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/permission.rb', line 14 def find_for_role(role_ids) return find_by_sql( ["select p.* from #{prefix}permissions p inner join #{prefix}roles_permissions rp on p.id = rp.permission_id where role_id in (?) order by p.name", role_ids] ) end |
.find_not_for_role(role_id) ⇒ Object
Find Permissions that are not already associated with the given Role ID.
31 32 33 |
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/permission.rb', line 31 def find_not_for_role(role_id) return find_by_sql( ["select p.* from #{prefix}permissions p where id not in (select permission_id from #{prefix}roles_permissions rp where role_id in (?)) order by name", role_id] ) end |