This application now has a comprehensive roles-based authorization system with three levels of access: Viewer, Contributor, and Admin.
- Permissions: Can only view content
- Default Role: All new users are created as viewers
- Access: Read-only access to notes, Bible verses, comments, and cross-references
- Permissions: Can create, read, edit, and delete their own content
- Access:
- Create new notes
- Edit/delete their own notes
- Add comments on any content
- Edit/delete their own comments
- Add cross-references
- Edit/delete their own cross-references
- Permissions: Full access to all content and user management
- Access:
- All Contributor permissions
- Edit/delete ANY user's content
- Access to Admin Dashboard
- Manage user roles (promote/demote users)
- Delete users
- URL:
/admin/users - Only accessible to users with Admin role
- Link appears in navigation bar for admins
-
User Statistics
- View counts of Viewers, Contributors, and Admins
- Quick filter links to view users by role
-
User Management Table
- View all users with email, name, role, and creation date
- Edit user roles
- Delete spam users
- Current user is highlighted
-
Role Management
- Change any user's role between Viewer, Contributor, and Admin
- Visual role badges with color coding:
- Viewer: Blue
- Contributor: Green
- Admin: Purple
app/models/user.rb- Includes role enum with three values
- Authorization methods:
can_view?(resource)- Always true for all userscan_create?- True for Contributors and Adminscan_edit?(resource)- True for resource owner (Contributors) or Adminscan_delete?(resource)- Same as can_edit?can_manage_users?- True only for Admins
app/controllers/concerns/authorizable.rb- Provides controller methods:
authorize_create!authorize_edit!(resource)authorize_delete!(resource)authorize_admin!
- Handles unauthorized access with flash messages and redirects
NotesControllerCommentsControllerCrossReferencesControllerAdmin::UsersController
All creation, edit, and delete buttons are conditionally shown based on user permissions:
- Notes index (new note button)
- Note show (edit/delete buttons)
- Comments (edit/delete links)
- Bible verses (add comment/cross-reference buttons)
- Role badge displayed next to user email in navbar
- Admin link only visible to admins
- Color-coded role indicators throughout the app
rolecolumn (string) stores: 'viewer', 'contributor', or 'admin'- Default value set to 'viewer' on user creation
- Added
user_idcolumn to track who created each cross-reference - Enables contributors to only edit/delete their own cross-references
To promote existing users to different roles, use the Admin Dashboard or Rails console:
# In Rails console
user = User.find_by(email: 'user@example.com')
user.update(role: 'admin')
# or
user.update(role: 'contributor')- All authorization is enforced both in views (UI) and controllers (backend)
- Viewers attempting to access restricted actions receive appropriate error messages
- Admin dashboard is protected by
authorize_admin!callback - Users cannot delete themselves from the admin dashboard
- All role changes are logged in the application
Consider adding:
- Activity logging for role changes
- Email notifications when users are promoted
- Bulk role management
- Team/group management
- Custom permission sets beyond the three basic roles