Skip to content

Commit d27e0a8

Browse files
committed
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
1 parent d3a4f3e commit d27e0a8

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

config/initializers/rolify.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
# config.use_mongoid
44

55
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
6+
#
7+
# Enabled because these are convenient methods, and according to the Rolify documentation they
8+
# are generated at boot time (and when `add_role` is run), so shouldn't hurt performance.
69
config.use_dynamic_shortcuts
710

811
# Configuration to remove roles from database once the last resource is removed. Default is: true
9-
# config.remove_role_if_empty = false
12+
#
13+
# Toggled to false because we have well-defined user roles that we don't want removed, even if
14+
# the last user using them is deleted.
15+
config.remove_role_if_empty = false
1016
end

db/seeds.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
99
# Character.create(name: 'Luke', movie: movies.first)
1010

11+
Role.create!([
12+
{ name: "new_user" },
13+
{ name: "insights_user" },
14+
{ name: "media_vault_user" },
15+
{ name: "admin" },
16+
])
17+
1118
easy_password = "password123"
1219

1320
# Super-admin account; no applicant necessary.

docs/ARCHITECTURE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ Zenodotus allows its users to search its archive using image or text inputs. Sea
2121

2222
## User model
2323

24-
Zenodotus' `User` model handles authentication for the app via [Devise](https://github.com/heartcombo/devise). Roles are managed with the Rolify gem. Internal users have the `:admin` role and are recognized with the `is_admin?` helper (provided by Rolify automatically).
24+
Zenodotus' `User` model handles authentication for the app via [Devise](https://github.com/heartcombo/devise). Roles are managed with the Rolify gem, which also generates role-specific helpers (e.g., `is_admin?`) at boot time.
25+
26+
Roles:
27+
28+
- `new_user`: Indicates a user was newly-created and has not yet gone through the setup process (clicked the link in their welcome email and chosen their own password). Applied to every new user created from an applicant, and removed when they have completed their own setup process.
29+
- `insights_user`: Indicates a user has access to Fact-Check Insights. Applied to every new user created from an applicant.
30+
- `media_vault_user`: Indicates a user has access to MediaVault. Currently only applied manually.
31+
- `admin`: Indicates a user is authorized to administrate the site. (I.e., an internal user.)
2532

2633
## MediaReview
2734
Coming soon

0 commit comments

Comments
 (0)