diff --git a/common/config/config-defaults.rb b/common/config/config-defaults.rb
index aa9a26671a..d20b01eb61 100644
--- a/common/config/config-defaults.rb
+++ b/common/config/config-defaults.rb
@@ -433,13 +433,15 @@
# Don't display the accession ("unprocessed material") link on the main navigation menu
# AppConfig[:pui_hide][:accessions] = true
-# the following determine when the request button gets greyed out/disabled
+# the following determine when the request button is displayed
+AppConfig[:pui_requests_permitted_for_types] = [:resource, :archival_object, :accession, :digital_object, :digital_object_component]
AppConfig[:pui_requests_permitted_for_containers_only] = false # set to 'true' if you want to disable if there is no top container
# Repository-specific examples. We are using the imaginary repository code of 'foo'. Note the lower-case
AppConfig[:pui_repos] = {}
# Example:
# AppConfig[:pui_repos][{repo_code}] = {}
+# AppConfig[:pui_repos][{repo_code}][:requests_permitted_for_types] = [:resource, :archival_object, :accession, :digital_object, :digital_object_component] # for a particular repository, only enable requests for certain record types (Note this configuration will override AppConfig[:pui_requests_permitted_for_types] for the repository)
# AppConfig[:pui_repos][{repo_code}][:requests_permitted_for_containers_only] = true # for a particular repository ,disable request
# AppConfig[:pui_repos][{repo_code}][:request_email] = {email address} # the email address to send any repository requests
# AppConfig[:pui_repos][{repo_code}][:hide] = {}
diff --git a/public-new/app/controllers/accessions_controller.rb b/public-new/app/controllers/accessions_controller.rb
index 310bfc2bca..6ae57ba09b 100644
--- a/public-new/app/controllers/accessions_controller.rb
+++ b/public-new/app/controllers/accessions_controller.rb
@@ -78,6 +78,7 @@ def show
@context = []
@context.unshift({:uri => @result.resolved_repository['uri'], :crumb => @result.resolved_repository['name']})
@context.push({:uri => '', :crumb => @result.display_string })
+ fill_request_info
rescue RecordNotFound
@type = I18n.t('accession._singular')
@page_title = I18n.t('errors.error_404', :type => @type)
diff --git a/public-new/app/controllers/concerns/result_info.rb b/public-new/app/controllers/concerns/result_info.rb
index ae1d43d5ed..c04ac8bb3d 100644
--- a/public-new/app/controllers/concerns/result_info.rb
+++ b/public-new/app/controllers/concerns/result_info.rb
@@ -16,18 +16,17 @@ def breadcrumb_info
context
end
- def fill_request_info(resource = false)
+ def fill_request_info
@request = @result.build_request_item
if @request
hier = ''
@context.each_with_index { |c, i| hier << c[:crumb] << '. ' unless i == 0 || c[:uri].blank? }
@request[:hierarchy] = hier.strip
- else
- # FIXME
- raise 'nil @request.. do something'
end
+ p ['fill_request_info', @request]
+
@request
end
diff --git a/public-new/app/controllers/objects_controller.rb b/public-new/app/controllers/objects_controller.rb
index 98c4e495f0..e047d2fd91 100644
--- a/public-new/app/controllers/objects_controller.rb
+++ b/public-new/app/controllers/objects_controller.rb
@@ -90,11 +90,11 @@ def show
@repo_info = @result.repository_information
@page_title = @result.display_string
@context = @result.breadcrumb
+ fill_request_info
if @result['primary_type'] == 'digital_object' || @result['primary_type'] == 'digital_object_component'
@dig = process_digital(@result['json'])
else
- @dig = process_digital_instance(@result['json']['instances'])
- fill_request_info
+ @dig = process_digital_instance(@result['json']['instances'])
process_extents(@result['json'])
end
rescue Exception => error
diff --git a/public-new/app/controllers/resources_controller.rb b/public-new/app/controllers/resources_controller.rb
index f873893042..1b31df97b9 100644
--- a/public-new/app/controllers/resources_controller.rb
+++ b/public-new/app/controllers/resources_controller.rb
@@ -140,7 +140,7 @@ def show
@page_title = "#{I18n.t('resource._singular')}: #{strip_mixed_content(@result.display_string)}"
@context = [{:uri => @repo_info['top']['uri'], :crumb => @repo_info['top']['name']}, {:uri => nil, :crumb => process_mixed_content(@result.display_string)}]
# @rep_image = get_rep_image(@result['json']['instances'])
- fill_request_info(true)
+ fill_request_info
# GONE # @tree = fetch_tree(uri)
rescue RecordNotFound
@type = I18n.t('resource._singular')
@@ -169,7 +169,7 @@ def infinite
@repo_info = @result.repository_information
@page_title = "#{I18n.t('resource._singular')}: #{strip_mixed_content(@result.display_string)}"
@context = [{:uri => @repo_info['top']['uri'], :crumb => @repo_info['top']['name']}, {:uri => nil, :crumb => process_mixed_content(@result.display_string)}]
- fill_request_info(true)
+ fill_request_info
@ordered_records = archivesspace.get_record(@root_uri + '/ordered_records').json.fetch('uris')
rescue RecordNotFound
@type = I18n.t('resource._singular')
@@ -223,7 +223,7 @@ def inventory
@repo_info = @result.repository_information
@page_title = "#{I18n.t('resource._singular')}: #{strip_mixed_content(@result.display_string)}"
@context = [{:uri => @repo_info['top']['uri'], :crumb => @repo_info['top']['name']}, {:uri => nil, :crumb => process_mixed_content(@result.display_string)}]
- fill_request_info(true)
+ fill_request_info
# top container stuff ... sets @records
fetch_containers(uri, "#{uri}/inventory", params)
diff --git a/public-new/app/models/record.rb b/public-new/app/models/record.rb
index ccc5322077..875370d7e2 100644
--- a/public-new/app/models/record.rb
+++ b/public-new/app/models/record.rb
@@ -68,87 +68,18 @@ def note(type)
end
def build_request_item
- return if resolved_resource.nil?
-
- has_top_container = false
- container_info = {}
-
- %i(top_container_url container location_title location_url restriction_ends machine barcode).each {|sym| container_info[sym] = [] }
-
- unless json['instances'].blank?
- json['instances'].each do |instance|
- sub_container = instance.dig('sub_container')
-
- next if sub_container.nil?
-
- top_container_uri = sub_container.dig('top_container', 'ref');
- top_container = top_container_for_uri(top_container_uri)
-
- next if container_info.fetch(:top_container_url).include?(top_container_uri)
-
- hsh = {
- :container => parse_sub_container_display_string(sub_container, instance),
- :top_container_url => top_container_uri,
- }
-
- if top_container
- has_top_container = true
- top_container_json = ASUtils.json_parse(top_container.fetch('json'))
- hsh[:barcode] = top_container_json.dig('barcode')
-
- location = parse_top_container_location(top_container_json)
-
- if (location)
- hsh[:location_title] = location.dig('title')
- hsh[:location_url] = location.dig('uri')
- else
- hsh[:location_title] = ''
- hsh[:location_url] = ''
- end
- else
- hsh[:barcode] = ''
- hsh[:location_title] = ''
- hsh[:location_url] = ''
- end
-
- restricts = top_container_json.dig('active_restrictions')
- if restricts
- ends = ''
- restricts.each do |r|
- lar = r.dig('local_access_restriction_type')
- container_info[:machine] += lar if lar
- ends << ' ' << r.dig('end') || ''
- end
- unless ends == ''
- container_info[:restriction_ends] << ends.strip
- end
- end
-
- hsh.keys.each {|sym| container_info[sym].push(hsh[sym] || '')}
- end
- end
-
- return if (!has_top_container && !RequestItem::allow_nontops(resolved_repository.dig('repo_code')))
-
- request = RequestItem.new(container_info)
-
- request[:request_uri] = uri
- request[:repo_name] = resolved_repository.dig('name')
- request[:repo_code] = resolved_repository.dig('repo_code')
- request[:repo_uri] = resolved_repository.dig('uri')
- request[:cite] = cite
- request[:identifier] = identifier
- request[:title] = display_string
-
- note = note('accessrestrict')
- unless note.blank?
- request[:restrict] = note['note_text']
+ return unless RequestItem.allow_for_type(resolved_repository.dig('repo_code'), primary_type.intern)
+
+ if ['resource', 'archival_object'].include?(primary_type)
+ build_resource_request_item
+ elsif ['digital_object', 'digital_object_component'].include?(primary_type)
+ build_digital_object_request_item
+ elsif 'accession' == primary_type
+ build_accession_request_item
+ else
+ # not supported!
+ nil
end
-
- request[:resource_id] = resolved_resource.dig('uri')
- request[:resource_name] = resolved_resource.dig('title') || ['unknown']
-
- request
end
private
@@ -486,4 +417,96 @@ def digital_object_for_uri(uri)
end
end
+ def build_resource_request_item
+ return if resolved_resource.nil?
+
+ has_top_container = false
+ container_info = {}
+
+ %i(top_container_url container location_title location_url restriction_ends machine barcode).each {|sym| container_info[sym] = [] }
+
+ unless json['instances'].blank?
+ json['instances'].each do |instance|
+ sub_container = instance.dig('sub_container')
+
+ next if sub_container.nil?
+
+ top_container_uri = sub_container.dig('top_container', 'ref');
+ top_container = top_container_for_uri(top_container_uri)
+
+ next if container_info.fetch(:top_container_url).include?(top_container_uri)
+
+ hsh = {
+ :container => parse_sub_container_display_string(sub_container, instance),
+ :top_container_url => top_container_uri,
+ }
+
+ if top_container
+ has_top_container = true
+ top_container_json = ASUtils.json_parse(top_container.fetch('json'))
+ hsh[:barcode] = top_container_json.dig('barcode')
+
+ location = parse_top_container_location(top_container_json)
+
+ if (location)
+ hsh[:location_title] = location.dig('title')
+ hsh[:location_url] = location.dig('uri')
+ else
+ hsh[:location_title] = ''
+ hsh[:location_url] = ''
+ end
+ else
+ hsh[:barcode] = ''
+ hsh[:location_title] = ''
+ hsh[:location_url] = ''
+ end
+
+ restricts = top_container_json.dig('active_restrictions')
+ if restricts
+ ends = ''
+ restricts.each do |r|
+ lar = r.dig('local_access_restriction_type')
+ container_info[:machine] += lar if lar
+ ends << ' ' << r.dig('end') || ''
+ end
+ unless ends == ''
+ container_info[:restriction_ends] << ends.strip
+ end
+ end
+
+ hsh.keys.each {|sym| container_info[sym].push(hsh[sym] || '')}
+ end
+ end
+
+ return if (!has_top_container && !RequestItem::allow_nontops(resolved_repository.dig('repo_code')))
+
+ request = RequestItem.new(container_info)
+
+ request[:request_uri] = uri
+ request[:repo_name] = resolved_repository.dig('name')
+ request[:repo_code] = resolved_repository.dig('repo_code')
+ request[:repo_uri] = resolved_repository.dig('uri')
+ request[:cite] = cite
+ request[:identifier] = identifier
+ request[:title] = display_string
+
+ note = note('accessrestrict')
+ unless note.blank?
+ request[:restrict] = note['note_text']
+ end
+
+ request[:resource_id] = resolved_resource.dig('uri')
+ request[:resource_name] = resolved_resource.dig('title') || ['unknown']
+
+ request
+ end
+
+ def build_digital_object_request_item
+ RequestItem.new({})
+ end
+
+ def build_accession_request_item
+ RequestItem.new({})
+ end
+
end
diff --git a/public-new/app/models/request_item.rb b/public-new/app/models/request_item.rb
index fd79052da2..262763cb9e 100644
--- a/public-new/app/models/request_item.rb
+++ b/public-new/app/models/request_item.rb
@@ -6,6 +6,21 @@ class RequestItem < Struct.new(:user_name, :user_email, :date, :note, :hierarchy
:top_container_url, :container, :barcode, :location_title,
:location_url, :repo_uri, :repo_code)
+ def RequestItem.allow_for_type(repository_code, record_type)
+ p ['allow_for_type', repository_code, record_type]
+ fallback = AppConfig[:pui_requests_permitted_for_types].include?(record_type)
+ p ['fallback', fallback]
+ p ['config', AppConfig[:pui_repos]]
+ p ['repository_code.to_s.downcase', repository_code.to_s.downcase]
+ allowed_repo_types = AppConfig[:pui_repos].dig(repository_code.to_s.downcase, :requests_permitted_for_types) if repository_code
+ p ['allowed_repo_types', allowed_repo_types]
+ if allowed_repo_types
+ allowed_repo_types.include?(record_type)
+ else
+ fallback
+ end
+ end
+
def RequestItem.allow_nontops(repo_code)
allow = nil
rep_allow = nil
diff --git a/public-new/app/views/shared/_modal_actions.html.erb b/public-new/app/views/shared/_modal_actions.html.erb
index c4d13c81a4..0f8feb8562 100644
--- a/public-new/app/views/shared/_modal_actions.html.erb
+++ b/public-new/app/views/shared/_modal_actions.html.erb
@@ -5,7 +5,7 @@
<%# using clipboard.js: https://clipboardjs.com/ %>
-<% if defined?(@request) %>
+<% if defined?(@request) && !@request.nil? %>
<% req = render partial: 'shared/request_form' %>
<%= render partial: 'shared/modal', locals: {:modal_id => 'request_modal', :title => t('actions.request'),
:modal_body => req } %>
diff --git a/public-new/app/views/shared/_request_page_action.html.erb b/public-new/app/views/shared/_request_page_action.html.erb
index 7dc3a83df1..2eeb391176 100644
--- a/public-new/app/views/shared/_request_page_action.html.erb
+++ b/public-new/app/views/shared/_request_page_action.html.erb
@@ -1,4 +1,4 @@
-<% if defined?(@request) %>
+<% if defined?(@request) && !@request.nil? %>
<%= form_tag "#{@request[:request_uri]}/request", :id => 'request_sub' do |f| %>
<%= render partial: 'shared/request_hiddens' %>