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:
@@ -1,4 +1,4 @@
|
||||
"""One person's whole picture for the General Manager and Admin: who they are, where they
|
||||
"""One person's whole picture for the Assistant General Manager and Admin: who they are, where they
|
||||
work, who they report to, their doctors and chemists, their reports and their company forms."""
|
||||
|
||||
import uuid
|
||||
@@ -139,7 +139,7 @@ async def user_overview(db: AsyncSession, actor: User, user_id: uuid.UUID) -> di
|
||||
data["reports"]["recent"] = [to_list_item(r).model_dump(mode="json") for r in recent]
|
||||
data["forms"] = await _forms(db, user)
|
||||
|
||||
elif user.role == Role.AM:
|
||||
elif user.role == Role.ABM:
|
||||
managed = (
|
||||
await db.execute(
|
||||
select(Headquarters)
|
||||
|
||||
+3
-3
@@ -24,17 +24,17 @@ async def my_profile(
|
||||
@router.get("/{user_id}/overview")
|
||||
async def user_overview(
|
||||
user_id: uuid.UUID,
|
||||
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),
|
||||
) -> dict:
|
||||
"""The whole picture of one person, for the General Manager and Admin."""
|
||||
"""The whole picture of one person, for the Assistant General Manager and Admin."""
|
||||
return await overview.user_overview(db, current_user, user_id)
|
||||
|
||||
|
||||
@router.get("", response_model=list[UserRead])
|
||||
async def list_users(
|
||||
role: Role | None = None,
|
||||
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),
|
||||
) -> list[User]:
|
||||
return await UserService(db).list_users(current_user, role)
|
||||
|
||||
@@ -36,7 +36,7 @@ class UserUpdate(BaseModel):
|
||||
#: A new password. Signs the user out everywhere and clears a lockout.
|
||||
password: str | None = Field(default=None, min_length=8, max_length=128)
|
||||
phone: str | None = Field(default=None, max_length=20)
|
||||
#: Admin-only. Moving to MR needs `headquarters_id`; leaving MR or AM ends that role's
|
||||
#: Admin-only. Moving to MR needs `headquarters_id`; leaving MR or ABM ends that role's
|
||||
#: assignments, and the user is signed out so they sign in again with the new role.
|
||||
role: Role | None = None
|
||||
headquarters_id: uuid.UUID | None = None
|
||||
@@ -61,7 +61,7 @@ class UserRead(BaseModel):
|
||||
|
||||
|
||||
class MyProfile(BaseModel):
|
||||
"""S4 — the MR profile screen. Includes the DERIVED reporting Area Manager."""
|
||||
"""S4 — the MR profile screen. Includes the DERIVED reporting Area Business Manager."""
|
||||
|
||||
id: uuid.UUID
|
||||
full_name: str
|
||||
|
||||
@@ -175,14 +175,14 @@ class UserService:
|
||||
return user
|
||||
|
||||
async def _end_role_assignments(self, user_id: uuid.UUID, old_role: Role) -> dict[str, int]:
|
||||
"""Close what the old role held: an MR's doctors and chemists, an AM's headquarters."""
|
||||
"""Close what the old role held: an MR's doctors and chemists, an ABM's headquarters."""
|
||||
today = date.today()
|
||||
if old_role in FIELD_ROLES:
|
||||
targets = [
|
||||
("doctors", DoctorAssignment, DoctorAssignment.mr_user_id),
|
||||
("chemists", ChemistAssignment, ChemistAssignment.mr_user_id),
|
||||
]
|
||||
elif old_role == Role.AM:
|
||||
elif old_role == Role.ABM:
|
||||
targets = [("headquarters", AMHeadquarters, AMHeadquarters.area_manager_user_id)]
|
||||
else:
|
||||
return {}
|
||||
@@ -204,7 +204,7 @@ class UserService:
|
||||
return list((await self.db.execute(stmt)).scalars().all())
|
||||
|
||||
async def my_profile(self, user: User) -> MyProfile:
|
||||
"""S4 — includes the reporting Area Manager DERIVED through the headquarters."""
|
||||
"""S4 — includes the reporting Area Business Manager DERIVED through the headquarters."""
|
||||
hq_code = hq_name = None
|
||||
manager_id = manager_name = None
|
||||
|
||||
@@ -221,7 +221,7 @@ class UserService:
|
||||
AMHeadquarters.effective_to.is_(None),
|
||||
)
|
||||
)
|
||||
# A headquarters may have several Area Managers: name every one.
|
||||
# A headquarters may have several Area Business Managers: name every one.
|
||||
managers = list((await self.db.execute(stmt.order_by(User.full_name))).scalars())
|
||||
if managers:
|
||||
manager_id = managers[0].id
|
||||
|
||||
Reference in New Issue
Block a user