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
5 changes: 5 additions & 0 deletions app/forms/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
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
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.

27 changes: 13 additions & 14 deletions app/helpers/shared_search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@

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
end

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
Expand Down
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
15 changes: 15 additions & 0 deletions app/indexers/collection_resource_indexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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|
index_document["account_cname_tesim"] = Site.instance&.account&.cname
index_document['account_institution_name_ssim'] = Site.instance.institution_label
end
end
end
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_class, 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
2 changes: 1 addition & 1 deletion app/views/hyrax/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<div class="card-body">
<%# 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 %>
<div class="form-group">
<%= f.hint :email %>
<%= f.label :email, class: "control-label", required: false %>
<%= f.input_field :email, class: "form-control", value: "" %>
<%= f.select :role,
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
12 changes: 6 additions & 6 deletions config/initializers/wings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
Wings::ModelRegistry.register(klass, klass)
end
Wings::ModelRegistry.register(Collection, Collection)
Wings::ModelRegistry.register(Hyrax::PcdmCollection, Collection)
Wings::ModelRegistry.register(Hyrax::AdministrativeSet, AdminSet)
Wings::ModelRegistry.register(CollectionResource, Collection)
Wings::ModelRegistry.register(AdminSet, AdminSet)
Wings::ModelRegistry.register(AdminSetResource, AdminSet)

Valkyrie::MetadataAdapter.register(
Freyja::MetadataAdapter.new,
Expand Down Expand Up @@ -63,11 +63,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

Expand All @@ -84,9 +84,9 @@
].include?(klass_name)
"#{klass_name}Resource".constantize
elsif 'Collection' == klass_name
Hyrax::PcdmCollection
CollectionResource
elsif 'AdminSet' == klass_name
Hyrax::AdministrativeSet
AdminSetResource
# Without this mapping, we'll see cases of Postgres Valkyrie adapter attempting to write to
# Fedora. Yeah!
elsif 'Hydra::AccessControl' == klass_name
Expand Down
Loading
Loading