Overview
Location:services/permissions.py
This module provides:
- Role-based permission checking across all resources
- Temporary privilege elevation for assistants
- Master code verification for sensitive operations
- Centralized RBAC policy matrix
- Permission enforcement helpers
Core Concepts
Roles
The system supports three user roles:- admin: Full access to all features and settings
- assistant: Limited access, can elevate privileges with master code
- artist: Access to own appointments, portfolio, and client interactions
Policy Values
allow
Full permission granted for this role
own
Permission granted only for owned resources (artist role)
locked
Requires master code elevation (assistant only)
deny
Permission explicitly denied
Resources
Protected resources include:agenda- Appointment schedulingclients- Client data managementstaff- User and staff managementportfolio- Artist portfolio itemsreports- Financial reports and transactionsinventory- Stock and inventory managementsecurity- System settings and backups
RBAC Matrix
The complete permission matrix is defined in theRBAC dictionary at services/permissions.py:38-87.
View example permissions
View example permissions
Functions
can
Checks if a role has permission to perform an action on a resource.User role: “admin”, “assistant”, or “artist”
Resource name (e.g., “agenda”, “clients”, “inventory”)
Action to perform (e.g., “view”, “create”, “edit”, “delete”)
Resource owner’s artist_id (for “own” policy checks)
Current user’s artist_id (for “own” policy checks)
Current user’s ID (for elevation status checks)
bool - True if permission is granted, False otherwise
assistant_needs_code
Determines if a specific action requires master code elevation for assistants.Resource name
Action to check
bool - True if the action has “locked” policy for assistants
is_elevated_now
Checks if a user currently has elevated privileges.User ID to check
bool - True if the user has active elevation
elevate_for
Grants temporary elevated privileges to a user.User ID to elevate
Duration of elevation in minutes
None
verify_master_code
Verifies a master code against the stored hash in the database.Plain text master code to verify
SQLAlchemy database session
bool - True if the code matches, False otherwise
The master code hash is stored in the
settings table with key "MASTER_CODE_HASH". Use the same bcrypt functions from the auth service to set it.enforce
Raises aPermissionError if the current user lacks permission. Used for defense-in-depth within service functions.
Resource being accessed
Action being performed
Resource owner’s ID for ownership checks
Database session (for future use)
None - Raises PermissionError if not allowed
clear_elevation
Removes elevation status for a specific user.User ID to clear elevation for
None
Call this function when a user logs out to ensure their elevation doesn’t persist.
Typical Workflow
User attempts restricted action
An assistant tries to edit client information, which is a “locked” action.
System checks permission
Call
can() to verify if the action is allowed. Returns False for locked actions without elevation.Verify and elevate
Call
verify_master_code() with the input. If valid, call elevate_for() to grant temporary privileges.Perform action
The assistant can now perform locked actions for the duration of the elevation period.
Permission Examples
Agenda permissions
Agenda permissions
- View: All roles can view the agenda
- Create/Edit: Admin and assistant can manage any appointment; artists can only manage their own
- Export: Admin and assistant can export; artists can export only their own data
Client permissions
Client permissions
- View/Create: All roles allowed
- Edit/Delete: Admin always allowed; assistant needs master code; artist denied
- Export: Admin always allowed; assistant needs master code; artist denied
Staff permissions
Staff permissions
- View: All roles can view staff list
- Manage users: Admin only
- Portfolio: All can view; artists can edit only their own
Security permissions
Security permissions
- All actions: Admin only (settings, audit logs, backups, code rotation)
Related
Authentication Service
User authentication and password management
User Roles
Detailed role descriptions and capabilities