-
Notifications
You must be signed in to change notification settings - Fork 48
Groups with Roles Feature
Jill Peterson edited this page Jan 11, 2023
·
19 revisions
- Creating Default Roles and Groups
- Setup an Existing Application to use Groups with Roles
- Role Set Creation Guidelines
- Search Permissions Notes
Default Roles
and Hyrax::Groups
are seeded into an account (tenant) at creation time (see CreateAccount#create_defaults).
To manually seed default Roles
and Hyrax::Groups
across all tenants, run this rake task:
rake hyku:roles:create_default_roles_and_groups
These rake tasks will create data across all tenants necessary to setup Groups with Roles. Run them in the order listed below.
Prerequisites:
- All Collections must have CollectionTypes and PermissionTemplates (see the Collection Migration section in the Hyrax 2.1 Release Notes)
rake hyku:roles:create_default_roles_and_groups
rake hyku:roles:create_collection_accesses
rake hyku:roles:create_admin_set_accesses
rake hyku:roles:create_collection_type_participants
rake hyku:roles:add_admin_users_to_admin_group
rake hyku:roles:grant_workflow_roles
rake hyku:roles:destroy_registered_group_collection_type_participants # optional
* The hyku:roles:destroy_registered_group_collection_type_participants
task is technically optional. However, without it, collection readers will be allowed to create Collections.
- Add role names to the RolesService::DEFAULT_ROLES constant
- Find related ability concern in Hyrax (if applicable)
- Look in
app/models/concerns/hyrax/ability/
(local repo first, then Hyrax's repo) - E.g. ability concern for Collections is
app/models/concerns/hyrax/ability/collection_ability.rb
- If a concern matching the record type exists in Hyrax, but no the local repo, copy the file into the local repo
- Be sure to add override comments (use the
OVERRIDE:
prefix)
- Be sure to add override comments (use the
- If no concern matching the record type exists, create one.
- E.g. if creating an ablility concern for the
User
model, createapp/models/concerns/hyrax/ability/user_ability.rb
- E.g. if creating an ablility concern for the
- Create a method in the concern called
<record_type>_roles
(e.g.collection_roles
) - Add the method to the array of method names in Ability#ability_logic
- Within the
<record_type>_roles
method in the ability concern, add CanCanCan rules for each role, following that role's specific criteria.
- When adding/removing permissions, get as granular as possible.
- Beware using
can :manage
-- in CanCanCan,:manage
refers to any permission, not just CRUD actions.- E.g. If you want a role to be able to create, read, edit, update, but not destroy Users
# Bad - could grant unwanted permissions can :manage, User cannot :destroy, User # Good can :create, User can :read, User can :edit, User can :update, User
- CanCanCan rules are hierarchical:
# Will still grant read permission cannot :manage, User # remove all permissions related to users can :read, User
- Add new / change existing
#can?
ability checks in views and controllers where applicable
- For guidelines on overriding dependencies, see the Overrides to Dependencies section of the README
- Add ability specs and feature specs
- Permissions are injected in the solr query's
fq
("filter query") param (link to code) - Enforced (injected into solr query) in Blacklight::AccessControls::Enforcement
- Represented by an instance of
Blacklight::AccessControls::PermissionsQuery
(see #permissions_doc) - Admin users don't have permission filters injected when searching (link to code)
-
SearchBuilder
may be related to when permissions are and aren't enforced - Related discussions in Slack: