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

User permission #21

Open
1 task
jillpe opened this issue Dec 20, 2023 · 7 comments
Open
1 task

User permission #21

jillpe opened this issue Dec 20, 2023 · 7 comments
Assignees
Labels
maintenance bills to maintenance

Comments

@jillpe
Copy link

jillpe commented Dec 20, 2023

Summary

The following user ends up with permissions to add to all collections and should not have that.

Image

Accepted Criteria

  • The user above only has permission to add to the following collections
@bkiahstroud bkiahstroud self-assigned this Jan 2, 2024
@bkiahstroud
Copy link

The user above only has permission to add to the following collections

@jillpe the language above implies there should be a list of approved collections the user can add to. Do we have that list anywhere?

@jillpe
Copy link
Author

jillpe commented Feb 2, 2024

No, but I will get clarification (I'm pretty sure it's just the collection they created)

@bkiahstroud bkiahstroud added the maintenance bills to maintenance label Feb 7, 2024
@bkiahstroud
Copy link

bkiahstroud commented Jul 31, 2024

Notes

  1. [email protected] is a member of the managers-pomona group
Screenshot

Edit Role ScholarWorks 2024-07-31 at 9 50 09 AM


  1. Two Hyrax::CollectionTypeParticpant records exist for [email protected]. The existence of these records are what grant this user :create and :manage access to all newly created User Collections
pp Hyrax::CollectionTypeParticipant.where(agent_id: "[email protected]")
[#<Hyrax::CollectionTypeParticipant:0x000055c96d7a37d0
  id: 8,
  hyrax_collection_type_id: 2,
  agent_type: "user",
  agent_id: "[email protected]",
  access: "manage",
  created_at: Wed, 14 Jul 2021 16:17:20 UTC +00:00,
  updated_at: Wed, 14 Jul 2021 16:17:20 UTC +00:00>,
 #<Hyrax::CollectionTypeParticipant:0x000055c96d7a35a0
  id: 9,
  hyrax_collection_type_id: 2,
  agent_type: "user",
  agent_id: "[email protected]",
  access: "create",
  created_at: Wed, 14 Jul 2021 16:17:38 UTC +00:00,
  updated_at: Wed, 14 Jul 2021 16:17:38 UTC +00:00>]

  1. Stats
  • Number of Collections user has access to: 1,340
Hyrax::PermissionTemplateAccess.where(agent_id: "[email protected]")
  • Number of Collections user has created: 224
Collection.where(depositor: '[email protected]')
  • Number of Collections user has access to that they did not create: 1,116 (1,340 - 224)

Proposed Solution

  • Delete the 2 Hyrax::CollectionTypeParticipant records
Implementation
ctp = Hyrax::CollectionTypeParticipant.where(agent_id: '[email protected]')
ctp.count == 2 ? ctp.map(&:destroy) : puts 'deleting unexpected records'
  • Revoke [email protected]'s access from all collections they have individual access to that they did not create1
Implementation
resp = ActiveFedora::SolrService.get(
  'has_model_ssim:Collection',
  fq: 'depositor_ssim:[email protected]',
  fl: 'id',
  rows: 1_000
)
good_ids = resp.dig('response', 'docs').pluck('id')
total_access_count = Hyrax::PermissionTemplateAccess.where(agent_id: "[email protected]").count
superfluous_accesses = Hyrax::PermissionTemplateAccess
                         .joins(:permission_template)
                         .where(agent_id: "[email protected]")
                         .where
                         .not(permission_templates: { source_id: good_ids })
bad_permission_templates = superfluous_accesses.map(&:permission_template);nil

if (total_access_count - good_ids.size) == superfluous_accesses.count
  superfluous_accesses.destroy_all
else
  puts "error: counts don't match"
end

bad_permission_templates.each do |permission_template|
  begin
    collection = permission_template.collection
    permission_template.reset_access_controls_for(collection: collection)
  rescue Hyrax::ObjectNotFoundError => e
    puts "PermissionTemplate #{permission_template.id} is for an AdminSet. No need to call #reset_access_controls_for. Skipping..."
    next
  end
end

1 Note that they are in the managers-pomona group, so they should still retain access to all collections that group has been granted access to

@bkiahstroud
Copy link

On hold pending approval from the client to move forward with the Proposed Solution (see previous comment)

@dswalker
Copy link

dswalker commented Aug 6, 2024

This sounds good to me, Kiah. I approve.

@bkiahstroud
Copy link

The user in question should no longer have access to collections they did not create, nor should they be granted access to every newly created collection moving forward

@aprilrieger
Copy link

@dswalker will review and test and provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance bills to maintenance
Projects
None yet
Development

No branches or pull requests

4 participants