Server backup 2026-11-07 of uncommitted work in projects/pharma-web-celtic
Snapshot of the working tree on srv1071960 (branch main), taken during server cleanup. .env files, node_modules, builds, logs and media were excluded.
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
Layer 1 (`require_role`) answers "WHAT may this role do?".
|
||||
Layer 2 (`assert_can_*`) answers "WHOSE data may this specific user touch?".
|
||||
|
||||
Most RBAC bugs live in the gap between those two questions: "AM" is a role, but
|
||||
"AM *of this headquarters*" is a scope. Both checks are mandatory on scoped
|
||||
Most RBAC bugs live in the gap between those two questions: "ABM" is the stored role code
|
||||
for an ABM, but "ABM *of this headquarters*" is a scope. Both checks are mandatory on scoped
|
||||
endpoints, and every one has a negative test asserting 403 (X1-X3).
|
||||
"""
|
||||
|
||||
@@ -64,7 +64,7 @@ def require_role(*allowed: Role):
|
||||
|
||||
|
||||
async def active_hq_ids_for_am(db: AsyncSession, am_user_id: uuid.UUID) -> set[uuid.UUID]:
|
||||
"""Headquarters this Area Manager currently manages (`effective_to IS NULL`)."""
|
||||
"""Headquarters this Area Business Manager currently manages (`effective_to IS NULL`)."""
|
||||
stmt = select(AMHeadquarters.headquarters_id).where(
|
||||
AMHeadquarters.area_manager_user_id == am_user_id,
|
||||
AMHeadquarters.effective_to.is_(None),
|
||||
@@ -73,10 +73,10 @@ async def active_hq_ids_for_am(db: AsyncSession, am_user_id: uuid.UUID) -> set[u
|
||||
|
||||
|
||||
async def visible_hq_ids(db: AsyncSession, user: User) -> set[uuid.UUID] | None:
|
||||
"""Headquarters the user may see. `None` means "all" (GM and ADMIN)."""
|
||||
if user.role in (Role.GM, Role.ADMIN):
|
||||
"""Headquarters the user may see. `None` means "all" (AGM and ADMIN)."""
|
||||
if user.role in (Role.AGM, Role.ADMIN):
|
||||
return None
|
||||
if user.role == Role.AM:
|
||||
if user.role == Role.ABM:
|
||||
return await active_hq_ids_for_am(db, user.id)
|
||||
if user.role in FIELD_ROLES:
|
||||
return user.covered_headquarter_ids
|
||||
@@ -94,13 +94,13 @@ async def assert_can_view_dcr(db: AsyncSession, user: User, dcr) -> None:
|
||||
"""Layer 2 for reports.
|
||||
|
||||
ADMIN may inspect report content for support and administration, but cannot act on
|
||||
reports because every transition endpoint still requires the AM role.
|
||||
reports because every transition endpoint still requires the ABM role code (ABM).
|
||||
"""
|
||||
if user.role in (Role.GM, Role.ADMIN):
|
||||
if user.role in (Role.AGM, Role.ADMIN):
|
||||
return
|
||||
if user.role in FIELD_ROLES and dcr.mr_user_id == user.id:
|
||||
return
|
||||
if user.role == Role.AM:
|
||||
if user.role == Role.ABM:
|
||||
if dcr.headquarters_id in await active_hq_ids_for_am(db, user.id):
|
||||
return
|
||||
raise ForbiddenError("Report outside your data scope")
|
||||
|
||||
Reference in New Issue
Block a user