Skip to content

Commit

Permalink
Merge pull request #1009 from sul-dlss/embargo-relase-date
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Nov 6, 2023
2 parents 9c0cfae + 494047c commit 059cfe7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,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

0 comments on commit 059cfe7

Please sign in to comment.