diff --git a/Gemfile b/Gemfile index 2c799a17..a49fdd07 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index ab0736f8..0822044a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -428,7 +428,7 @@ DEPENDENCIES dalli debug dlss-capistrano - dor-rights-auth + dor-rights-auth (~> 1.8) faraday honeybadger http diff --git a/app/models/stacks_media_stream.rb b/app/models/stacks_media_stream.rb index 9c045ac6..670d91fe 100644 --- a/app/models/stacks_media_stream.rb +++ b/app/models/stacks_media_stream.rb @@ -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 diff --git a/app/models/stacks_rights.rb b/app/models/stacks_rights.rb index b0b21e64..90863ac1 100644 --- a/app/models/stacks_rights.rb +++ b/app/models/stacks_rights.rb @@ -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) diff --git a/app/services/media_authentication_json.rb b/app/services/media_authentication_json.rb index 5571e05a..32b6265a 100644 --- a/app/services/media_authentication_json.rb +++ b/app/services/media_authentication_json.rb @@ -19,24 +19,13 @@ 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? @@ -44,15 +33,30 @@ def 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 @@ -60,7 +64,7 @@ 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 diff --git a/spec/requests/media_auth_request_spec.rb b/spec/requests/media_auth_request_spec.rb index fd589052..e1f38821 100644 --- a/spec/requests/media_auth_request_spec.rb +++ b/spec/requests/media_auth_request_spec.rb @@ -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 @@ -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