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

Wrap stringy sql in Arel.sql for pluck calls #4818

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def admin_set_with_deposit?
ids = PermissionTemplateAccess.for_user(ability: self,
access: ['deposit', 'manage'])
.joins(:permission_template)
.pluck('DISTINCT source_id')
.pluck(Arel.sql('DISTINCT source_id'))
query = "_query_:\"{!raw f=has_model_ssim}AdminSet\" AND {!terms f=id}#{ids.join(',')}"
ActiveFedora::SolrService.count(query).positive?
end
Expand Down
6 changes: 3 additions & 3 deletions app/services/hyrax/collection_types/permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class PermissionsService
# If calling from Abilities, pass the ability. If you try to get the ability from the user, you end up in an infinit loop.
def self.collection_type_ids_for_user(roles:, user: nil, ability: nil)
return false unless user.present? || ability.present?
return Hyrax::CollectionType.all.pluck('DISTINCT id') if user_admin?(user, ability)
return Hyrax::CollectionType.all.pluck(Arel.sql('DISTINCT id')) if user_admin?(user, ability)
Hyrax::CollectionTypeParticipant.where(agent_type: Hyrax::CollectionTypeParticipant::USER_TYPE,
agent_id: user_id(user, ability),
access: roles)
.or(
Hyrax::CollectionTypeParticipant.where(agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE,
agent_id: user_groups(user, ability),
access: roles)
).pluck('DISTINCT hyrax_collection_type_id')
).pluck(Arel.sql('DISTINCT hyrax_collection_type_id'))
end

# @api public
Expand Down Expand Up @@ -174,7 +174,7 @@ def self.access_to_collection_type?(collection_type:, access:, user: nil, abilit
def self.agent_ids_for(collection_type:, agent_type:, access:)
Hyrax::CollectionTypeParticipant.where(hyrax_collection_type_id: collection_type.id,
agent_type: agent_type,
access: access).pluck('DISTINCT agent_id')
access: access).pluck(Arel.sql('DISTINCT agent_id'))
end
private_class_method :agent_ids_for

Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/collections/permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PermissionsService
def self.source_ids_for_user(access:, ability:, source_type: nil, exclude_groups: [])
scope = PermissionTemplateAccess.for_user(ability: ability, access: access, exclude_groups: exclude_groups)
.joins(:permission_template)
ids = scope.pluck('DISTINCT source_id')
ids = scope.pluck(Arel.sql('DISTINCT source_id'))
return ids unless source_type
filter_source(source_type: source_type, ids: ids)
end
Expand Down