-
Notifications
You must be signed in to change notification settings - Fork 136
Add orcid sub-property type to compound metadata #7484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: nested-compound-metadata-foundation
Are you sure you want to change the base?
Changes from 13 commits
294f526
855bcb7
2566f88
641f40b
eb53303
17f5e45
fcc45ba
0178608
d213ad9
9ff128b
2f2cd5f
d5c4104
74e4e5e
28ce594
b396796
8dc12f9
628a20d
5557740
a44ffe6
3a586c2
4d37dde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Hyrax | ||
| # Validates every `type: orcid` sub-property value on a compound's persisted | ||
| # rows. A blank value is allowed (required-ness lives in | ||
| # {Hyrax::CompoundEntryValidator}); a non-blank value must match | ||
| # {Hyrax::OrcidValidator::ORCID_REGEXP} in either the bare-iD form | ||
| # (`0000-0000-0000-0000`) or the full `https://orcid.org/` URL form. | ||
| # | ||
| # Adds one error per offending row to `:base`, naming the compound and the | ||
| # offending sub-property — same keying convention {Hyrax::CompoundEntryValidator} | ||
| # uses so work and collection forms render the message cleanly. See | ||
| # documentation/compound_fields.md. | ||
| class OrcidSubpropertyValidator < ActiveModel::Validator | ||
| def validate(record) | ||
| schema = Hyrax::CompoundSchema.for(schema_source(record)) | ||
| schema.definitions.each do |name, definition| | ||
| next unless record.respond_to?(name) | ||
| validate_compound(record, name, definition) | ||
| end | ||
| rescue StandardError => e | ||
| Hyrax.logger.debug("OrcidSubpropertyValidator: #{e.message}") | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # The schema declarations live on the underlying resource, not the form | ||
| # wrapper: a Reform form exposes it as `model`. Fall back to the record | ||
| # itself (e.g. a plain ActiveModel object in unit tests). | ||
| def schema_source(record) | ||
| record.respond_to?(:model) ? record.model : record | ||
| end | ||
|
|
||
| def validate_compound(record, name, definition) | ||
| orcid_keys = definition[:subproperties].select { |_key, spec| spec[:type].to_s == 'orcid' }.keys | ||
| return if orcid_keys.empty? | ||
|
|
||
| Array(record.public_send(name)).each do |entry| | ||
| next unless entry.is_a?(Hash) | ||
| orcid_keys.each do |sub_property| | ||
| value = entry[sub_property] || entry[sub_property.to_sym] | ||
| next if value.blank? | ||
| next if Hyrax::OrcidValidator::ORCID_REGEXP.match?(value.to_s) | ||
| record.errors.add(:base, message_for(name, sub_property, value)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def message_for(name, sub_property, value) | ||
| I18n.t('hyrax.compound_fields.orcid.invalid', | ||
| compound: compound_label(name), | ||
| field: subproperty_label(name, sub_property), | ||
| value: value, | ||
| default: %("#{value}" is not a valid ORCID iD for #{compound_label(name)} > #{subproperty_label(name, sub_property)}.)) | ||
| end | ||
|
|
||
| def compound_label(name) | ||
| I18n.t("hyrax.compound_fields.#{name}.label", default: name.to_s.humanize) | ||
| end | ||
|
|
||
| def subproperty_label(compound_name, sub_property) | ||
| I18n.t("hyrax.compound_fields.#{compound_name}.#{sub_property}", default: sub_property.to_s.humanize) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -870,6 +870,11 @@ en: | |
| title: Title | ||
| participant_name: Name | ||
| participant_role: Role | ||
| orcid: | ||
|
Comment on lines
869
to
+873
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Holding on this one. It was intentional decision to NOT add a |
||
| badge_alt: ORCID iD | ||
| badge_aria: ORCID iD for %{name} | ||
| invalid: "%{compound} > %{field}: \"%{value}\" is not a valid ORCID iD" | ||
| placeholder: 0000-0000-0000-0000 | ||
| identifiers: | ||
| label: Identifiers | ||
| identifier: Identifier | ||
|
|
@@ -1420,6 +1425,9 @@ en: | |
| unknown_parent: "m3 profile subproperty `%{property}` declares `subproperty_of: %{parent}`, but `%{parent}` is not a declared `type: hash` compound property" | ||
| controlled_without_source: "m3 profile compound subproperty `%{property}` is `type: controlled` but declares neither `authority` nor `values`" | ||
| top_level_indexing: "m3 profile compound property `%{property}` must not declare top-level `indexing`; declare `indexing` (or `index_keys`) on each subproperty instead" | ||
| orcid_with_option_source: "m3 profile compound subproperty `%{property}` is `type: orcid` and must not declare `authority` or `values` (ORCID iDs are free-text, not a controlled vocabulary)" | ||
| orcid_badge_for_self: "m3 profile compound subproperty `%{property}` declares `badge_for: %{property}` (it cannot point at itself)" | ||
| orcid_badge_for_unknown_sibling: "m3 profile compound subproperty `%{property}` declares `badge_for: %{target}`, but `%{target}` is not a sibling sub-property of `%{parent}`" | ||
| redirects_validator: | ||
| errors: | ||
| invalid_available_on: "m3 profile `redirects` property must be available on at least one work or collection class declared in this profile" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.