Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide the embargo release date in the media auth API #1009

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ gem 'config'
gem 'faraday'
gem 'http'
gem 'cancancan'
gem 'dor-rights-auth', require: 'dor/rights_auth'
gem 'dor-rights-auth', '~> 1.8'
gem 'dalli'
gem 'retries'
gem 'zipline', '~> 1.2'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ GEM
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dor-rights-auth (1.7.0)
dor-rights-auth (1.8.0)
nokogiri
dry-configurable (1.1.0)
dry-core (~> 1.0, < 2)
Expand Down Expand Up @@ -427,7 +427,7 @@ DEPENDENCIES
dalli
debug
dlss-capistrano
dor-rights-auth
dor-rights-auth (~> 1.8)
faraday
honeybadger
http
Expand Down
3 changes: 2 additions & 1 deletion app/models/stacks_media_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def file
def stacks_rights
@stacks_rights ||= StacksRights.new(id:, file_name:)
end
delegate :rights, :restricted_by_location?, :stanford_restricted?, :embargoed?, to: :stacks_rights
delegate :rights, :restricted_by_location?, :stanford_restricted?, :embargoed?,
:embargo_release_date, to: :stacks_rights
end
2 changes: 1 addition & 1 deletion app/models/stacks_rights.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def restricted_by_location?
rights.restricted_by_location?(file_name)
end

delegate :embargoed?, to: :rights
delegate :embargoed?, :embargo_release_date, to: :rights

def object_thumbnail?
doc = Nokogiri::XML.parse(public_xml)
Expand Down
42 changes: 23 additions & 19 deletions app/services/media_authentication_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,52 @@ def initialize(user:, media:, auth_url:, ability:)
class DenyResponse
def initialize(auth_url)
@auth_url = auth_url
@status = []
@result = { status: [] }
end

attr_reader :status, :auth_url
attr_reader :result, :auth_url

def as_json
return { status: }.compact_blank.merge(login_service) if stanford_restricted?

{ status: }.compact_blank
end

def login_service
{
service: {
'@id' => auth_url,
'label' => 'Stanford-affiliated? Login to play'
}
}
result.compact_blank
end

def stanford_restricted?
status.include?(:stanford_restricted)
end

def add_stanford_restricted!
status << :stanford_restricted
add_status(:stanford_restricted)
result[:service] = login_service
end

def add_location_restricted!
status << :location_restricted
add_status(:location_restricted)
end

def add_embargo!(embargo_release_date)
add_status(:embargoed)
result[:embargo] = { release_date: embargo_release_date }
end

private

def add_status(status)
result[:status] << status
end

def add_embargo!
status << :embargoed
def login_service
{
'@id' => auth_url,
'label' => 'Stanford-affiliated? Login to play'
}
end
end

def build_response
DenyResponse.new(auth_url).tap do |response|
response.add_stanford_restricted! if stanford_grants_access?
response.add_location_restricted! if location_grants_access?
response.add_embargo! if embargoed?
response.add_embargo!(media.embargo_release_date) if embargoed?
end
end

Expand Down
12 changes: 10 additions & 2 deletions spec/requests/media_auth_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@

it 'indicates that the object is stanford restricted and embargoed in the json' do
get "/media/#{druid}/file.#{format}/auth_check"
expect(response.parsed_body['status']).to eq %w[stanford_restricted embargoed]
expect(response.parsed_body).to eq(
'status' => %w[stanford_restricted embargoed],
'embargo' => { 'release_date' => Time.parse('2099-05-15').getlocal.as_json },
'service' => { "@id" => "http://www.example.com/auth/iiif", "label" => "Stanford-affiliated? Login to play" }
)

end
end

Expand All @@ -111,7 +116,10 @@

it 'indicates that the object is embargoed in the json' do
get "/media/#{druid}/file.#{format}/auth_check.js"
expect(response.parsed_body['status']).to eq ['embargoed']
expect(response.parsed_body).to eq(
'status' => ['embargoed'],
'embargo' => { 'release_date' => Time.parse('2099-05-15').getlocal.as_json }
)
end
end
end
Expand Down