fix(secretary): settings menu structure, clinic timeline access, patient delete gate

Three reported secretary-access bugs.

1) Settings menu structure. Phase B flat-listed staff/discounts/sms/tags/
   appointment_settings/clinic_doctors in the secretary's main sidebar. Mirror
   the doctor/clinic layout instead: only inventory + services stay in the main
   «مدیریت» nav; the rest live under a single «تنظیمات» entry
   (→ /admin/account-settings). Made both settings navs permission-aware for
   secretaries: SETTINGS_MENU (menuForRole now takes `can`) and
   PurchaseSubscriptionSidebar filter by a per-item `perm`/`alwaysOpen` instead
   of role only, so a secretary sees exactly their permitted settings pages and
   owner-only items (subscription, secretary-management) stay hidden.

2) Clinic secretary appointment timeline. AppointmentsPage treated a
   clinic-scoped secretary as a single-doctor profile: the doctor list was
   fetched/shown only for isClinic/isAdmin, so no doctor tabs, timeline, or
   booking. Now a clinic-scoped secretary is multi-doctor: fetches the doctor
   list, shows tabs, auto-selects the first doctor. The list comes from a new
   authenticated endpoint GET /api/v1/my/clinic-doctors returning only the
   secretary's ASSIGNED doctors — /clinic/doctor-list is on the public (no-JWT)
   firewall and cannot scope by user, so it would have leaked unbookable doctors.

3) Patient record delete. The `patients.delete` toggle was dead: every record
   delete (note/medical-record/attachment/call/message) was gated as
   `patients.update`. Mapped them to `patients.delete` so the toggle is honored
   and delete is controllable separately from edit.

New SecretaryAccessChecker::assignedClinicDoctorIds. Tests: doctor-list scoping,
patients.delete separation (denied/allowed). docs/api secretary.md +
appointment.md updated. Backend 286 + frontend 25 pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-23 18:01:32 +03:30
co-authored by Claude Opus 4.8
parent 653dd57300
commit 54c8b008bf
14 changed files with 274 additions and 122 deletions
+19 -33
View File
@@ -104,55 +104,41 @@ describe("Sidebar — گِیت منوی منشی بر اساس مجوز", () =>
);
});
it("با مجوز inventory.view و tags.view، همان آیتم‌ها نمایش داده می‌شوند", () => {
setSecretary({ inventory: { view: true }, tags: { view: true } });
it("انبارداری با مجوز inventory.view در سایدبار اصلی می‌آید", () => {
setSecretary({ inventory: { view: true } });
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
expect(screen.getByText("انبارداری").closest("a")).toHaveAttribute(
"href",
"/admin/inventory",
);
expect(screen.getByText("تگ‌ها").closest("a")).toHaveAttribute(
});
it("آیتم «تنظیمات» همیشه برای منشی نمایش داده می‌شود", () => {
setSecretary({ appointments: { view: true } });
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
// «تنظیمات» هم عنوان بخش است هم آیتم؛ فقط لینکِ آیتم را می‌سنجیم.
expect(screen.getByRole("link", { name: "تنظیمات" })).toHaveAttribute(
"href",
"/admin/tags-settings",
"/admin/account-settings",
);
});
it("منابع فاز B (staff/discounts/sms/appointment_settings) با مجوز نمایش داده می‌شوند", () => {
it("منابعِ زیرمجموعهٔ تنظیمات (staff/discounts/sms/tags/appointment/clinic_doctors) در سایدبار اصلی نمی‌آیند", () => {
// حتی با همهٔ مجوزها، این‌ها باید فقط داخل صفحهٔ تنظیمات باشند نه nav اصلی.
setSecretary({
staff: { view: true },
discounts: { view: true },
sms: { view: true },
tags: { view: true },
appointment_settings: { view: true },
clinic_doctors: { view: true },
});
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
expect(screen.getByText("پرسنل").closest("a")).toHaveAttribute("href", "/admin/staff");
expect(screen.getByText("تخفیف‌ها").closest("a")).toHaveAttribute("href", "/admin/discounts");
expect(screen.getByText("پیامک‌ها").closest("a")).toHaveAttribute("href", "/admin/sms-wallet");
// scope=clinic → مسیر تنظیمات کلینیک
expect(screen.getByText("تنظیمات نوبت‌دهی").closest("a")).toHaveAttribute(
"href",
"/admin/settings/appointment-settings",
);
});
it("مدیریت پزشکان کلینیک در scope=doctor حتی با مجوز دیده نمی‌شود", () => {
useAuthStore.setState({
primaryRole: "secretary",
dbUuid: "d1",
userName: "منشی",
availableContexts: [],
context: { scope: "doctor", permissions: { resources: { clinic_doctors: { view: true } } } },
} as any);
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
expect(screen.queryByText("پرسنل")).not.toBeInTheDocument();
expect(screen.queryByText("تخفیف‌ها")).not.toBeInTheDocument();
expect(screen.queryByText("پیامک‌ها")).not.toBeInTheDocument();
expect(screen.queryByText("تگ‌ها")).not.toBeInTheDocument();
expect(screen.queryByText("تنظیمات نوبت‌دهی")).not.toBeInTheDocument();
expect(screen.queryByText("پزشکان کلینیک")).not.toBeInTheDocument();
});
it("مدیریت پزشکان کلینیک در scope=clinic با مجوز دیده می‌شود", () => {
setSecretary({ clinic_doctors: { view: true } });
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
expect(screen.getByText("پزشکان کلینیک").closest("a")).toHaveAttribute(
"href",
"/admin/settings/clinic-doctors",
);
});
});