Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display the workflow actions you can take on an item
- Loading branch information
Showing
15 changed files
with
113 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module CurationConcerns | ||
class WorkflowPresenter | ||
def initialize(solr_document, current_ability) | ||
@solr_document = solr_document | ||
@current_ability = current_ability | ||
end | ||
|
||
attr_reader :solr_document, :current_ability | ||
|
||
def state | ||
sipity_entity.workflow_state_name if sipity_entity | ||
end | ||
|
||
# TODO: maybe i18n here? | ||
def state_label | ||
state | ||
end | ||
|
||
# Returns an array of tuples (key, label) appropriate for a radio group | ||
def actions | ||
return [] unless sipity_entity && current_ability | ||
actions = CurationConcerns::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(entity: sipity_entity, user: current_ability.current_user) | ||
actions.map { |action| [action.name, action_label(action)] } | ||
end | ||
|
||
private | ||
|
||
def action_label(action) | ||
I18n.t("curation_concerns.workflow.#{action.workflow.name}.#{action.name}") | ||
end | ||
|
||
def sipity_entity | ||
PowerConverter.convert(solr_document, to: :sipity_entity) | ||
rescue PowerConverter::ConversionError | ||
nil | ||
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
18 changes: 3 additions & 15 deletions
18
app/views/curation_concerns/base/_advisor_actions.html.erb
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 |
---|---|---|
@@ -1,17 +1,5 @@ | ||
<h4>Actions</h4> | ||
|
||
<div class="radio"> | ||
<label for="advisor_approve"><input type="radio" name="optRadios" id="advisor_approve">Approve</label> | ||
</div> | ||
<div class="radio"> | ||
<label for="advisor_reject"><input type="radio" name="optRadios" id="advisor_reject">Reject</label> | ||
</div> | ||
<div class="radio"> | ||
<label for="advisor_flag"><input type="radio" name="optRadios" id="advisor_flag">Flag</label> | ||
</div> | ||
<div class="radio"> | ||
<label for="advisor_takedown"><input type="radio" name="optRadios" id="advisor_takedown">Take Down</label> | ||
</div> | ||
<div class="radio"> | ||
<label for="advisor_restore"><input type="radio" name="optRadios" id="advisor_restore">Restore</label> | ||
</div> | ||
<%= form_tag main_app.curation_concerns_workflow_action_path(presenter), method: :put do %> | ||
<%= collection_radio_buttons(:workflow_action, :name, presenter.workflow.actions, :first, :last) %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryGirl.define do | ||
factory :sipity_entity, class: Sipity::Entity do | ||
proxy_for_global_id 'gid://internal/Mock/1' | ||
workflow { workflow_state.workflow } | ||
workflow_state | ||
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
26 changes: 26 additions & 0 deletions
26
spec/presenters/curation_concerns/workflow_presenter_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CurationConcerns::WorkflowPresenter do | ||
let(:solr_document) { SolrDocument.new(attributes) } | ||
let(:attributes) do | ||
{ "id" => '888888', | ||
"has_model_ssim" => ["GenericWork"] } | ||
end | ||
|
||
let(:user) { create(:user) } | ||
let(:ability) { Ability.new(user) } | ||
let(:presenter) { described_class.new(solr_document, ability) } | ||
let(:entity) { instance_double(Sipity::Entity) } | ||
|
||
describe "#actions" do | ||
let(:workflow) { create(:workflow, name: 'testing') } | ||
before do | ||
allow(CurationConcerns::Workflow::PermissionQuery).to receive(:scope_permitted_workflow_actions_available_for_current_state).and_return([Sipity::WorkflowAction.new(name: "complete", workflow: workflow)]) | ||
allow(I18n).to receive(:t).with('curation_concerns.workflow.testing.complete').and_return("Approve") | ||
allow(presenter).to receive(:sipity_entity).and_return(entity) | ||
end | ||
|
||
subject { presenter.actions } | ||
it { is_expected.to eq [['complete', 'Approve']] } | ||
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