Skip to content

Commit

Permalink
Merge pull request #6712 from samvera/treat-valkyrie-id-and-string-sa…
Browse files Browse the repository at this point in the history
…me-for-permissions

🐛 Account for String and Valkyrie::ID Permissions
  • Loading branch information
dlpierce authored Feb 21, 2024
2 parents d8e5025 + 2cde6c1 commit a48c602
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 7 additions & 7 deletions app/models/concerns/hyrax/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def admin?
#
# Overrides hydra-head, (and restores the method from blacklight-access-controls)
def download_permissions
can :download, String do |id|
test_download(id)
can :download, [::String, ::Valkyrie::ID] do |id|
test_download(id.to_s)
end

can :download, ::SolrDocument do |obj|
Expand Down Expand Up @@ -189,8 +189,8 @@ def uploaded_file_abilities
# self.ability_logic += [:proxy_deposit_abilities]
def proxy_deposit_abilities
if Flipflop.transfer_works?
can :transfer, String do |id|
user_is_depositor?(id)
can :transfer, [::String, Valkyrie::ID] do |id|
user_is_depositor?(id.to_s)
end
end

Expand Down Expand Up @@ -368,7 +368,7 @@ def admin_permissions
alias_action :show, to: :read
alias_action :discover, to: :read
can :update, :appearance
can :manage, String # The identifier of a work or FileSet
can :manage, [String, Valkyrie::ID] # The identifier of a work or FileSet
can :manage, curation_concerns_models
can :manage, Sipity::WorkflowResponsibility
can :manage, :collection_types
Expand Down Expand Up @@ -414,9 +414,9 @@ def registered_user?
end

# Returns true if the current user is the depositor of the specified work
# @param document_id [String] the id of the document.
# @param document_id [String, Valkyrie::ID] the id of the document.
def user_is_depositor?(document_id)
doc = Hyrax::SolrService.search_by_id(document_id, fl: 'depositor_ssim')
doc = Hyrax::SolrService.search_by_id(document_id.to_s, fl: 'depositor_ssim')
current_user.user_key == doc['depositor_ssim']&.first
end

Expand Down
9 changes: 7 additions & 2 deletions app/models/concerns/hyrax/ability/collection_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ def collection_abilities # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
can :deposit, ::SolrDocument do |solr_doc|
Hyrax::Collections::PermissionsService.can_deposit_in_collection?(ability: self, collection_id: solr_doc.id) # checks collections and admin_sets
end
can :deposit, String do |collection_id|
Hyrax::Collections::PermissionsService.can_deposit_in_collection?(ability: self, collection_id: collection_id)

can :deposit, [::String, ::Valkyrie::ID] do |collection_id|
Hyrax::Collections::PermissionsService.can_deposit_in_collection?(ability: self, collection_id: collection_id.to_s)
end

can :view_admin_show, ::SolrDocument do |solr_doc| # admin show page
Hyrax::Collections::PermissionsService.can_view_admin_show_for_collection?(ability: self, collection_id: solr_doc.id) # checks collections and admin_sets
end

can :view_admin_show, [::String, ::Valkyrie::ID] do |collection_id| # admin show page
Hyrax::Collections::PermissionsService.can_view_admin_show_for_collection?(ability: self, collection_id: collection_id.to_s) # checks collections and admin_sets
end
end
end
end
Expand Down

0 comments on commit a48c602

Please sign in to comment.