Class: Hyrax::Workflow::PermissionGenerator

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

Overview

Note:

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: [])

    -

  • keywords

Options Hash (**keywords):

  • :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:



48
49
50
51
52
53
54
55
56
# File 'app/services/hyrax/workflow/permission_generator.rb', line 48

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)



32
33
34
# File 'app/services/hyrax/workflow/permission_generator.rb', line 32

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

Instance Method Details

#callObject



81
82
83
84
85
86
87
88
# File 'app/services/hyrax/workflow/permission_generator.rb', line 81

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