Skip to content

Commit

Permalink
Depositor should have read access. Fixes #672
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Apr 4, 2017
1 parent 05b3584 commit 70aedc9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/services/hyrax/workflow/grant_read_to_depositor.rb
@@ -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
Expand Up @@ -46,6 +46,7 @@
}
],
"methods": [
"Hyrax::Workflow::GrantReadToDepositor",
"Hyrax::Workflow::ActivateObject"
]
}, {
Expand Down
33 changes: 33 additions & 0 deletions spec/services/hyrax/workflow/grant_read_to_depositor_spec.rb
@@ -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

0 comments on commit 70aedc9

Please sign in to comment.