User management
This page explains how users, authentication, and permissions work across the platform.
User types
Django users
All users have a base Django user account with: - Username and email - Password authentication - Basic profile information - Staff/superuser flags
Extended profiles
Users may have additional profile data depending on their role:
| Profile | Purpose | Link |
|---|---|---|
| MunicipalityUser | Municipal staff | One-to-one with User |
Anonymous users
Some platform features are accessible without authentication: - Public occurrence submission - Public occupancy dashboards - Read-only API endpoints (if configured)
Authentication methods
Username/password
Standard Django authentication: - Login via Django Admin or API - Password reset via email - Session-based authentication
API authentication
For programmatic access: - Token authentication (DRF) - JWT tokens (if configured) - API keys for service accounts
Social authentication
If configured (django-allauth): - OAuth providers (Google, Microsoft, etc.) - SAML for enterprise SSO
Role hierarchy
Platform roles
| Role | Scope | Capabilities |
|---|---|---|
| Superuser | Platform-wide | All operations, all municipalities |
| Platform Admin | Platform-wide | Module configuration, user management |
Municipality roles
| Role | Scope | Capabilities |
|---|---|---|
| Municipality Admin | Single municipality | Full control within municipality |
| Manager | Single municipality | Configure workflows, manage staff |
| Operator | Single municipality | Work on records, day-to-day operations |
| Viewer | Single municipality | Read-only access |
Role assignment
- Create Django user account
- Set staff flag if needed for admin access
- Create MunicipalityUser profile with role
- Assign to department (optional)
- Set category restrictions (optional)
Permissions system
Module-level permissions
Controlled via MODULE_PERMISSIONS in settings:
MODULE_PERMISSIONS = {
'occurrences': {
'view': ['public', 'staff', 'manager', 'admin'],
'create': ['public', 'staff', 'admin'],
...
},
}
Object-level permissions
Fine-grained control via: - Municipality ownership (users see their municipality's data) - Department permissions (which occurrence types) - Category restrictions (MunicipalityUser.allowed_occurrence_types)
Permission checking
In views/APIs:
from apps.utils.module_registry import user_can_access_module
if user_can_access_module(request.user, 'equipment', 'create'):
# Allow creation
Creating users
Via Django Admin
- Navigate to Users → Users
- Click Add User
- Set username and password
- Save, then edit to add:
- Email and name
- Staff/superuser flags
- Groups (if using)
Via API (if enabled)
POST /api/users/
{
"username": "jsmith",
"email": "jsmith@municipality.gov",
"password": "secure_password",
"first_name": "John",
"last_name": "Smith"
}
Self-registration
If enabled, citizens can register: 1. Visit registration page 2. Provide email and password 3. Verify email (if required) 4. Account created with basic permissions
Staff onboarding
Process
- Create user account (or have them self-register)
- Create MunicipalityUser profile:
- Assign to correct municipality
- Set appropriate role
- Assign department (if applicable)
- Set permissions:
- Category restrictions (if needed)
- Department permissions
- Approve the user (set is_approved = True)
- Notify the user of their access
Checklist
- [ ] Django user created
- [ ] MunicipalityUser profile created
- [ ] Role assigned
- [ ] Department assigned (optional)
- [ ] Category restrictions set (if needed)
- [ ] User approved
- [ ] Welcome email sent
User approval workflow
For municipalities requiring approval before staff can work:
- User registers or is created
- MunicipalityUser created with
is_approved = False - Administrator reviews the request
- Administrator sets
is_approved = True - User can now access staff functions
Checking approval
municipality_user = request.user.municipality_profile
if not municipality_user.is_approved:
# Deny access to staff functions
Deactivating users
Temporary deactivation
- Set
is_active = Falseon MunicipalityUser - User cannot access municipality functions
- Django user account remains active
Full deactivation
- Set
is_active = Falseon Django User - User cannot log in at all
- Data and history preserved
Permanent removal
Generally not recommended. Instead: - Deactivate the user - Remove sensitive data if required - Maintain audit trail
Audit and logging
User actions are tracked: - Login/logout events - Record modifications (via audit models) - API access (if logging enabled)
View audit information in: - Django Admin audit logs - Record history (created_by, updated_by fields) - API access logs
Behind the scenes (grounded in code)
- User model:
apps/users/models.py(extends Django User) - Municipality profile:
apps/municipalities/models.py→MunicipalityUser - Permission checking:
apps/utils/module_registry.py - Authentication:
config/settings/base.py(AUTH settings) - API authentication: DRF TokenAuthentication or JWT
- Admin:
apps/users/admin.py