Class: Sipity::Workflow
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sipity::Workflow
- Defined in:
- app/models/sipity/workflow.rb
Overview
A named workflow for processing an entity. Originally I had thought of calling this a Type, but once I extracted the Processing submodule, type felt to much of a noun, not conveying potentiality. Workflow conveys “things will happen” because of this.
Defined Under Namespace
Classes: NoActiveWorkflowError
Constant Summary collapse
- DEFAULT_INITIAL_WORKFLOW_STATE =
'new'
Class Method Summary collapse
-
.activate!(permission_template:, workflow_id: nil, workflow_name: nil) ⇒ Sipity::Workflow
Within the given permission_template scope: * Activate the specified workflow_id or workflow_name * Deactivate the other workflows.
-
.find_active_workflow_for(admin_set_id:) ⇒ Sipity::Workflow
That is active for the given administrative set`.
Instance Method Summary collapse
-
#find_deposit_action ⇒ Sipity::WorkflowAction
Find an action in this workflow that has no starting state.
- #initial_workflow_state ⇒ Object
-
#update_responsibilities(role:, agents:) ⇒ Object
Grant a workflow responsibility to a set of agents and remove it from any agents who currently have the workflow responsibility, but are not in the provided list.
Class Method Details
.activate!(permission_template:, workflow_id: nil, workflow_name: nil) ⇒ Sipity::Workflow
Within the given permission_template scope:
* Activate the specified workflow_id or workflow_name
* Deactivate the other workflows
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/sipity/workflow.rb', line 52 def self.activate!(permission_template:, workflow_id: nil, workflow_name: nil) raise(ArgumentError, "You must specify a workflow_id or workflow_name to activate!") if workflow_id.blank? && workflow_name.blank? workflow_to_activate = Sipity::Workflow.find_by!({ permission_template: , id: workflow_id, name: workflow_name }.compact) active_workflow = Sipity::Workflow.where(permission_template: , active: true) return workflow_to_activate if workflow_to_activate == active_workflow.first workflow_to_activate.tap do |workflow| active_workflow.update(active: nil) workflow.update!(active: true) end end |
.find_active_workflow_for(admin_set_id:) ⇒ Sipity::Workflow
Returns that is active for the given administrative set`.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/sipity/workflow.rb', line 29 def self.find_active_workflow_for(admin_set_id:) templates = Hyrax::PermissionTemplate.arel_table workflows = Sipity::Workflow.arel_table Sipity::Workflow.where(active: true).where( workflows[:permission_template_id].in( templates.project(templates[:id]).where(templates[:source_id].eq(admin_set_id.to_s)) ) ).first! rescue ActiveRecord::RecordNotFound => err raise NoActiveWorkflowError, err. end |
Instance Method Details
#find_deposit_action ⇒ Sipity::WorkflowAction
Find an action in this workflow that has no starting state. This is the deposit action.
70 71 72 73 74 75 76 77 |
# File 'app/models/sipity/workflow.rb', line 70 def find_deposit_action actions_that_lead_to_states = Sipity::WorkflowStateAction.all.pluck(:workflow_action_id) relation = Sipity::WorkflowAction.where(workflow: self) relation = relation.where('id NOT IN (?)', actions_that_lead_to_states) if actions_that_lead_to_states.any? relation.first! rescue ActiveRecord::RecordNotFound => err raise NoActiveWorkflowError, err. end |
#initial_workflow_state ⇒ Object
21 22 23 |
# File 'app/models/sipity/workflow.rb', line 21 def initial_workflow_state workflow_states.find_or_create_by!(name: DEFAULT_INITIAL_WORKFLOW_STATE) end |
#update_responsibilities(role:, agents:) ⇒ Object
Grant a workflow responsibility to a set of agents and remove it from any agents who currently have the workflow responsibility, but are not in the provided list
84 85 86 87 |
# File 'app/models/sipity/workflow.rb', line 84 def update_responsibilities(role:, agents:) add_workflow_responsibilities(role, agents) remove_workflow_responsibilities(role, agents) end |