Class: CurationConcerns::Workflow::PermissionGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/services/curation_concerns/workflow/permission_generator.rb

Overview

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

Constructor Details

#initialize(roles:, workflow:, agents: [], **keywords) {|_self| ... } ⇒ PermissionGenerator

Returns a new instance of PermissionGenerator.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
# File 'app/services/curation_concerns/workflow/permission_generator.rb', line 18

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



14
15
16
# File 'app/services/curation_concerns/workflow/permission_generator.rb', line 14

def self.call(**keywords, &block)
  new(**keywords, &block).call
end

Instance Method Details

#callObject



51
52
53
54
55
56
57
58
# File 'app/services/curation_concerns/workflow/permission_generator.rb', line 51

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)
    create_action_and_permission_for_actions(workflow_role)
  end
end