Class: Hyrax::Workflow::PermissionGenerator

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

Overview

Note:

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

Constructor Details

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

TODO:

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)

Parameters:

  • roles (Array<Sipity::Role, #string>)
    • converted to Sipity::Role

  • workflow (Sipity::Workflow)

    -

  • agents (Array<Object>) (defaults to: [])

    -

  • entity (Sipity::Entity)
    • if given

    • will grant the given :agents the given :roles for the given :entity (e.g. Sipity::EntitySpecificResponsibility)

  • action_names (Array<String>)
    • it will wire-up the workflow, allowing the given :roles to take the given :actions

Yields:

  • (_self)

Yield Parameters:


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

TODO:

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

#callObject


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