Class: Hyrax::Workflow::PermissionGenerator
- Inherits:
-
Object
- Object
- Hyrax::Workflow::PermissionGenerator
- Defined in:
- app/services/hyrax/workflow/permission_generator.rb
Overview
And yes this violates some kind of single responsibility principle as it has many different access points
This has three major uses:
-
To assign Work specific permissions (e.g. Sipity::EntitySpecificResponsibility)
-
a depositor of a work has a Work specific permission
-
-
To assign Workflow specific permissions (e.g. Sipity::WorkflowResponsibility)
-
the review of all deposited works has a Workflow specific permission
-
-
To assign Roles to different Actions, and thus allow users with those roles to take the given actions
It is a “power users” helper class. It builds out the permissions for a host of information.
See the specs for more on what is happening, however the general idea is to encapsulate the logic of assigning :agents to the :role either for the :entity or the :workflow. Then creating the given :action_names for the :workflow and :workflow_state and granting permission in that :workflow_state for the given :role.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(roles:, workflow:, agents: [], **keywords) {|_self| ... } ⇒ PermissionGenerator
constructor
if NOT given - will grant the given :agents the given :roles for the given :workflow (e.g. Sipity::WorkflowResponsibility).
Constructor Details
#initialize(roles:, workflow:, agents: [], **keywords) {|_self| ... } ⇒ PermissionGenerator
Extract public class level methods that expose each of the options (and don’t rely on an external parameter list)
if NOT given
- will grant the given :agents the given :roles for the given :workflow (e.g. Sipity::WorkflowResponsibility)
42 43 44 45 46 47 48 49 50 |
# File 'app/services/hyrax/workflow/permission_generator.rb', line 42 def initialize(roles:, workflow:, agents: [], **keywords) self.roles = roles self.workflow = workflow self.agents = agents self.entity = keywords.fetch(:entity) if keywords.key?(:entity) self.workflow_state = keywords.fetch(:workflow_state, false) self.action_names = keywords.fetch(:action_names, []) yield(self) if block_given? end |
Class Method Details
.call(**keywords, &block) ⇒ Object
Extract public class level methods that expose each of the primary purposes (instead of relying on parameters)
29 30 31 |
# File 'app/services/hyrax/workflow/permission_generator.rb', line 29 def self.call(**keywords, &block) new(**keywords, &block).call end |
Instance Method Details
#call ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'app/services/hyrax/workflow/permission_generator.rb', line 75 def call roles.each do |role| workflow_role = Sipity::WorkflowRole.find_or_create_by!(role: role, workflow: workflow) associate_workflow_role_at_entity_level(workflow_role) associate_workflow_role_at_workflow_level(workflow_role) (workflow_role) end end |