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.
Constant Summary collapse
- DEFAULT_INITIAL_WORKFLOW_STATE =
'new'.freeze
Class Method Summary collapse
-
.activate!(permission_template:, workflow_id: nil, workflow_name: nil) ⇒ TrueClass
Within the given permission_template scope: * Deactivate the current active workflow (if one exists) * Activate the specified workflow_id.
-
.find_active_workflow_for(admin_set_id:) ⇒ Sipity::Workflow
That is active for the given administrative set`.
Instance Method Summary collapse
- #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) ⇒ TrueClass
Within the given permission_template scope:
* Deactivate the current active workflow (if one exists)
* Activate the specified workflow_id
49 50 51 52 53 54 55 56 |
# File 'app/models/sipity/workflow.rb', line 49 def self.activate!(permission_template:, workflow_id: nil, workflow_name: nil) raise "You must specify a workflow_id or workflow_name to activate!" if workflow_id.blank? && workflow_name.blank? finder_attributes = { permission_template: , id: workflow_id, name: workflow_name }.compact Sipity::Workflow.find_by!(finder_attributes).tap do |workflow| Sipity::Workflow.where(permission_template: , active: true).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`.
27 28 29 30 31 32 33 34 35 |
# File 'app/models/sipity/workflow.rb', line 27 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[:admin_set_id].eq(admin_set_id)) ) ).first! end |
Instance Method Details
#initial_workflow_state ⇒ Object
19 20 21 |
# File 'app/models/sipity/workflow.rb', line 19 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
63 64 65 66 |
# File 'app/models/sipity/workflow.rb', line 63 def update_responsibilities(role:, agents:) add_workflow_responsibilities(role, agents) remove_workflow_responsibilities(role, agents) end |