-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add user roles #349
Add user roles #349
Commits on Sep 19, 2022
-
Rolify lets us add “global” and resource-specific roles to our User model. Issue #299
Configuration menu - View commit details
-
Copy full SHA for 8b5fa0d - Browse repository at this point
Copy the full SHA 8b5fa0dView commit details -
This commit begins the process of adding roles to the User model by: - Generating the role boilerplate and migrations - Configuring Rolify (specifically, enabling dynamic shortcuts so we can do queries like `user.is_admin?` or `user.is_insights_user?`) - Adding Role fixtures It also moves the Devise stuff in the User model up next to Rolify, with the idea that this sort of model-inheritance stuff should come before the model-definition stuff. Issue #299
Configuration menu - View commit details
-
Copy full SHA for 9acb2dd - Browse repository at this point
Copy the full SHA 9acb2ddView commit details -
Use role instead of attribute to define admins
This is a consequential commit. Previously, we were defining admins by the presence of a `super_admin` attribute on the `User` model. Now, we’re using Rolify with an `admin` role. Consequently, this commit: - Adds a (reversible) migration which finds all users with the `super_admin` attribute and adds the `:admin` role to them - Updates the seeds file to create the admin user - Removes the `User#super_admin?` method and converts all use of it to the `User#is_admin?` dynamic method created by Rolify - Updates the `User` fixtures and tests - Updates the `ARCHITECTURE.md` user model documentation Issue #299
Configuration menu - View commit details
-
Copy full SHA for 60cec4d - Browse repository at this point
Copy the full SHA 60cec4dView commit details
Commits on Sep 20, 2022
-
Assign default roles to new users
This commit adds the `new_user` and `insights_user` roles to users that we create from applicants. It doesn’t do this to all new users using an `after_create` callback on the `User` model, as suggested by the Rolify docs, because we want more control over when we assign these roles. Issue #299
Configuration menu - View commit details
-
Copy full SHA for df97cee - Browse repository at this point
Copy the full SHA df97ceeView commit details -
Remove
new_user
role during account creationThe `new_user` role distinguishes users who haven’t been through setup yet from those who have. This commit removes that role during account creation. Issue #299
Configuration menu - View commit details
-
Copy full SHA for 27df82f - Browse repository at this point
Copy the full SHA 27df82fView commit details -
Configuration menu - View commit details
-
Copy full SHA for baf8952 - Browse repository at this point
Copy the full SHA baf8952View commit details -
Use
new_user
role for "already-setup checkPrior to the existence of our roles and the `new_user` role, we were using `user.sign_in_count` as a proxy for whether a user was already setup, and thus whether we could send them setup instructions. Now, we use the existence of the `new_user` role instead, as it’s more explicitly intended for this. Issue #299
Configuration menu - View commit details
-
Copy full SHA for df4b8d4 - Browse repository at this point
Copy the full SHA df4b8d4View commit details -
Clean up users fixtures and update tests
Now that we have roles, we can target users more specifically for specific tests. We also don’t need some of the duplicate test fixtures. Issue #299
Configuration menu - View commit details
-
Copy full SHA for f9a9cfd - Browse repository at this point
Copy the full SHA f9a9cfdView commit details -
Add Rubocop exclusions for Rolify stuff
Since adding Rolify, we are triggering two significant Rubocop offenses: - `has_and_belongs_to_many` is frowned upon in favor of `has_many :through`, but Rolify still uses the former. There have been many attempts to resolve this (see the Rolify issues and PRs) over the past decade, but none have fully landed. It’s beyond us to try and wrestle this into existence, so we’re going to make an exception and move on. - The HABTM join table has no timestamps, which is also frowned upon. We genuinely don’t care, however, and so are making an exception. Issue #299
Configuration menu - View commit details
-
Copy full SHA for d3a4f3e - Browse repository at this point
Copy the full SHA d3a4f3eView commit details -
Seed database with Rolify roles and tweak config
This commit addresses some excellent @cguess feedback in PR #349: - Disable the Rolify `config.remove_role_if_empty`, which would purge unused roles automatically once the last resource used them. We don’t want this until we know that we do. - Seeds the database with the actual known/defined roles. - Updates the documentation about our architecture with the roles. Issue #299
Configuration menu - View commit details
-
Copy full SHA for d27e0a8 - Browse repository at this point
Copy the full SHA d27e0a8View commit details