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,7 +3,7 @@
|
||||
Design notes (report §13.2):
|
||||
- `area_territory` was merged into `headquarters` — the brief states HQ *is* the
|
||||
territory, and two tables for one concept invites drift.
|
||||
- An MR's Area Manager is DERIVED through the headquarters, not stored on the MR.
|
||||
- An MR's Area Business Manager is DERIVED through the headquarters, not stored on the MR.
|
||||
An HQ handover therefore re-points every MR in that HQ with no data migration.
|
||||
"""
|
||||
|
||||
@@ -54,10 +54,10 @@ class Headquarters(Base, UUIDMixin, TimestampMixin):
|
||||
|
||||
|
||||
class AMHeadquarters(Base, UUIDMixin, TimestampMixin):
|
||||
"""Which Area Manager currently manages which headquarters.
|
||||
"""Which Area Business Manager currently manages which headquarters.
|
||||
|
||||
`effective_to IS NULL` means "current". A headquarters may have several Area Managers
|
||||
and an Area Manager several headquarters; the partial unique index only stops the same
|
||||
`effective_to IS NULL` means "current". A headquarters may have several Area Business Managers
|
||||
and an Area Business Manager several headquarters; the partial unique index only stops the same
|
||||
pair being active twice.
|
||||
"""
|
||||
|
||||
|
||||
@@ -24,16 +24,16 @@ router = APIRouter(prefix="/headquarters", tags=["organization"])
|
||||
async def list_headquarters(
|
||||
current_user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)
|
||||
) -> list[Headquarters]:
|
||||
"""Scoped: an MR sees their own HQ, an AM sees theirs, GM/Admin see all."""
|
||||
"""Scoped: an MR sees their own HQ, an ABM sees theirs, AGM/Admin see all."""
|
||||
return await OrganizationService(db).list_headquarters(current_user)
|
||||
|
||||
|
||||
@router.get("/area-managers", response_model=list[AMHeadquartersRead])
|
||||
async def list_area_manager_mappings(
|
||||
current_user: User = Depends(require_role(Role.ADMIN, Role.GM)),
|
||||
current_user: User = Depends(require_role(Role.ADMIN, Role.AGM)),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Which Area Manager currently manages which headquarters (one row per pair)."""
|
||||
"""Which Area Business Manager currently manages which headquarters (one row per pair)."""
|
||||
return await OrganizationService(db).list_area_manager_mappings(current_user)
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ async def set_area_manager_headquarters(
|
||||
current_user: User = Depends(require_role(Role.ADMIN)),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Replace the set of headquarters an Area Manager manages (any number)."""
|
||||
"""Replace the set of headquarters an Area Business Manager manages (any number)."""
|
||||
return await OrganizationService(db).set_area_manager_headquarters(
|
||||
area_manager_user_id,
|
||||
payload.headquarters_ids,
|
||||
|
||||
@@ -43,7 +43,7 @@ class AssignAreaManager(BaseModel):
|
||||
|
||||
|
||||
class SetAreaManagerHeadquarters(BaseModel):
|
||||
"""The complete list of headquarters an Area Manager should manage (may be empty)."""
|
||||
"""The complete list of headquarters an Area Business Manager should manage (may be empty)."""
|
||||
|
||||
headquarters_ids: list[uuid.UUID] = Field(default_factory=list, max_length=500)
|
||||
effective_from: date | None = None
|
||||
|
||||
@@ -60,7 +60,7 @@ class OrganizationService:
|
||||
return list((await self.db.execute(stmt)).scalars().all())
|
||||
|
||||
async def list_area_manager_mappings(self, actor: User) -> list[AMHeadquarters]:
|
||||
"""Current (open) Area Manager to headquarters mappings, for display."""
|
||||
"""Current (open) Area Business Manager to headquarters mappings, for display."""
|
||||
stmt = (
|
||||
select(AMHeadquarters)
|
||||
.join(Headquarters, Headquarters.id == AMHeadquarters.headquarters_id)
|
||||
@@ -79,7 +79,7 @@ class OrganizationService:
|
||||
actor: User,
|
||||
ip: str | None = None,
|
||||
) -> list[AMHeadquarters]:
|
||||
"""Make `headquarters_ids` exactly the set of headquarters this AM manages.
|
||||
"""Make `headquarters_ids` exactly the set of headquarters this ABM manages.
|
||||
|
||||
Headquarters missing from the list are released, new ones are added. Other Area
|
||||
Managers of the same headquarters keep it: a headquarters may have several.
|
||||
@@ -87,9 +87,9 @@ class OrganizationService:
|
||||
manager = await self.db.get(User, am_user_id)
|
||||
if manager is None or manager.company_id != actor.company_id:
|
||||
raise NotFoundError("User not found")
|
||||
if manager.role != Role.AM:
|
||||
if manager.role != Role.ABM:
|
||||
raise ValidationError(
|
||||
"Only a user with the AM role can manage a headquarters",
|
||||
"Only an ABM can manage a headquarters",
|
||||
{"user_role": manager.role.value},
|
||||
)
|
||||
|
||||
@@ -165,7 +165,7 @@ class OrganizationService:
|
||||
actor: User,
|
||||
ip: str | None = None,
|
||||
) -> AMHeadquarters:
|
||||
"""Add an Area Manager to a headquarters, beside any it already has.
|
||||
"""Add an Area Business Manager to a headquarters, beside any it already has.
|
||||
|
||||
Assigning the same pair twice changes nothing (`uq_active_am_hq_pair`).
|
||||
"""
|
||||
@@ -176,9 +176,9 @@ class OrganizationService:
|
||||
manager = await self.db.get(User, am_user_id)
|
||||
if manager is None:
|
||||
raise NotFoundError("User not found")
|
||||
if manager.role != Role.AM:
|
||||
if manager.role != Role.ABM:
|
||||
raise ValidationError(
|
||||
"Only a user with the AM role can manage a headquarters",
|
||||
"Only an ABM can manage a headquarters",
|
||||
{"user_role": manager.role.value},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user