-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set visibility based on Date Created
Closes #691.
- Loading branch information
1 parent
95761a8
commit caccdb5
Showing
7 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/change_set_persisters/plum_change_set_persister/apply_visibility_by_date.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
class PlumChangeSetPersister | ||
class ApplyVisibilityByDate | ||
attr_reader :change_set_persister, :change_set | ||
def initialize(change_set_persister:, change_set:, post_save_resource: nil) | ||
@change_set = change_set | ||
@change_set_persister = change_set_persister | ||
end | ||
|
||
def run | ||
return unless change_set.try(:set_visibility_by_date?) | ||
return unless date_object | ||
change_set.validate(visibility: calculated_visibility, rights_statement: calculated_rights_statement) | ||
change_set.sync | ||
change_set | ||
end | ||
|
||
private | ||
|
||
def date | ||
Array.wrap(change_set.resource.primary_imported_metadata.created).first | ||
end | ||
|
||
def date_object | ||
return unless date | ||
Time.zone.parse(date) | ||
rescue | ||
Rails.logger.warn("Unable to parse created date: #{change_set.resource.primary_imported_metadata.created}") | ||
nil | ||
end | ||
|
||
def limit_date | ||
Time.zone.parse("1924-01-01T00:00:00Z") | ||
end | ||
|
||
def public_access? | ||
date_object < limit_date | ||
end | ||
|
||
def calculated_visibility | ||
if public_access? | ||
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC | ||
else | ||
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE | ||
end | ||
end | ||
|
||
def calculated_rights_statement | ||
if public_access? | ||
"http://rightsstatements.org/vocab/NKC/1.0/" | ||
else | ||
"http://rightsstatements.org/vocab/InC/1.0/" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
app/views/records/edit_fields/_source_metadata_identifier.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
<% current_id = @change_set.id if @change_set %> | ||
<%= f.input :source_metadata_identifier, label: 'Source Metadata ID', input_html: { class: 'mutex detect-duplicates', data: { value: current_id, field: 'source_metadata_identifier_ssim', model: f.object.model.class.to_s } } %> | ||
<%= f.input :refresh_remote_metadata, label: 'Refresh metadata from PULFA/Voyager', as: :boolean %> | ||
<div class="row"> | ||
<div class="col-xs-3"> | ||
<%= f.input :refresh_remote_metadata, label: 'Refresh metadata from PULFA/Voyager', as: :boolean %> | ||
</div> | ||
<div class="col-xs-3"> | ||
<%= f.input :set_visibility_by_date, label: 'Set visibility by Date Created', as: :boolean %> | ||
</div> | ||
<div class="col-xs-6"> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"@context":"http://bibdata.princeton.edu/context.json", | ||
"@id":"http://bibdata.princeton.edu/bibliographic/123456", | ||
"title":{ | ||
"@value":"Earth rites : fertility rites in pre-industrial Britain", | ||
"@language":"fr" | ||
}, | ||
"language":"eng", | ||
"creator":"Bord, Janet, 1945-", | ||
"call_number":"BL980.G7 B66 1982", | ||
"extent":"xiv, 273 p. : ill. ; 24 cm.", | ||
"format":"Book", | ||
"description":"Includes index.", | ||
"publisher":"London ; New York : Granada, 1982.", | ||
"subject":"Fertility cults—Great Britain—History", | ||
"title_sort":"Earth rites : fertility rites in pre-industrial Britain / Janet and Colin Bord.", | ||
"spatial":"Great Britain", | ||
"contributor":[ | ||
"Bord, Colin" | ||
], | ||
"author":"Bord, Janet, 1945-", | ||
"created":"1982", | ||
"date":"1982" | ||
} |