Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge backport of #689: show the admin set name on the workflow role …
…widget Fixes #908
- Loading branch information
Showing
11 changed files
with
114 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,30 @@ | ||
module Hyrax | ||
module Admin | ||
# Displays a single workflow role | ||
class WorkflowRolePresenter | ||
def users | ||
::User.registered | ||
def initialize(workflow_role) | ||
@workflow = workflow_role.workflow | ||
@role = workflow_role.role | ||
@admin_set_id = workflow.permission_template.admin_set_id | ||
end | ||
|
||
def presenter_for(user) | ||
agent = user.sipity_agent | ||
return unless agent | ||
AgentPresenter.new(agent) | ||
# @todo This is a hack; I don't want to include reference to the admin set; | ||
# However based on the current UI, in which we list all workflows (spanning all admin sets) this is required. | ||
# @return [String] A meaningful label for the given WorkflowRole | ||
def label | ||
"#{admin_set_label(admin_set_id)} - #{role.name} (#{workflow.name})" | ||
end | ||
|
||
class AgentPresenter | ||
def initialize(agent) | ||
@agent = agent | ||
end | ||
|
||
def responsibilities_present? | ||
@agent.workflow_responsibilities.any? | ||
end | ||
private | ||
|
||
def responsibilities | ||
@agent.workflow_responsibilities.each do |responsibility| | ||
yield ResponsibilityPresenter.new(responsibility) | ||
end | ||
end | ||
end | ||
attr_accessor :workflow, :role, :admin_set_id | ||
|
||
class ResponsibilityPresenter | ||
def initialize(responsibility) | ||
@responsibility = responsibility | ||
@wf_role = responsibility.workflow_role | ||
def admin_set_label(id) | ||
result = ActiveFedora::Base.search_by_id(id, fl: 'title_tesim') | ||
result['title_tesim'].first | ||
rescue ActiveFedora::ObjectNotFoundError | ||
"[AdminSet ID=#{id}]" | ||
end | ||
|
||
attr_accessor :responsibility | ||
|
||
def label | ||
"#{@wf_role.workflow.name} - #{@wf_role.role.name}" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Hyrax | ||
module Admin | ||
# Displays a list of users and their associated workflow roles | ||
class WorkflowRolesPresenter | ||
def users | ||
::User.registered | ||
end | ||
|
||
def presenter_for(user) | ||
agent = user.sipity_agent | ||
return unless agent | ||
AgentPresenter.new(agent) | ||
end | ||
|
||
class AgentPresenter | ||
def initialize(agent) | ||
@agent = agent | ||
end | ||
|
||
def responsibilities_present? | ||
@agent.workflow_responsibilities.any? | ||
end | ||
|
||
def responsibilities | ||
@agent.workflow_responsibilities.each do |responsibility| | ||
yield ResponsibilityPresenter.new(responsibility) | ||
end | ||
end | ||
end | ||
|
||
class ResponsibilityPresenter | ||
def initialize(responsibility) | ||
@responsibility = responsibility | ||
@workflow_role_presenter = WorkflowRolePresenter.new(responsibility.workflow_role) | ||
end | ||
|
||
attr_accessor :responsibility | ||
|
||
delegate :label, to: :@workflow_role_presenter | ||
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
18 changes: 8 additions & 10 deletions
18
spec/presenters/hyrax/admin/workflow_role_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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::Admin::WorkflowRolePresenter do | ||
let(:presenter) { described_class.new } | ||
let(:presenter) { described_class.new(workflow_role) } | ||
let(:role) { Sipity::Role[:depositor] } | ||
let(:workflow) { create(:workflow) } | ||
let(:workflow_role) { Sipity::WorkflowRole.new(role: role, workflow: workflow) } | ||
|
||
describe "#users" do | ||
subject { presenter.users } | ||
let!(:user) { create(:user) } | ||
before do | ||
create(:user, :guest) | ||
end | ||
it "doesn't include guests" do | ||
expect(subject).to eq [user] | ||
end | ||
describe '#label' do | ||
subject { presenter.label } | ||
|
||
it { is_expected.to be_a(String) } | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
spec/presenters/hyrax/admin/workflow_roles_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,18 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::Admin::WorkflowRolesPresenter do | ||
let(:presenter) { described_class.new } | ||
|
||
describe "#users" do | ||
subject { presenter.users } | ||
|
||
let!(:user) { create(:user) } | ||
|
||
before do | ||
create(:user, :guest) | ||
end | ||
it "doesn't include guests" do | ||
expect(subject).to eq [user] | ||
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