Skip to content

Commit

Permalink
Modify Collection & Admin Set Valkyrization
Browse files Browse the repository at this point in the history
Addresses:

☄️ EPIC: Valkyrize Hyku scientist-softserv/hykuup_knapsack#35
valkyrize collection and admin set resources scientist-softserv/hykuup_knapsack#94

Moves away from directly using Hyrax::PcdmCollection and
Hyrax::AdministrativeSet instead favoring inheriting from those
(with CollectionResource and AdminSetResource). This allows for
inheriting from Hyrax factories and extending them; thus bringing
Hyku’s testing ecosystem closer to Hyrax.

Note: There are a few of the new specs that still fail.
-
  • Loading branch information
laritakr committed Feb 16, 2024
1 parent c106563 commit fc4118a
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 155 deletions.
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.

22 changes: 0 additions & 22 deletions app/forms/hyrax/forms/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
end
15 changes: 15 additions & 0 deletions app/models/collection_resource.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 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.
# @see https://samvera.slack.com/archives/C0F9JQJDQ/p1705421588370699 Slack discussion thread.
include Hyrax::Permissions::Readable
prepend OrderAlready.for(:creator)
end
14 changes: 0 additions & 14 deletions app/models/hyrax/pcdm_collection_decorator.rb

This file was deleted.

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
Hyrax.query_service.find_all_of_model(model: Hyrax.config.admin_set_class).each do |admin_set|
permission_template = Hyrax::PermissionTemplate.find_or_create_by!(source_id: admin_set.id)
Hyrax::Workflow::PermissionGrantor.grant_default_workflow_roles!(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
Hyrax.query_service.find_all_of_model(model: Hyrax.config.collection_class).each do |collection|
pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: collection.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:) 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
Hyrax.query_service.find_all_of_model(model: Hyrax.config.admin_set_class).each do |admin_set|
pt = Hyrax::PermissionTemplate.find_or_create_by!(source_id: admin_set.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: admin_set) 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
6 changes: 4 additions & 2 deletions config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
# 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'

# 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'
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(CollectionResource, Collection)
Wings::ModelRegistry.register(AdminSet, AdminSet)
Wings::ModelRegistry.register(Hyrax::AdministrativeSet, AdminSet)
Wings::ModelRegistry.register(AdminSetResource, AdminSet)
Wings::ModelRegistry.register(FileSet, FileSet)
Wings::ModelRegistry.register(Hyrax::FileSet, FileSet)

Expand Down Expand Up @@ -64,11 +64,11 @@
end

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 @@ -85,9 +85,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

0 comments on commit fc4118a

Please sign in to comment.