4.0 KiB
4.0 KiB
PX Source User - Strict Access Control
Overview
PX Source Users have STRICT LIMITED ACCESS to the system. They can ONLY access:
/px-sources/*pages (their dedicated portal)- Password change page
- Basic settings page
- Logout
ALL other URLs are blocked and redirected to /px-sources/dashboard/
Implementation
1. Middleware (apps/px_sources/middleware.py)
class SourceUserRestrictionMiddleware:
"""
STRICT middleware that restricts source users to ONLY:
1. /px-sources/* pages
2. Password change
3. Settings
4. Logout
"""
ALLOWED_PATH_PREFIXES = ['/px-sources/']
ALLOWED_URL_NAMES = {
'accounts:password_change',
'accounts:settings',
'accounts:logout',
'accounts:login',
}
2. Settings Configuration
Added to config/settings/base.py:
MIDDLEWARE = [
...
'apps.px_sources.middleware.SourceUserRestrictionMiddleware',
...
]
3. View-Level Enforcement
Updated views to redirect source users:
CommandCenterView.dispatch()- redirects to/px-sources/dashboard/my_dashboard()- redirects to/px-sources/dashboard/@block_source_userdecorator - redirects to/px-sources/dashboard/
Allowed URLs for Source Users
| URL | Access | Description |
|---|---|---|
/px-sources/dashboard/ |
✅ | Source User Dashboard |
/px-sources/complaints/ |
✅ | List their complaints |
/px-sources/complaints/new/ |
✅ | Create new complaint |
/px-sources/inquiries/ |
✅ | List their inquiries |
/px-sources/inquiries/new/ |
✅ | Create new inquiry |
/accounts/password/change/ |
✅ | Change password |
/accounts/settings/ |
✅ | Basic settings |
/accounts/logout/ |
✅ | Logout |
/static/* |
✅ | Static files (CSS/JS) |
/media/* |
✅ | Media files |
/i18n/* |
✅ | Language switching |
Blocked URLs (Redirected to /px-sources/dashboard/)
| URL | Blocked | Behavior |
|---|---|---|
/ |
✅ | Redirected |
/dashboard/my/ |
✅ | Redirected |
/dashboard/admin-evaluation/ |
✅ | Redirected |
/analytics/* |
✅ | Redirected |
/surveys/* |
✅ | Redirected |
/complaints/ |
✅ | Redirected |
/complaints/inquiries/ |
✅ | Redirected |
/organizations/* |
✅ | Redirected |
/config/* |
✅ | Redirected |
/actions/* |
✅ | Redirected |
/physicians/* |
✅ | Redirected |
/px-sources/ (admin pages) |
✅ | Redirected |
/px-sources/new/ |
✅ | Redirected |
/px-sources/<id>/edit/ |
✅ | Redirected |
Testing
Test Cases
-
Login as Source User
- Visit:
/ - Expected: Redirected to
/px-sources/dashboard/
- Visit:
-
Try to access Command Center
- Visit:
/dashboard/my/ - Expected: Redirected to
/px-sources/dashboard/
- Visit:
-
Try to access Surveys
- Visit:
/surveys/ - Expected: Redirected to
/px-sources/dashboard/
- Visit:
-
Try to access Staff
- Visit:
/organizations/staff/ - Expected: Redirected to
/px-sources/dashboard/
- Visit:
-
Access Source User Portal
- Visit:
/px-sources/dashboard/ - Expected: ✅ Works!
- Visit:
-
Access Password Change
- Visit:
/accounts/password/change/ - Expected: ✅ Works!
- Visit:
-
Create Complaint
- Visit:
/px-sources/complaints/new/ - Expected: ✅ Works!
- Visit:
Security Notes
- Middleware runs on EVERY request - Cannot be bypassed
- No error messages - Silent redirect for better UX
- Whitelist approach - Only explicitly allowed URLs work
- Superusers excluded - Superusers bypass all restrictions
- Static files allowed - Required for CSS/JS to work
Files Modified
apps/px_sources/middleware.py- UpdatedSourceUserRestrictionMiddlewareconfig/settings/base.py- Added middleware to MIDDLEWARE listapps/dashboard/views.py- Added redirects in viewsapps/core/decorators.py- Updated@block_source_userdecorator
Last Updated: 2026-02-25