Skip to content

18 · Clinic accounts, management roles and public team ​

Status: ready-for-agent · Approved implementation brief, 2026-08-31

Tracker: GitLab project web/smilab-web. Publication is pending: the local GitLab CLI has no API token in config, keyring or environment. This repository PRD is the documented fallback, not a published issue. Apply the ready-for-agent label when publication becomes available.

Problem Statement ​

Clinic onboarding can assign existing active accounts, but cannot safely invite staff, activate new accounts, recover passwords or distinguish clinic-wide management authority. The public branch detail cannot show an editorially selected real team. Demo personas are not production authorization, and copying them would create inconsistent authority between consultation centres and clinics.

Solution ​

Extend the existing authenticated CRM account and role boundary. A single email identifies one account belonging to at most one clinic, with any number of branch assignments within it. Management authority is clinic-wide and additive. Email invitations and password recovery have safe, single-use lifecycles. CRM owns public names, role labels, optional photos and biographies; Strapi only enables, selects and orders the assigned active team at each selected live branch.

User Stories ​

  1. As a Smilab administrator, I want to designate a clinic owner, so that responsibility is explicit.
  2. As a Smilab administrator, I want to change or remove an owner, so that only the platform controls ownership.
  3. As a clinic owner, I want ordinary member capabilities, so that management does not remove daily work.
  4. As a clinic owner, I want to create, change and remove clinic administrators, so that I can delegate management.
  5. As a clinic administrator, I want every ordinary member capability, so that administration is additive.
  6. As a clinic administrator, I want to invite and manage ordinary members, so that staff can join without manual account creation.
  7. As a clinic administrator, I must not change an owner or another administrator, so that delegated authority cannot escalate itself.
  8. As a member, I want access through the existing authentication and permissions, so that existing CRM behavior stays compatible.
  9. As an administrator, I want to assign a member to several branches of my clinic, so that work across locations needs no duplicate accounts.
  10. As an administrator, I want branch assignments to leave my clinic-wide management scope unchanged, so that I can manage all locations.
  11. As an inviter, I want to invite by email without learning whether it already has an account, so that account existence stays private.
  12. As a new invitee, I want to choose my password through an invitation link, so that I can activate my account securely.
  13. As an existing account holder, I want to sign in and accept an invitation without creating another account, so that my identity remains stable.
  14. As an invitee, I want a seven-day link, so that I have a reasonable time to join.
  15. As an administrator, I want resend to invalidate the earlier link, so that only the latest invitation works.
  16. As an administrator, I want to revoke a pending invitation, so that an unwanted invitation cannot later grant access.
  17. As an account holder, I want ordinary email password recovery, so that a forgotten password does not require a new account.
  18. As an inactive account holder, I must not bypass activation restrictions through an invitation or reset, so that suspension remains effective.
  19. As a clinic administrator, I want to edit a member's public name, photo and biography, so that the website reflects actual staff.
  20. As a staff member, I want my displayed role to derive from the existing account role model, so that public text cannot grant permissions.
  21. As a Strapi editor, I want to enable or disable a branch's team section, so that publication remains an editorial choice.
  22. As a Strapi editor, I want to select only active users assigned to that branch and order them, so that unrelated people do not appear.
  23. As a website visitor, I want only the selected team on the selected branch detail, so that other branches' teams are not mixed in.
  24. As a visitor, I want every team card to have a name and role, with photo and biography optional, so that incomplete optional content does not hide useful staff.
  25. As an operator, I want expired, consumed, revoked and superseded invitation links rejected consistently, so that retries and races cannot grant duplicate access.
  26. As an operator, I want cross-clinic invitations and branch assignments rejected, so that this scope does not accidentally introduce multi-tenant accounts.
  27. As an operator, I want consultation-centre and clinic authorization to use the same production role mechanism, so that neither creates a parallel framework.
  28. As an editor, I want the exact selected-live-branch carousel and detail behavior preserved, so that adding a team does not expand branch visibility.

Implementation Decisions ​

  • Keep the API as the owner of identity verification, authorization, account lifecycle, tenant scope, persistence, email/storage providers and public field projection. CRM and Web use generated contracts.
  • Preserve existing global role values and Smilab behavior. Extend the same production role mechanism with clinic administration and ownership. No standalone profession/position system and no promotion of demo personas into authority.
  • Capability inheritance: clinic member is the baseline; clinic admin includes all member capabilities plus management of ordinary members; clinic owner includes those and management of admins. Only the existing Smilab administrative authority can manage owners. Target-role and requested-role checks both apply, including invitations and self-edits.
  • Share role classification/capability decisions with consultation-centre and existing clinic API guards. Tenant restrictions remain independent of capability inheritance. Branch assignment never restricts administrator scope or grants management authority.
  • Keep one existing auth identity per normalized email and one clinic per account. Reject a different-clinic identity without enumerating it to an unauthenticated caller. Retain stable identity UUIDs and existing branch assignments.
  • Invitation states are pending, accepted, revoked, superseded or expired. Store only a hash of a high-entropy application token; seven-day expiry, single-use atomic acceptance, serialized resend/revoke and replay rejection. Email delivery errors must not expose provider details or tokens. Secrets never enter logs or public DTOs.
  • New identities choose a password through the invitation. Existing identities authenticate and accept as the invited email identity. An invitation must not reset an existing user's password, reactivate a suspended account or transfer it to another clinic.
  • Password recovery uses the existing identity provider behind the API boundary, with generic request responses, short-lived single-use recovery credentials and no account enumeration. Existing active gates remain effective.
  • Public profile has name, role derived from the account role, optional safe image URL/photo and optional short bio. No publication-ready flag. Neither display text nor CMS selection can grant account permissions.
  • Strapi stores branch-level team enablement and ordered profile UUID references, not profile content. Eligibility is revalidated against current active status, tenant, branch assignment and a usable name/role on every public read. Omit unusable or stale selected profiles; deduplicate by first occurrence and preserve editorial order. No automatic selection, siblings or fallback people.
  • Preserve original carousel/detail draft behavior: exact enabled branch/tenant pairs, live only, current published selection, one branch per detail, canonical slug/UUID and validated legacy redirect. No booking CTA.
  • Migrations are additive, preserve data and existing role meaning, and explicitly account for the earlier blanket clinic-admin backfill. Do not infer an owner from that backfill. Existing clinic administrators retain equivalent management access; owners require explicit Smilab assignment.

