Class: CurationConcerns::Forms::WorkflowActionForm
- Inherits:
-
Object
- Object
- CurationConcerns::Forms::WorkflowActionForm
- Extended by:
- ActiveModel::Translation
- Includes:
- ActiveModel::Validations
- Defined in:
- app/forms/curation_concerns/forms/workflow_action_form.rb
Overview
Responsible for processing that the :current_ability (and associated current_user) has taken a Sipity::WorkflowAction on an object that has a Sipity::Entity.
The form enforces that the action taken is valid.
Instance Attribute Summary collapse
- #comment ⇒ Object readonly
- #current_ability ⇒ Object readonly
- #name ⇒ Object readonly
- #work ⇒ Object readonly
Instance Method Summary collapse
- #authorized_for_processing ⇒ Object
-
#initialize(current_ability:, work:, attributes: {}) ⇒ WorkflowActionForm
constructor
A new instance of WorkflowActionForm.
- #save ⇒ Object
Constructor Details
#initialize(current_ability:, work:, attributes: {}) ⇒ WorkflowActionForm
Returns a new instance of WorkflowActionForm.
19 20 21 22 23 24 25 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 19 def initialize(current_ability:, work:, attributes: {}) @current_ability = current_ability @work = work @name = attributes.fetch(:name, false) @comment = attributes.fetch(:comment, nil) convert_to_sipity_objects! end |
Instance Attribute Details
#comment ⇒ Object (readonly)
27 28 29 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 27 def comment @comment end |
#current_ability ⇒ Object (readonly)
27 28 29 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 27 def current_ability @current_ability end |
#name ⇒ Object (readonly)
27 28 29 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 27 def name @name end |
#work ⇒ Object (readonly)
27 28 29 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 27 def work @work end |
Instance Method Details
#authorized_for_processing ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 40 def return true if CurationConcerns::Workflow::PermissionQuery.( user: subject.user, entity: subject.entity, action: sipity_workflow_action ) errors.add(:base, :unauthorized) false end |
#save ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/forms/curation_concerns/forms/workflow_action_form.rb', line 29 def save return false unless valid? Workflow::WorkflowActionService.run(subject: subject, action: sipity_workflow_action, comment: comment) true end |