Skip to content

Commit

Permalink
AR-1660 allow for a request action to be shown for resources, archiva…
Browse files Browse the repository at this point in the history
…l objects, digital objects, digital object components and accessions. Make displaying of this request action configurable for the entire instance and allow these to permittable request types to be configured at a repository level.
  • Loading branch information
payten authored and marktriggs committed Jun 19, 2017
1 parent 0c1d5a2 commit 8f8b7f8
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 92 deletions.
4 changes: 3 additions & 1 deletion common/config/config-defaults.rb
Expand Up @@ -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] = {}
Expand Down
1 change: 1 addition & 0 deletions public-new/app/controllers/accessions_controller.rb
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions public-new/app/controllers/concerns/result_info.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions public-new/app/controllers/objects_controller.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions public-new/app/controllers/resources_controller.rb
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
183 changes: 103 additions & 80 deletions public-new/app/models/record.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions public-new/app/models/request_item.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion public-new/app/views/shared/_modal_actions.html.erb
Expand Up @@ -5,7 +5,7 @@
<%# using clipboard.js: https://clipboardjs.com/ %>
<script type ="text/javascript" >setupCite("cite_modal", "<%= t('actions.clipboard') %>")</script>
<% 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 } %>
Expand Down
2 changes: 1 addition & 1 deletion 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' %>
<button type="submit" class="btn page_action request btn-default" title="<%= t('actions.request') %>">
Expand Down

0 comments on commit 8f8b7f8

Please sign in to comment.