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

override can_create_any_work? to stop causing overlong solr queries #474

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,28 @@ def can_import_works?
def can_export_works?
can_create_any_work?
end

# Overrides hyarx 2.9.6 to call a version of admin_set_with_deposit? that limits
# the id string used in the solr query to 200 ids (see admin_set_with_deposit_limited?
def can_create_any_work?
Hyrax.config.curation_concerns.any? do |curation_concern_type|
can?(:create, curation_concern_type)
end && admin_set_with_deposit_limited?
end

# If the ids string is too long then solr will bail so (until we are on hyrax3.x)
# introduce an _entirely_ abitrary limit to the number of ids used in query
# admin_Sets with depositos _should_ appear in the first 200 collections, but there
# is a risk that this fix will mis-report whether a user can create a work in an admin set
# The mis-report will be a false negative so will not admit users to any admin_sets
# they shouldn't have access to, but may in extreme circumstances lock some out.
# TODO upgrade hyrax used by hyku to version 3.x
def admin_set_with_deposit_limited?
ids = Hyrax::PermissionTemplateAccess.for_user(ability: self,
access: ['deposit', 'manage'])
.joins(:permission_template)
.pluck(Arel.sql('DISTINCT source_id'))
query = "_query_:\"{!raw f=has_model_ssim}AdminSet\" AND {!terms f=id}#{ids.take(200).join(',')}"
ActiveFedora::SolrService.count(query).positive?
end
end
Loading