-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1081 from projecthydra/starting_action
Start workflow with an action
- Loading branch information
Showing
15 changed files
with
123 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module CurationConcerns | ||
# A simple data object for holding a user, work and their workflow proxies | ||
class WorkflowActionInfo | ||
def initialize(work, user) | ||
@work = work | ||
@user = user | ||
@entity = PowerConverter.convert(work, to: :sipity_entity) | ||
@agent = PowerConverter.convert(user, to: :sipity_agent) | ||
end | ||
|
||
attr_reader :entity, :agent, :user, :work | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/services/curation_concerns/workflow/workflow_action_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module CurationConcerns | ||
module Workflow | ||
class WorkflowActionService | ||
def self.run(subject:, action:, comment: nil) | ||
new(subject: subject, action: action, comment: comment).run | ||
end | ||
|
||
def initialize(subject:, action:, comment:) | ||
@subject = subject | ||
@action = action | ||
@comment_text = comment | ||
end | ||
|
||
attr_reader :subject, :action, :comment_text | ||
|
||
def run | ||
update_sipity_workflow_state | ||
comment = create_sipity_comment | ||
handle_sipity_notifications(comment: comment) | ||
handle_additional_sipity_workflow_action_processing(comment: comment) | ||
subject.work.update_index # So that the new actions and state are written into solr. | ||
end | ||
|
||
protected | ||
|
||
def update_sipity_workflow_state | ||
return true unless action.resulting_workflow_state_id.present? | ||
subject.entity.update_attribute(:workflow_state_id, action.resulting_workflow_state_id) | ||
end | ||
|
||
def create_sipity_comment | ||
return true unless comment_text.present? | ||
Sipity::Comment.create!(entity: subject.entity, agent: subject.agent, comment: comment_text) | ||
end | ||
|
||
def handle_sipity_notifications(comment:) | ||
CurationConcerns::Workflow::NotificationService.deliver_on_action_taken( | ||
entity: subject.entity, | ||
comment: comment, | ||
action: action, | ||
user: subject.user | ||
) | ||
end | ||
|
||
# Run any configured custom methods | ||
def handle_additional_sipity_workflow_action_processing(comment:) | ||
CurationConcerns::Workflow::ActionTakenService.handle_action_taken( | ||
entity: subject.entity, | ||
comment: comment, | ||
action: action, | ||
user: subject.user | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
spec/controllers/curation_concerns/workflow_actions_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters