Skip to content

Commit

Permalink
Merge pull request #1011 from sul-dlss/media-not-readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Nov 6, 2023
2 parents 30837d9 + 3e71597 commit 9ea66c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 52 deletions.
28 changes: 13 additions & 15 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,57 +41,58 @@ def initialize(user)
# NOTE: the below ability definitions which reference StacksFile also implicitly
# cover StacksImage and StacksMediaStream, and any other subclasses of StacksFile.

models = [StacksFile, StacksImage, StacksMediaStream]
downloadable_models = [StacksFile, StacksImage]
access_models = downloadable_models + [StacksMediaStream]

can :download, models do |f|
can :download, downloadable_models do |f|
value, rule = f.rights.world_rights_for_file f.file_name

value && (rule.nil? || rule != Dor::RightsAuth::NO_DOWNLOAD_RULE)
end

can [:access], models do |f|
can [:access], access_models do |f|
value, _rule = f.rights.world_rights_for_file f.file_name

value
end

if user.stanford?
can :download, models do |f|
can :download, downloadable_models do |f|
value, rule = f.rights.stanford_only_rights_for_file f.file_name

value && (rule.nil? || rule != Dor::RightsAuth::NO_DOWNLOAD_RULE)
end

can [:access], models do |f|
can [:access], access_models do |f|
value, _rule = f.rights.stanford_only_rights_for_file f.file_name

value
end
end

if user.app_user?
can :download, models do |f|
can :download, downloadable_models do |f|
value, rule = f.rights.agent_rights_for_file f.file_name, user.id

value && (rule.nil? || rule != Dor::RightsAuth::NO_DOWNLOAD_RULE)
end

can [:access], models do |f|
can [:access], access_models do |f|
value, _rule = f.rights.agent_rights_for_file f.file_name, user.id

value
end
end

if user.locations.present?
can :download, models do |f|
can :download, downloadable_models do |f|
user.locations.any? do |location|
value, rule = f.rights.location_rights_for_file(f.file_name, location)
value && (rule.nil? || rule != Dor::RightsAuth::NO_DOWNLOAD_RULE)
end
end

can [:access], models do |f|
can [:access], access_models do |f|
user.locations.any? do |location|
value, _rule = f.rights.location_rights_for_file(f.file_name, location)
value
Expand All @@ -105,7 +106,7 @@ def initialize(user)
# ...
# end

can [:access], models do |f|
can [:access], access_models do |f|
value, _rule = f.rights.cdl_rights_for_file(f.file_name)
next unless value

Expand All @@ -125,7 +126,7 @@ def initialize(user)
(projection.tile? || projection.thumbnail?) && can?(:access, projection.image)
end

can [:access], Projection do |projection|
can :access, Projection do |projection|
can?(:access, projection.image)
end

Expand All @@ -135,10 +136,7 @@ def initialize(user)
projection.thumbnail? && projection.object_thumbnail?
end

can :stream, StacksMediaStream do |f|
can? :access, f
end

alias_action :stream, to: :access
can :read_metadata, StacksImage
end
end
37 changes: 0 additions & 37 deletions spec/abilities/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -84,7 +83,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -108,7 +106,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, big_image) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
Expand All @@ -133,7 +130,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand All @@ -160,7 +156,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -183,7 +178,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand Down Expand Up @@ -251,7 +245,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand Down Expand Up @@ -295,7 +288,6 @@
let(:user) { User.new(ip_address: 'ip.address2') }
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -308,7 +300,6 @@
let(:user) { User.new(ip_address: 'some.unknown.ip') }
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand All @@ -333,7 +324,6 @@
let(:user) { User.new(ip_address: 'ip.address2') }
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -345,7 +335,6 @@
let(:user) { User.new(ip_address: 'some.unknown.ip') }
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand Down Expand Up @@ -373,7 +362,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -397,7 +385,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -421,7 +408,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -444,7 +430,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -467,7 +452,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -492,7 +476,6 @@
end
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -515,7 +498,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand All @@ -538,7 +520,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand All @@ -561,7 +542,6 @@
end
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand Down Expand Up @@ -593,7 +573,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -607,7 +586,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -623,7 +601,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -639,7 +616,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -655,7 +631,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand Down Expand Up @@ -686,7 +661,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -700,7 +674,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -714,7 +687,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand Down Expand Up @@ -743,7 +715,6 @@
context 'for an anonymous user' do
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -757,7 +728,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand Down Expand Up @@ -791,7 +761,6 @@
context 'as an anonymous user' do
it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand Down Expand Up @@ -826,7 +795,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -843,7 +811,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand All @@ -856,7 +823,6 @@
context 'as an anonymous user' do
it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand Down Expand Up @@ -891,7 +857,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.to be_able_to(:download, image) }
it { is_expected.to be_able_to(:download, media) }
it { is_expected.to be_able_to(:read, tile) }
it { is_expected.to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand All @@ -905,7 +870,6 @@

it { is_expected.not_to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.not_to be_able_to(:access, file) }
Expand All @@ -919,7 +883,6 @@

it { is_expected.to be_able_to(:download, file) }
it { is_expected.not_to be_able_to(:download, image) }
it { is_expected.not_to be_able_to(:download, media) }
it { is_expected.not_to be_able_to(:read, tile) }
it { is_expected.not_to be_able_to(:stream, media) }
it { is_expected.to be_able_to(:access, file) }
Expand Down

0 comments on commit 9ea66c0

Please sign in to comment.