Class: Hyrax::PermissionTemplateApplicator
- Inherits:
-
Object
- Object
- Hyrax::PermissionTemplateApplicator
- Defined in:
- app/services/hyrax/permission_template_applicator.rb
Overview
Applies a ‘PermissionTemplate` to a given model object by adding the template’s manage and view users to the model’s permissions.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_to(model:) ⇒ Boolean
(also: #to)
True if the permissions have been successfully applied.
-
#initialize(template:) ⇒ PermissionTemplateApplicator
constructor
A new instance of PermissionTemplateApplicator.
Constructor Details
#initialize(template:) ⇒ PermissionTemplateApplicator
Returns a new instance of PermissionTemplateApplicator.
23 24 25 |
# File 'app/services/hyrax/permission_template_applicator.rb', line 23 def initialize(template:) self.template = template end |
Instance Attribute Details
#template ⇒ Hyrax::PermissionTemplate
19 20 21 |
# File 'app/services/hyrax/permission_template_applicator.rb', line 19 def template @template end |
Class Method Details
.apply(template) ⇒ PermissionTemplateApplicator
31 32 33 |
# File 'app/services/hyrax/permission_template_applicator.rb', line 31 def self.apply(template) new(template: template) end |
Instance Method Details
#apply_to(model:) ⇒ Boolean Also known as: to
Returns true if the permissions have been successfully applied.
38 39 40 41 42 43 44 45 |
# File 'app/services/hyrax/permission_template_applicator.rb', line 38 def apply_to(model:) model.edit_groups += template.agent_ids_for(agent_type: 'group', access: 'manage') model.edit_users += template.agent_ids_for(agent_type: 'user', access: 'manage') model.read_groups += template.agent_ids_for(agent_type: 'group', access: 'view') model.read_users += template.agent_ids_for(agent_type: 'user', access: 'view') true end |