Testing Decisions ​

  • Prefer the existing injected authentication service and onboarding service boundary, with API injection tests and isolated real-PostgreSQL integration tests. Test observable behavior and database outcomes rather than duplicating helper implementation.
  • Cover unauthenticated, inactive, wrong-tenant, ordinary member, admin, owner and Smilab actors against both the current target role and requested replacement role. Assert inheritance explicitly and preserve consultation-centre access behavior.
  • Cover normalized-email identity reuse, new-user activation, authenticated existing-user acceptance, wrong signed-in identity, duplicate requests, acceptance races, expiry boundary, resend invalidation, revocation and replay. Assert no cross-tenant reassignment, no duplicate identity and no partial grant after failure.
  • Cover generic reset requests, invalid/expired/replayed credentials, password validation, provider failure and suspended-account behavior. Ensure tokens/provider details never appear in DTOs or errors.
  • Test multi-branch assignment within one clinic and rejection of other-clinic or inactive users/branches as applicable.
  • Test public field allowlisting and CMS enabled/disabled/empty configuration, active assignment eligibility, required name/role, optional photo/bio, exact ordering, deduplication and stale references. Preserve selected-live-branch and HTTP 404/308 regression tests.
  • Run narrow checks and types first, behavior tests and relevant integration suites, generated-client checks, Tailwind checks and affected API/CRM/Web/Strapi builds. Review before draft commits/pushes. Do not run migrations against hosted data during implementation.

Out of Scope ​

Multi-tenant identities or memberships; booking/availability/reservation work and CTA; replacement of authentication or the role system; a new profession taxonomy; production authority for demo-only roles; automatic team publishing; user-level publication switches; copying CRM profiles into CMS; merges or production rollout.

Further Notes ​

Dependency order: onboarding account/role migrations and API first; Strapi team contract second; generated client and Web team rendering third. The existing Web draft !10 and Strapi draft !1 retain their committed branch-selection work. The onboarding-focused draft is based on the current UX onboarding branch and must reconcile current main changes without overwriting them. Product docs travel with these implementation drafts; no docs-only MR. Email/provider configuration and valid hosted TLS must be verified before deployment; local verification is not proof of hosted delivery.

Approved membership lifecycle guard ​

Read-only inventory of current persisted dependencies: branch membership joins; live branch completeness requires an active assigned user; appointments can reference a profile as a sales_rep resource; recurring working hours and dated schedule exceptions use that same resource identity; centre sales-representative membership links profiles; leads retain their responsible profile; consultation consent and onboarding audit records retain historical actor identities. Booking options belong to branches and currently have no staff/profile assignment. No clinic staff reservation or per-user clinic service assignment table exists yet.

Do not hard-delete accounts. Deactivation is reversible and preserves audit, consent and historical appointments. At the existing membership mutation boundary, block deactivation/removal of assignments that would break a live branch's active-staff requirement, a nonterminal appointment, an applicable recurring schedule or future schedule exception, or an active operational assignment. Return a specific human-readable conflict reason, never silently cancel bookings or reassign work. Preserve historical membership removal in the onboarding audit. Use existing models only; future per-user clinic service/calendar reservations must extend this same guard before being introduced. Branch booking options alone cannot identify which staff member serves them and must not be treated as invented per-user reservations.

Tests must prove rejection is atomic and historical records remain unchanged; removing a redundant member with no active dependencies remains allowed. Guard both member deactivation and the existing onboarding branch-assignment editor so one route cannot bypass the other. Scope checks and actor/target role restrictions precede any returned dependency details.

Recovery delivery and provider failures ​

Recovery requests return the same immediate response without waiting for account lookup or SMTP delivery, preventing account-existence timing differences. This first implementation starts delivery in the API process; a durable email outbox/retry worker is not yet present and remains a deployment reliability limitation. SMTP transport uses finite timeouts and requires TLS in production. Recovery tokens expire after one hour. Consumption and an authentication-pending gate commit before the identity-provider password write. A second transaction locks the profile across the provider write and finalization; the attempt identifier rejects an obsolete queued reset. Successful completion invalidates sessions again and clears the gate. Login sessions carry the request start time, so a delayed old-password login cannot survive the reset. Provider failure or process interruption leaves authentication blocked until a fresh recovery succeeds; the old token is never replayed. Invitation activation uses the invitation UUID as the provisional identity UUID so a provider-success/database-rollback retry can reconcile the same identity without duplicating an account.