scientist-softserv / scholarworks

Cal State Hyrax
0 stars 0 forks source link

User permission #21

Open jillpe opened 10 months ago

jillpe commented 10 months ago

Summary

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

Image

Accepted Criteria

bkiahstroud commented 8 months ago

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 commented 8 months ago

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

bkiahstroud commented 2 months ago

Notes

  1. 004268589@cpp.edu is a member of the managers-pomona group
Screenshot ![Edit Role ScholarWorks 2024-07-31 at 9 50 09 AM](https://github.com/user-attachments/assets/54d05776-4824-478d-913a-751dd32599da)

  1. Two Hyrax::CollectionTypeParticpant records exist for 004268589@cpp.edu. The existence of these records are what grant this user :create and :manage access to all newly created User Collections
```ruby pp Hyrax::CollectionTypeParticipant.where(agent_id: "004268589@cpp.edu") [#, #] ```

  1. Stats
Hyrax::PermissionTemplateAccess.where(agent_id: "004268589@cpp.edu")
Collection.where(depositor: '004268589@cpp.edu')

Proposed Solution

Implementation ```ruby ctp = Hyrax::CollectionTypeParticipant.where(agent_id: '004268589@cpp.edu') ctp.count == 2 ? ctp.map(&:destroy) : puts 'deleting unexpected records' ```
Implementation ```ruby resp = ActiveFedora::SolrService.get( 'has_model_ssim:Collection', fq: 'depositor_ssim:004268589@cpp.edu', fl: 'id', rows: 1_000 ) good_ids = resp.dig('response', 'docs').pluck('id') total_access_count = Hyrax::PermissionTemplateAccess.where(agent_id: "004268589@cpp.edu").count superfluous_accesses = Hyrax::PermissionTemplateAccess .joins(:permission_template) .where(agent_id: "004268589@cpp.edu") .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 commented 2 months ago

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

dswalker commented 2 months ago

This sounds good to me, Kiah. I approve.

bkiahstroud commented 2 months ago

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 commented 1 month ago

@dswalker will review and test and provide feedback.