Class: Hyrax::Forms::WorkflowActionForm
- Inherits:
-
Object
- Object
- Hyrax::Forms::WorkflowActionForm
- Extended by:
- ActiveModel::Translation
- Includes:
- ActiveModel::Validations
- Defined in:
- app/forms/hyrax/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
Returns the value of attribute comment.
-
#current_ability ⇒ Object
readonly
Returns the value of attribute current_ability.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#work ⇒ Object
readonly
Returns the value of attribute work.
Class Method Summary collapse
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.
24 25 26 27 28 29 30 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 24 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)
Returns the value of attribute comment.
32 33 34 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 32 def comment @comment end |
#current_ability ⇒ Object (readonly)
Returns the value of attribute current_ability.
32 33 34 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 32 def current_ability @current_ability end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 32 def name @name end |
#work ⇒ Object (readonly)
Returns the value of attribute work.
32 33 34 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 32 def work @work end |
Class Method Details
.workflow_action_for(name, scope:) ⇒ Object
59 60 61 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 59 def workflow_action_for(name, scope:) Sipity::WorkflowAction(name, scope) { nil } end |
Instance Method Details
#authorized_for_processing ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 45 def return false if name.blank? # name is the action which converts to sipity_workflow_action return true if Hyrax::Workflow::PermissionQuery.( user: subject.user, entity: subject.entity, action: sipity_workflow_action ) errors.add(:base, :unauthorized) false end |
#save ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/forms/hyrax/forms/workflow_action_form.rb', line 34 def save return false unless valid? Workflow::WorkflowActionService.run(subject: subject, action: sipity_workflow_action, comment: comment) true end |