initial commit

This commit is contained in:
Antigravity
2026-11-18 18:06:22 +05:30
commit 13556aa423
229 changed files with 58732 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
from dataclasses import dataclass
from typing import Optional
from ..models import User
from .permissions import Role
@dataclass
class DepartmentScope:
is_unconstrained: bool
department_id: Optional[int]
is_empty: bool
def resolve_department_scope(
user: User,
requested_dept_id: Optional[int] = None,
) -> DepartmentScope:
"""Resolve department scoping based on user role and assigned department.
Rules:
- If user.role != 'department_user': unconstrained, department_id=requested_dept_id, is_empty=False.
- If user.role == 'department_user' and user.department_id is None: is_empty=True, department_id=None, is_unconstrained=False.
- If user.role == 'department_user' and user.department_id is not None: is_empty=False, department_id=user.department_id
(requested_dept_id is ignored, cannot widen or change), is_unconstrained=False.
"""
if user.role != Role.department_user.value:
return DepartmentScope(
is_unconstrained=True,
department_id=requested_dept_id,
is_empty=False,
)
if user.department_id is None:
return DepartmentScope(
is_unconstrained=False,
department_id=None,
is_empty=True,
)
return DepartmentScope(
is_unconstrained=False,
department_id=user.department_id,
is_empty=False,
)