Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depositor should have read access. Fixes #672
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Hyrax | ||
module Workflow | ||
# This is a built in function for workflow, so that a workflow action can be created that | ||
# grants the creator the ability to view their work. | ||
class GrantReadToDepositor | ||
def self.call(target:, **) | ||
target.read_users += [target.depositor] | ||
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
} | ||
], | ||
"methods": [ | ||
"Hyrax::Workflow::GrantReadToDepositor", | ||
"Hyrax::Workflow::ActivateObject" | ||
] | ||
}, { | ||
|
33 changes: 33 additions & 0 deletions
33
spec/services/hyrax/workflow/grant_read_to_depositor_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,33 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::Workflow::GrantReadToDepositor do | ||
let(:depositor) { create(:user) } | ||
let(:user) { User.new } | ||
|
||
describe ".call" do | ||
subject do | ||
described_class.call(target: work, | ||
comment: "A pleasant read", | ||
user: user) | ||
end | ||
|
||
context "with no additional viewers" do | ||
let(:work) { create(:work_without_access, depositor: depositor.user_key) } | ||
|
||
it "adds read access" do | ||
expect { subject }.to change { work.read_users }.from([]).to([depositor.user_key]) | ||
expect(work).to be_valid | ||
end | ||
end | ||
|
||
context "with an additional viewers" do | ||
let(:viewer) { create(:user) } | ||
let(:work) { create(:work_without_access, depositor: depositor.user_key, read_users: [viewer.user_key]) } | ||
|
||
it "adds read access" do | ||
expect { subject }.to change { work.read_users }.from([viewer.user_key]).to([viewer.user_key, depositor.user_key]) | ||
expect(work).to be_valid | ||
end | ||
end | ||
end | ||
end |