Skip to content

Commit

Permalink
Stop supporting rights xml
Browse files Browse the repository at this point in the history
We only use cocina now
  • Loading branch information
jcoyne committed May 20, 2024
1 parent df6ba8d commit da5b01d
Show file tree
Hide file tree
Showing 28 changed files with 45 additions and 990 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ gem 'config'
gem 'faraday'
gem 'http'
gem 'cancancan'
gem 'dor-rights-auth', '~> 1.8'
gem 'dalli'
gem 'retries'
gem 'zipline', '~> 1.2'
Expand Down
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ GEM
ed25519
docile (1.4.0)
domain_name (0.6.20240107)
dor-rights-auth (1.8.0)
nokogiri
drb (2.2.1)
dry-configurable (1.1.0)
dry-core (~> 1.0, < 2)
Expand Down Expand Up @@ -260,6 +258,8 @@ GEM
nio4r (2.7.3)
nokogiri (1.16.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
ocfl (0.4.1)
Expand Down Expand Up @@ -463,7 +463,6 @@ DEPENDENCIES
dalli
debug
dlss-capistrano
dor-rights-auth (~> 1.8)
faraday
honeybadger
http
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ def current_ability
end

def ability_class
Settings.features.cocina ? CocinaAbility : Ability
CocinaAbility
end
end
114 changes: 0 additions & 114 deletions app/models/ability.rb

This file was deleted.

16 changes: 8 additions & 8 deletions app/models/cocina_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ def initialize(user)
access_models = downloadable_models + [StacksMediaStream]

can :download, downloadable_models do |f|
f.cocina_rights.download == 'world'
f.rights.download == 'world'
end

can [:access], access_models do |f|
f.cocina_rights.view == 'world'
f.rights.view == 'world'
end

if user.stanford?
can :download, downloadable_models do |f|
f.cocina_rights.download == 'stanford'
f.rights.download == 'stanford'
end

can [:access], access_models do |f|
f.cocina_rights.view == 'stanford'
f.rights.view == 'stanford'
end
end

if user.locations.present?
can :download, downloadable_models do |f|
next unless f.cocina_rights.download == 'location-based'
next unless f.rights.download == 'location-based'

user.locations.include?(f.cocina_rights.location)
user.locations.include?(f.rights.location)
end

can [:access], access_models do |f|
user.locations.any? do |_location|
next unless f.cocina_rights.view == 'location-based'
next unless f.rights.view == 'location-based'

user.locations.include?(f.cocina_rights.location)
user.locations.include?(f.rights.location)
end
end
end
Expand Down
13 changes: 1 addition & 12 deletions app/models/purl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def public_json(druid)
def files(druid, &)
return to_enum(:files, druid) unless block_given?

Settings.features.cocina ? files_from_json(druid, &) : files_from_xml(druid, &)
files_from_json(druid, &)
end

def files_from_json(druid)
Expand All @@ -54,17 +54,6 @@ def files_from_json(druid)
end
end

def files_from_xml(druid)
doc = Nokogiri::XML.parse(public_xml(druid))

doc.xpath('//contentMetadata/resource').each do |resource|
resource.xpath('file|externalFile').each do |attr|
file = StacksFile.new(id: druid, file_name: attr['id'])
yield file
end
end
end

private

def public_xml_url(druid)
Expand Down
2 changes: 1 addition & 1 deletion app/models/stacks_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def storage_root
def stacks_rights
@stacks_rights ||= StacksRights.new(id:, file_name:)
end
delegate :rights, :cocina_rights, :restricted_by_location?, :stanford_restricted?, :embargoed?,
delegate :rights, :restricted_by_location?, :stanford_restricted?, :embargoed?,
:embargo_release_date, :location, to: :stacks_rights

def streamable?
Expand Down
2 changes: 1 addition & 1 deletion app/models/stacks_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ def info_service
def stacks_rights
@stacks_rights ||= StacksRights.new(id:, file_name:)
end
delegate :rights, :cocina_rights, :maybe_downloadable?, :object_thumbnail?,
delegate :rights, :maybe_downloadable?, :object_thumbnail?,
:stanford_restricted?, :restricted_by_location?, to: :stacks_rights
end
2 changes: 1 addition & 1 deletion app/models/stacks_media_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def stacks_rights
@stacks_rights ||= StacksRights.new(id:, file_name:)
end

delegate :rights, :cocina_rights, :restricted_by_location?, :stanford_restricted?, :embargoed?,
delegate :rights, :restricted_by_location?, :stanford_restricted?, :embargoed?,
:embargo_release_date, :location, to: :stacks_rights
end
73 changes: 8 additions & 65 deletions app/models/stacks_rights.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,93 +13,44 @@ def initialize(id:, file_name:)
end

def maybe_downloadable?
if use_json?
%w[world stanford].include?(cocina_rights.download)
else
rights.world_unrestricted_file?(file_name) ||
rights.stanford_only_unrestricted_file?(file_name)
end
%w[world stanford].include?(rights.download)
end

def stanford_restricted?
if use_json?
cocina_rights.view == 'stanford'
else
value, _rule = rights.stanford_only_rights_for_file file_name

value
end
rights.view == 'stanford'
end

# Returns true if a given file has any location restrictions.
# Falls back to the object-level behavior if none at file level.
def restricted_by_location?
if use_json?
cocina_rights.view == 'location-based' || cocina_rights.download == 'location-based'
else
rights.restricted_by_location?(file_name)
end
end

def embargoed?
use_json? ? cocina_embargo? : rights.embargoed?
rights.view == 'location-based' || rights.download == 'location-based'
end

def embargo_release_date
use_json? ? cocina_embargo_release_date : rights.embargo_release_date
cocina_embargo_release_date
end

def cocina_embargo?
def embargoed?
cocina_embargo_release_date && Time.parse(cocina_embargo_release_date).getlocal > Time.now.getlocal
end

def cocina_embargo_release_date
@cocina_embargo_release_date ||= public_json.dig('access', 'embargo', 'releaseDate')
end

def object_thumbnail?
use_json? ? cocina_thumbnail? : xml_thumbnail?
end

def xml_thumbnail?
doc = Nokogiri::XML.parse(public_xml)

thumb_element = doc.xpath('//thumb')

if thumb_element.any?
thumb_element.text == "#{id}/#{file_name}"
else
doc.xpath("//file[@id=\"#{file_name}\"]/../@sequence").text == '1'
end
end

# Based on implementation of ThumbnailService in DSA
def cocina_thumbnail?
def object_thumbnail?
thumbnail_file = public_json.dig('structural', 'contains')
.lazy.flat_map { |file_set| file_set.dig('structural', 'contains') }
.find { |file| file['hasMimeType'] == THUMBNAIL_MIME_TYPE }
thumbnail_file == cocina_file
end

def use_json?
Settings.features.cocina
end

def rights
use_json? ? cocina_rights : dor_auth_rights
end

def dor_auth_rights
@dor_auth_rights ||= Dor::RightsAuth.parse(rights_xml)
end

def cocina_rights
@cocina_rights ||= CocinaRights.new(cocina_file['access'])
@rights ||= CocinaRights.new(cocina_file['access'])
end

def location
use_json? ? cocina_rights.location : dor_auth_rights.obj_lvl.location.keys.first
end
delegate :location, to: :rights

private

Expand All @@ -116,12 +67,4 @@ def find_file
def public_json
@public_json ||= Purl.public_json(id)
end

def rights_xml
public_xml
end

def public_xml
@public_xml ||= Purl.public_xml(id)
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def ability
end

def ability_class
Settings.features.cocina ? CocinaAbility : Ability
CocinaAbility
end

def webauth_user?
Expand Down
Loading

0 comments on commit da5b01d

Please sign in to comment.