From d96b85c62344dd336a86d0e9aa07ec58fdeda4f7 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 26 Jan 2024 17:27:24 -0500 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=8E=81=20Implement=20a=20CollectionRe?= =?UTF-8?q?source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove decorating of PdcmCollection and generate a CollectionResource. Address some inconsistent behavior between Collection & CollectionResource. Temporarily address bulkrax_identifier inconsistencies, to be moved into Bulkrax at a later point. These came in via some contribute-back work. --- app/forms/collection_resource_form.rb | 9 +++++++ .../forms/pcdm_collection_form_decorator.rb | 6 ----- app/indexers/collection_indexer.rb | 1 + app/indexers/collection_resource_indexer.rb | 18 ++++++++++++++ app/indexers/concerns/hyku_indexing.rb | 1 + ...on_decorator.rb => collection_resource.rb} | 13 +++++----- .../hyrax/ability/collection_ability.rb | 8 ++++--- .../find_by_bulkrax_identifier.rb | 2 +- config/initializers/hyrax.rb | 3 ++- config/metadata/collection_resource.yaml | 24 +++++++++++++++++++ spec/forms/collection_resource_form_spec.rb | 13 ++++++++++ .../collection_resource_indexer_spec.rb | 13 ++++++++++ ...or_spec.rb => collection_resource_spec.rb} | 7 ++++-- 13 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 app/forms/collection_resource_form.rb delete mode 100644 app/forms/hyrax/forms/pcdm_collection_form_decorator.rb create mode 100644 app/indexers/collection_resource_indexer.rb rename app/models/{hyrax/pcdm_collection_decorator.rb => collection_resource.rb} (53%) create mode 100644 config/metadata/collection_resource.yaml create mode 100644 spec/forms/collection_resource_form_spec.rb create mode 100644 spec/indexers/collection_resource_indexer_spec.rb rename spec/models/{hyrax/pcdm_collection_decorator_spec.rb => collection_resource_spec.rb} (65%) diff --git a/app/forms/collection_resource_form.rb b/app/forms/collection_resource_form.rb new file mode 100644 index 000000000..149d1bce9 --- /dev/null +++ b/app/forms/collection_resource_form.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` +class CollectionResourceForm < Hyrax::Forms::PcdmCollectionForm + include Hyrax::FormFields(:basic_metadata) + include Hyrax::FormFields(:collection_resource) + include CollectionAccessFiltering +end diff --git a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb deleted file mode 100644 index 7aceeca04..000000000 --- a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -Hyrax::Forms::PcdmCollectionForm.class_eval do - include Hyrax::FormFields(:basic_metadata) - include CollectionAccessFiltering -end diff --git a/app/indexers/collection_indexer.rb b/app/indexers/collection_indexer.rb index 11e14de1a..647055249 100644 --- a/app/indexers/collection_indexer.rb +++ b/app/indexers/collection_indexer.rb @@ -9,6 +9,7 @@ class CollectionIndexer < Hyrax::CollectionIndexer def generate_solr_document super.tap do |solr_doc| solr_doc['bulkrax_identifier_tesim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) + solr_doc['bulkrax_identifier_sim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) solr_doc["account_cname_tesim"] = Site.instance&.account&.cname solr_doc['account_institution_name_ssim'] = Site.instance.institution_label end diff --git a/app/indexers/collection_resource_indexer.rb b/app/indexers/collection_resource_indexer.rb new file mode 100644 index 000000000..4a1bd0b09 --- /dev/null +++ b/app/indexers/collection_resource_indexer.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` +class CollectionResourceIndexer < Hyrax::Indexers::PcdmCollectionIndexer + include Hyrax::Indexer(:basic_metadata) + include Hyrax::Indexer(:collection_resource) + + def to_solr + super.tap do |index_document| + # TODO: Do we need the indexing for bulkrax_identifier? If it is in the resource yml, it is probably redundant. + solr_doc['bulkrax_identifier_tesim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) + solr_doc['bulkrax_identifier_sim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) + index_document["account_cname_tesim"] = Site.instance&.account&.cname + index_document['account_institution_name_ssim'] = Site.instance.institution_label + end + end +end diff --git a/app/indexers/concerns/hyku_indexing.rb b/app/indexers/concerns/hyku_indexing.rb index ea97bc9bc..b5e3cc301 100644 --- a/app/indexers/concerns/hyku_indexing.rb +++ b/app/indexers/concerns/hyku_indexing.rb @@ -14,6 +14,7 @@ module HykuIndexing solr_doc['account_cname_tesim'] = Site.instance&.account&.cname solr_doc['bulkrax_identifier_tesim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) + solr_doc['bulkrax_identifier_sim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) solr_doc['account_institution_name_ssim'] = Site.instance.institution_label # TODO: Reinstate once valkyrie fileset work is complete - https://github.com/scientist-softserv/hykuup_knapsack/issues/34 solr_doc['all_text_tsimv'] = full_text(object.file_sets.first&.id) if object.kind_of?(ActiveFedora::Base) diff --git a/app/models/hyrax/pcdm_collection_decorator.rb b/app/models/collection_resource.rb similarity index 53% rename from app/models/hyrax/pcdm_collection_decorator.rb rename to app/models/collection_resource.rb index 77788ae42..1ab439e6e 100644 --- a/app/models/hyrax/pcdm_collection_decorator.rb +++ b/app/models/collection_resource.rb @@ -1,13 +1,14 @@ # frozen_string_literal: true -# OVERRIDE Hyrax 5.0 to add basic metadata and AF methods to collection - -Hyrax::PcdmCollection.class_eval do +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` +class CollectionResource < Hyrax::PcdmCollection include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:collection_resource) include Hyrax::ArResource - - # This module provides the #public?, #private?, #restricted? methods; consider contributing this - # back to Hyrax; but that decision requires further discussion on architecture. + # This module provides the #public?, #private?, #restricted? methods; consider + # contributing this back to Hyrax; but that decision requires further discussion + # on architecture. # @see https://samvera.slack.com/archives/C0F9JQJDQ/p1705421588370699 Slack discussion thread. include Hyrax::Permissions::Readable prepend OrderAlready.for(:creator) diff --git a/app/models/concerns/hyrax/ability/collection_ability.rb b/app/models/concerns/hyrax/ability/collection_ability.rb index 80d181ae4..bd3b05995 100644 --- a/app/models/concerns/hyrax/ability/collection_ability.rb +++ b/app/models/concerns/hyrax/ability/collection_ability.rb @@ -11,7 +11,7 @@ module CollectionAbility # rubocop:disable Metrics/PerceivedComplexity # rubocop:disable Metrics/CyclomaticComplexity def collection_abilities - models = [Hyrax::PcdmCollection, Hyrax.config.collection_class].uniq + models = [Collection, Hyrax::PcdmCollection, Hyrax.config.collection_class].uniq if admin? models.each do |collection_model| can :manage, collection_model @@ -107,8 +107,10 @@ def collection_abilities unless ActiveModel::Type::Boolean.new.cast( ENV.fetch('HYKU_RESTRICT_CREATE_AND_DESTROY_PERMISSIONS', nil) ) - can %i[destroy manage_discovery manage_items_in_collection], Hyrax::PcdmCollection do |collection| - test_edit(collection.id) + models.each do |collection_model| + can %i[destroy manage_discovery manage_items_in_collection], collection_model do |collection| + test_edit(collection.id) + end end end end diff --git a/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb b/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb index aa86a35a9..91e8396d7 100644 --- a/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb +++ b/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb @@ -17,7 +17,7 @@ def initialize(query_service:) end def find_by_bulkrax_identifier(identifier:, use_valkyrie: true) - af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first + af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first || ActiveFedora::Base.where("bulkrax_identifier_tesim:#{identifier}").first return af_object unless use_valkyrie diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index 07efeacac..c5200efab 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -15,7 +15,8 @@ # Identify the model class name that will be used for Collections in your app # (i.e. ::Collection for ActiveFedora, Hyrax::PcdmCollection for Valkyrie) # config.collection_model = '::Collection' - config.collection_model = 'Hyrax::PcdmCollection' + # Injected via `rails g hyrax:collection_resource CollectionResource` + config.collection_model = 'CollectionResource' # Identify the model class name that will be used for Admin Sets in your app # (i.e. AdminSet for ActiveFedora, Hyrax::AdministrativeSet for Valkyrie) diff --git a/config/metadata/collection_resource.yaml b/config/metadata/collection_resource.yaml new file mode 100644 index 000000000..9e9e232fc --- /dev/null +++ b/config/metadata/collection_resource.yaml @@ -0,0 +1,24 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` + +attributes: {} diff --git a/spec/forms/collection_resource_form_spec.rb b/spec/forms/collection_resource_form_spec.rb new file mode 100644 index 000000000..4e05d208b --- /dev/null +++ b/spec/forms/collection_resource_form_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` +require 'rails_helper' +require 'valkyrie/specs/shared_specs' + +RSpec.describe CollectionResourceForm do + let(:change_set) { described_class.new(resource) } + let(:resource) { CollectionResource.new } + + it_behaves_like 'a Valkyrie::ChangeSet' +end diff --git a/spec/indexers/collection_resource_indexer_spec.rb b/spec/indexers/collection_resource_indexer_spec.rb new file mode 100644 index 000000000..e2e219b67 --- /dev/null +++ b/spec/indexers/collection_resource_indexer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/indexers' + +RSpec.describe CollectionResourceIndexer do + let(:indexer_class) { described_class } + let(:resource) { CollectionResource.new } + + it_behaves_like 'a Hyrax::Resource indexer' +end diff --git a/spec/models/hyrax/pcdm_collection_decorator_spec.rb b/spec/models/collection_resource_spec.rb similarity index 65% rename from spec/models/hyrax/pcdm_collection_decorator_spec.rb rename to spec/models/collection_resource_spec.rb index 29c4c2d11..e68fa754e 100644 --- a/spec/models/hyrax/pcdm_collection_decorator_spec.rb +++ b/spec/models/collection_resource_spec.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/hydra_works' -RSpec.describe Hyrax::PcdmCollection do +RSpec.describe CollectionResource do subject(:collection) { described_class.new } it_behaves_like 'a Hyrax::PcdmCollection' From 2115f7c4b4d99169858627d03485f661f5453534 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 26 Jan 2024 18:30:51 -0500 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=8E=81=20Create=20AdminSetResource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creates Hyku's version of Hyrax's Hyrax::AdministrativeSet rather than using the decorator pattern. --- app/forms/hyrax/admin_set_resource_form.rb | 5 +++++ .../forms/admin/administrative_set_form_decorator.rb | 11 ----------- app/indexers/admin_set_resource_indexer.rb | 4 ++++ ...trative_set_decorator.rb => admin_set_resource.rb} | 4 +--- app/models/concerns/hyrax/ability/work_ability.rb | 2 +- config/initializers/hyrax.rb | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) create mode 100644 app/forms/hyrax/admin_set_resource_form.rb delete mode 100644 app/forms/hyrax/forms/admin/administrative_set_form_decorator.rb create mode 100644 app/indexers/admin_set_resource_indexer.rb rename app/models/{hyrax/administrative_set_decorator.rb => admin_set_resource.rb} (52%) diff --git a/app/forms/hyrax/admin_set_resource_form.rb b/app/forms/hyrax/admin_set_resource_form.rb new file mode 100644 index 000000000..553ba91ff --- /dev/null +++ b/app/forms/hyrax/admin_set_resource_form.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class AdminSetResourceForm < Hyrax::Forms::AdministrativeSetForm + include CollectionAccessFiltering +end diff --git a/app/forms/hyrax/forms/admin/administrative_set_form_decorator.rb b/app/forms/hyrax/forms/admin/administrative_set_form_decorator.rb deleted file mode 100644 index a3d35a9ab..000000000 --- a/app/forms/hyrax/forms/admin/administrative_set_form_decorator.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Hyrax - module Forms - module AdministrativeSetFormDecorator - include CollectionAccessFiltering - end - end -end - -Hyrax::Forms::AdministrativeSetForm.prepend(Hyrax::Forms::AdministrativeSetFormDecorator) diff --git a/app/indexers/admin_set_resource_indexer.rb b/app/indexers/admin_set_resource_indexer.rb new file mode 100644 index 000000000..689159cff --- /dev/null +++ b/app/indexers/admin_set_resource_indexer.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class AdminSetResourceIndexer < Hyrax::Indexers::AdministrativeSetIndexer +end \ No newline at end of file diff --git a/app/models/hyrax/administrative_set_decorator.rb b/app/models/admin_set_resource.rb similarity index 52% rename from app/models/hyrax/administrative_set_decorator.rb rename to app/models/admin_set_resource.rb index 46e368386..6a04962a2 100644 --- a/app/models/hyrax/administrative_set_decorator.rb +++ b/app/models/admin_set_resource.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax 5.0 to add AF methods to collection - -Hyrax::AdministrativeSet.class_eval do +class AdminSetResource < Hyrax::AdministrativeSet include Hyrax::ArResource include Hyrax::Permissions::Readable end diff --git a/app/models/concerns/hyrax/ability/work_ability.rb b/app/models/concerns/hyrax/ability/work_ability.rb index 9d7daebc0..8c35a4843 100644 --- a/app/models/concerns/hyrax/ability/work_ability.rb +++ b/app/models/concerns/hyrax/ability/work_ability.rb @@ -32,7 +32,7 @@ def admin_set_with_deposit? return false if ids.empty? - Hyrax.custom_queries.find_ids_by_model(model: Hyrax::AdministrativeSet, ids:).any? + Hyrax.custom_queries.find_ids_by_model(model: Hyrax.config.admin_set_model, ids:).any? end end end diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index c5200efab..bf20b04a8 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -21,7 +21,7 @@ # Identify the model class name that will be used for Admin Sets in your app # (i.e. AdminSet for ActiveFedora, Hyrax::AdministrativeSet for Valkyrie) # config.admin_set_model = 'AdminSet' - config.admin_set_model = 'Hyrax::AdministrativeSet' + config.admin_set_model = 'AdminSetResource' # The email address that messages submitted via the contact page are sent to # This is set by account settings # config.contact_email = 'changeme@example.com' From e3ff454d2f0e8aa99dc01166a9980a4d8b9bf4d8 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 26 Jan 2024 18:41:26 -0500 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=8E=81=20Adjust=20Collection=20&=20Ad?= =?UTF-8?q?min=20Set=20Configurations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the addition of CollectionResource and AdminSetResource, these configurations need to change. --- app/services/roles_service.rb | 132 ++++++++++++++++++---------------- config/initializers/wings.rb | 6 +- 2 files changed, 75 insertions(+), 63 deletions(-) diff --git a/app/services/roles_service.rb b/app/services/roles_service.rb index e7f418b10..284c61e3d 100644 --- a/app/services/roles_service.rb +++ b/app/services/roles_service.rb @@ -233,9 +233,12 @@ def seed_qa_users! class GrantWorkflowRolesForAllAdminSetsJob < Hyrax::ApplicationJob def perform - AdminSet.find_each do |admin_set| - Hyrax::Workflow::PermissionGrantor - .grant_default_workflow_roles!(permission_template: admin_set.permission_template) + models = [AdminSet, Hyrax::AdministrativeSet, Hyrax.config.admin_set_class].uniq + models.each do |admin_set_model| + Hyrax.query_service.find_all_of_model(model: admin_set_model) do |admin_set| + Hyrax::Workflow::PermissionGrantor + .grant_default_workflow_roles!(permission_template: admin_set.permission_template) + end end end end @@ -243,35 +246,39 @@ def perform class CreateCollectionAccessesJob < Hyrax::ApplicationJob # rubocop:disable Metrics/MethodLength def perform - Collection.find_each do |c| - pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: c.id) - original_access_grants_count = pt.access_grants.count - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::MANAGE, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: Ability.admin_group_name - ) - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::MANAGE, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: 'collection_manager' - ) - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::VIEW, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: 'collection_editor' - ) - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::VIEW, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: 'collection_reader' - ) - - pt.reset_access_controls_for(collection: c) if pt.access_grants.count != original_access_grants_count + models = [Collection, Hyrax::PcdmCollection, Hyrax.config.collection_class].uniq + models.each do |collection_model| + Hyrax.query_service.find_all_of_model(model: collection_model) do |c| + + pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: c.id) + original_access_grants_count = pt.access_grants.count + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::MANAGE, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: Ability.admin_group_name + ) + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::MANAGE, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: 'collection_manager' + ) + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::VIEW, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: 'collection_editor' + ) + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::VIEW, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: 'collection_reader' + ) + + pt.reset_access_controls_for(collection: c) if pt.access_grants.count != original_access_grants_count + end end end # rubocop:enable Metrics/MethodLength @@ -280,35 +287,38 @@ def perform class CreateAdminSetAccessesJob < Hyrax::ApplicationJob # rubocop:disable Metrics/MethodLength def perform - AdminSet.find_each do |as| - pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: as.id) - original_access_grants_count = pt.access_grants.count - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::MANAGE, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: Ability.admin_group_name - ) - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::DEPOSIT, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: 'work_depositor' - ) - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::DEPOSIT, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: 'work_editor' - ) - - pt.access_grants.find_or_create_by!( - access: Hyrax::PermissionTemplateAccess::VIEW, - agent_type: Hyrax::PermissionTemplateAccess::GROUP, - agent_id: 'work_editor' - ) - - pt.reset_access_controls_for(collection: as) if pt.access_grants.count != original_access_grants_count + models = [AdminSet, Hyrax::AdministrativeSet, Hyrax.config.admin_set_class].uniq + models.each do |admin_set_model| + Hyrax.query_service.find_all_of_model(model: admin_set_model) do |as| + pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: as.id) + original_access_grants_count = pt.access_grants.count + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::MANAGE, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: Ability.admin_group_name + ) + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::DEPOSIT, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: 'work_depositor' + ) + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::DEPOSIT, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: 'work_editor' + ) + + pt.access_grants.find_or_create_by!( + access: Hyrax::PermissionTemplateAccess::VIEW, + agent_type: Hyrax::PermissionTemplateAccess::GROUP, + agent_id: 'work_editor' + ) + + pt.reset_access_controls_for(collection: as) if pt.access_grants.count != original_access_grants_count + end end end # rubocop:enable Metrics/MethodLength diff --git a/config/initializers/wings.rb b/config/initializers/wings.rb index 93673855c..cf5cac084 100644 --- a/config/initializers/wings.rb +++ b/config/initializers/wings.rb @@ -11,8 +11,10 @@ end Wings::ModelRegistry.register(Collection, Collection) Wings::ModelRegistry.register(Hyrax::PcdmCollection, Collection) + Wings::ModelRegistry.register(CollectionResource, Collection) Wings::ModelRegistry.register(Hyrax::AdministrativeSet, AdminSet) Wings::ModelRegistry.register(AdminSet, AdminSet) + Wings::ModelRegistry.register(AdminSetResource, AdminSet) Valkyrie::MetadataAdapter.register( Freyja::MetadataAdapter.new, @@ -83,9 +85,9 @@ ].include?(klass_name) "#{klass_name}Resource".constantize elsif 'Collection' == klass_name - Hyrax::PcdmCollection + CollectionResource elsif 'AdminSet' == klass_name - Hyrax::AdministrativeSet + AdminSetResource else klass_name.constantize end From cb8cc0c84420c064dee5d493095aae2b9da5eb2e Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 26 Jan 2024 18:49:51 -0500 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=A7=B9=20Clean=20up=20rubocop=20viola?= =?UTF-8?q?tions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/indexers/admin_set_resource_indexer.rb | 2 +- app/services/roles_service.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/indexers/admin_set_resource_indexer.rb b/app/indexers/admin_set_resource_indexer.rb index 689159cff..f8555ef99 100644 --- a/app/indexers/admin_set_resource_indexer.rb +++ b/app/indexers/admin_set_resource_indexer.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true class AdminSetResourceIndexer < Hyrax::Indexers::AdministrativeSetIndexer -end \ No newline at end of file +end diff --git a/app/services/roles_service.rb b/app/services/roles_service.rb index 284c61e3d..cfbce7a5c 100644 --- a/app/services/roles_service.rb +++ b/app/services/roles_service.rb @@ -249,7 +249,6 @@ def perform models = [Collection, Hyrax::PcdmCollection, Hyrax.config.collection_class].uniq models.each do |collection_model| Hyrax.query_service.find_all_of_model(model: collection_model) do |c| - pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: c.id) original_access_grants_count = pt.access_grants.count From 3401b0b0154a742c8eac7d780601245cb29ff80b Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 26 Jan 2024 19:06:35 -0500 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=8E=81=20Configure=20new=20admin=20se?= =?UTF-8?q?t=20form=20and=20indexer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/hyrax.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index bf20b04a8..382b8b054 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -22,6 +22,11 @@ # (i.e. AdminSet for ActiveFedora, Hyrax::AdministrativeSet for Valkyrie) # config.admin_set_model = 'AdminSet' config.admin_set_model = 'AdminSetResource' + # Identify the form that will be used for Admin Sets + config.administrative_set_form = 'AdminSetResourceForm' + # Identify the indexer that will be used for Admin Sets + config.administrative_set_indexer = 'AdminSetResourceIndexer' + # The email address that messages submitted via the contact page are sent to # This is set by account settings # config.contact_email = 'changeme@example.com' From ea267e7c067e200c3019f8b345fc17f9dded358a Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Thu, 1 Feb 2024 10:54:11 -0500 Subject: [PATCH 6/8] Additional setup for custom resources --- app/forms/{hyrax => }/admin_set_resource_form.rb | 0 app/indexers/collection_resource_indexer.rb | 3 --- app/models/concerns/hyrax/ability/work_ability.rb | 2 +- config/initializers/wings.rb | 6 ++---- 4 files changed, 3 insertions(+), 8 deletions(-) rename app/forms/{hyrax => }/admin_set_resource_form.rb (100%) diff --git a/app/forms/hyrax/admin_set_resource_form.rb b/app/forms/admin_set_resource_form.rb similarity index 100% rename from app/forms/hyrax/admin_set_resource_form.rb rename to app/forms/admin_set_resource_form.rb diff --git a/app/indexers/collection_resource_indexer.rb b/app/indexers/collection_resource_indexer.rb index 4a1bd0b09..9cafa241c 100644 --- a/app/indexers/collection_resource_indexer.rb +++ b/app/indexers/collection_resource_indexer.rb @@ -8,9 +8,6 @@ class CollectionResourceIndexer < Hyrax::Indexers::PcdmCollectionIndexer def to_solr super.tap do |index_document| - # TODO: Do we need the indexing for bulkrax_identifier? If it is in the resource yml, it is probably redundant. - solr_doc['bulkrax_identifier_tesim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) - solr_doc['bulkrax_identifier_sim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier) index_document["account_cname_tesim"] = Site.instance&.account&.cname index_document['account_institution_name_ssim'] = Site.instance.institution_label end diff --git a/app/models/concerns/hyrax/ability/work_ability.rb b/app/models/concerns/hyrax/ability/work_ability.rb index 8c35a4843..f4de232b5 100644 --- a/app/models/concerns/hyrax/ability/work_ability.rb +++ b/app/models/concerns/hyrax/ability/work_ability.rb @@ -32,7 +32,7 @@ def admin_set_with_deposit? return false if ids.empty? - Hyrax.custom_queries.find_ids_by_model(model: Hyrax.config.admin_set_model, ids:).any? + Hyrax.custom_queries.find_ids_by_model(model: Hyrax.config.admin_set_class, ids:).any? end end end diff --git a/config/initializers/wings.rb b/config/initializers/wings.rb index 068805a56..6189d3da0 100644 --- a/config/initializers/wings.rb +++ b/config/initializers/wings.rb @@ -10,9 +10,7 @@ Wings::ModelRegistry.register(klass, klass) end Wings::ModelRegistry.register(Collection, Collection) - Wings::ModelRegistry.register(Hyrax::PcdmCollection, Collection) Wings::ModelRegistry.register(CollectionResource, Collection) - Wings::ModelRegistry.register(Hyrax::AdministrativeSet, AdminSet) Wings::ModelRegistry.register(AdminSet, AdminSet) Wings::ModelRegistry.register(AdminSetResource, AdminSet) @@ -58,11 +56,11 @@ # rubocop:enable Metrics/BlockLength Rails.application.config.to_prepare do - Hyrax::AdministrativeSet.class_eval do + AdminSetResource.class_eval do attribute :internal_resource, Valkyrie::Types::Any.default("AdminSet"), internal: true end - Hyrax::PcdmCollection.class_eval do + CollectionResource.class_eval do attribute :internal_resource, Valkyrie::Types::Any.default("Collection"), internal: true end From 6603d69c554c01027e6970063c19cf9d4393198f Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Thu, 1 Feb 2024 20:42:28 -0500 Subject: [PATCH 7/8] Fix input position on manage users --- app/views/hyrax/admin/users/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/hyrax/admin/users/index.html.erb b/app/views/hyrax/admin/users/index.html.erb index c3c7e44a0..97be3ec03 100644 --- a/app/views/hyrax/admin/users/index.html.erb +++ b/app/views/hyrax/admin/users/index.html.erb @@ -17,8 +17,8 @@
<%# user_invitation_path is provided by devise_invitable %> <%= simple_form_for :user, url: main_app.user_invitation_path, html: { class: 'form-inline d-inline-flex' } do |f| %> + <%= f.hint :email %>
- <%= f.hint :email %> <%= f.label :email, class: "control-label", required: false %> <%= f.input_field :email, class: "form-control", value: "" %> <%= f.select :role, From ac248948b353aa7658cd55e182732f21a93eee10 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Tue, 6 Feb 2024 19:26:21 -0600 Subject: [PATCH 8/8] Modify generated url The catalog controller, when used in the shared tenant, wouldn't return the url to the work in the appropriate tenant without this generated url. With Valkyrie, additional logic is needed to handle resources and legacy models consistently. --- app/helpers/shared_search_helper.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/helpers/shared_search_helper.rb b/app/helpers/shared_search_helper.rb index 7d86b9444..33af4f064 100644 --- a/app/helpers/shared_search_helper.rb +++ b/app/helpers/shared_search_helper.rb @@ -2,22 +2,21 @@ module SharedSearchHelper def generate_work_url(model, request) - # needed because some attributes eg id is a symbol 7 others are string + # handle the various types of info we receive: if model.class == Hyrax::IiifAv::IiifFileSetPresenter - has_model = model.model_name.plural + base_route_name = model.model_name.plural id = model.id account_cname = request.server_name else - model = model.to_h.with_indifferent_access - - cname = model["account_cname_tesim"] - account_cname = Array.wrap(cname).first - - has_model = model["has_model_ssim"].first.underscore.pluralize - id = model["id"] + model_hash = model.to_h.with_indifferent_access + + base_route_name = model_hash["has_model_ssim"].first.constantize.model_name.plural + id = model_hash["id"] + account_cname = Array.wrap(model_hash["account_cname_tesim"]).first end + request_params = %i[protocol host port].map { |method| ["request_#{method}".to_sym, request.send(method)] }.to_h - url = get_url(id:, request: request_params, account_cname:, has_model:) + url = get_url(id:, request: request_params, account_cname:, base_route_name:) # pass search query params to work show page params[:q].present? ? "#{url}?q=#{params[:q]}" : url @@ -25,14 +24,14 @@ def generate_work_url(model, request) private - def get_url(id:, request:, account_cname:, has_model:) + def get_url(id:, request:, account_cname:, base_route_name:) new_url = "#{request[:request_protocol]}#{account_cname || request[:request_host]}" new_url += ":#{request[:request_port]}" if Rails.env.development? || Rails.env.test? - new_url += case has_model + new_url += case base_route_name when "collections" - "/#{has_model}/#{id}" + "/#{base_route_name}/#{id}" else - "/concern/#{has_model}/#{id}" + "/concern/#{base_route_name}/#{id}" end new_url end