This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permits all users to view all batches and batch objects (DDR-281) (#1800
- Loading branch information
1 parent
24c3797
commit 0a2a546
Showing
10 changed files
with
93 additions
and
15 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
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
13 changes: 13 additions & 0 deletions
13
lib/dul_hydra/ability_definitions/batch_ability_definitions.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,13 @@ | ||
module DulHydra | ||
class BatchAbilityDefinitions < Ddr::Auth::AbilityDefinitions | ||
|
||
def call | ||
can :read, [ Ddr::Batch::Batch, Ddr::Batch::BatchObject ] if authenticated? | ||
can :manage, Ddr::Batch::Batch, user: user | ||
can :manage, Ddr::Batch::BatchObject do |batch_object| | ||
batch_object.batch.user == 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
RSpec.describe BatchObjectsController, type: :controller do | ||
|
||
describe "#show" do | ||
let(:batch) { FactoryGirl.create(:batch_with_basic_update_batch_object) } | ||
let(:user) { FactoryGirl.create(:user) } | ||
before { sign_in user } | ||
specify { | ||
get :show, id: batch.batch_objects.first | ||
expect(response.response_code).to eq(200) | ||
} | ||
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
37 changes: 37 additions & 0 deletions
37
spec/lib/dul_hydra/ability_definitions/batch_ability_definitions_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,37 @@ | ||
require 'cancan/matchers' | ||
|
||
module DulHydra | ||
RSpec.describe BatchAbilityDefinitions do | ||
|
||
subject { described_class.call(ability) } | ||
|
||
let(:ability) { FactoryGirl.build(:abstract_ability) } | ||
|
||
describe "Batch permissions" do | ||
let(:batch) { FactoryGirl.create(:batch) } | ||
describe "when the user is the creator of the batch" do | ||
before { allow(ability).to receive(:user) { batch.user } } | ||
it { is_expected.to be_able_to(:manage, batch) } | ||
end | ||
describe "when the user is not the creator of the batch" do | ||
it { is_expected.to_not be_able_to(:manage, batch) } | ||
it { is_expected.to be_able_to(:read, batch) } | ||
end | ||
end | ||
|
||
describe "BatchObject permissions" do | ||
let(:batch) { FactoryGirl.create(:batch) } | ||
let(:resource) { Ddr::Batch::BatchObject.create(batch: batch) } | ||
describe "when the user is the creator of the batch" do | ||
before { allow(ability).to receive(:user) { batch.user } } | ||
it { is_expected.to be_able_to(:manage, resource) } | ||
end | ||
describe "when the user is not the creator of the batch" do | ||
it { is_expected.to_not be_able_to(:manage, resource) } | ||
it { is_expected.to be_able_to(:read, resource) } | ||
end | ||
end | ||
|
||
end | ||
|
||
end |