Skip to content
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

Modify Collection & Admin Set Valkyrization #2157

Closed
wants to merge 12 commits into from
9 changes: 9 additions & 0 deletions app/forms/collection_resource_form.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/forms/hyrax/admin_set_resource_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class AdminSetResourceForm < Hyrax::Forms::AdministrativeSetForm
include CollectionAccessFiltering
end
11 changes: 0 additions & 11 deletions app/forms/hyrax/forms/admin/administrative_set_form_decorator.rb

This file was deleted.

6 changes: 0 additions & 6 deletions app/forms/hyrax/forms/pcdm_collection_form_decorator.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/indexers/admin_set_resource_indexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class AdminSetResourceIndexer < Hyrax::Indexers::AdministrativeSetIndexer
end
1 change: 1 addition & 0 deletions app/indexers/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions app/indexers/collection_resource_indexer.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/indexers/concerns/hyku_indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 5 additions & 3 deletions app/models/concerns/hyrax/ability/collection_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/ability/work_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
131 changes: 70 additions & 61 deletions app/services/roles_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,45 +233,51 @@ 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

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
Expand All @@ -280,35 +286,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
# 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)
# config.admin_set_model = 'AdminSet'
config.admin_set_model = 'Hyrax::AdministrativeSet'
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 = '[email protected]'
Expand Down
6 changes: 4 additions & 2 deletions config/initializers/wings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions config/metadata/collection_resource.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
13 changes: 13 additions & 0 deletions spec/forms/collection_resource_form_spec.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions spec/indexers/collection_resource_indexer_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading