fix(secretary): gate CRUD action buttons across all panel pages by permission
Backend already returned 403 for ungranted secretary actions, but the UI still showed the add/edit/delete buttons (e.g. clinic-services showed «بخش جدید» to a secretary without services.create). Sweep every secretary-reachable page so each create/edit/delete/manage control renders only when the matching usePermissions().can(resource, action) is true. Owner/doctor/clinic are unaffected — can() returns true when there is no permission context — so this restricts only secretaries and mirrors the server checks. Pages/components gated (resource): - services: ClinicServicesPage, ServiceDetailPage (+ its tabs) - inventory: InventoryPage, InventoryItemsTable, InventoryActionsMenu, PackagesView - tags: TagsSettingsPage · staff: StaffPage · discounts: DiscountTab - sms: SmsWalletPage · insurances: TenantInsuranceContracts - clinic_doctors: ClinicDoctorsPage + ClinicDoctorsManager (props, default true) - patients: PatientsListPage, MyPatientsPage, PatientDetailPage (records/notes/ sessions/attachments/calls/wallet — create/update/delete split) - appointments: AppointmentsPage (add + empty-slot booking gated by create), TurnsTable (status dropdown → read-only badge without update_status; actions menu hidden without manage/cancel) - appointment_settings: AppointmentSettingsPage + ClinicAppointmentSettingsPage pass readOnly to ScheduleSection + FreeVisitPrice (new readOnly prop) Not gated: view/read, search, filter, tabs, navigation, export, and modal submit buttons reachable only via an already-gated trigger. tsc clean; full frontend suite 501/501 passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { UserGroupIcon } from '@heroicons/react/24/outline';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
import { usePermissions } from '../hooks/usePermissions';
|
||||
import SettingsLayout from '../components/layout/SettingsLayout';
|
||||
import { ScheduleSection } from '../components/schedule/ScheduleSection';
|
||||
import FreeVisitPrice from '../components/FreeVisitPrice';
|
||||
@@ -18,6 +19,9 @@ import type { ClinicDoctorItem } from '../components/ClinicDoctorsManager';
|
||||
*/
|
||||
function ClinicAppointmentSettingsContent() {
|
||||
const { dbUuid, context, availableContexts } = useAuthStore();
|
||||
const { can } = usePermissions();
|
||||
// منشیِ بدون مجوزِ ویرایشِ تنظیمات نوبتدهی، فقط مشاهده میکند.
|
||||
const apptReadOnly = !can('appointment_settings', 'update');
|
||||
const [activeUuid, setActiveUuid] = useState<string | null>(null);
|
||||
|
||||
// کاربری که هم پزشک است هم مالک کلینیک، dbUuidاش ممکن است uuid پزشک باشد.
|
||||
@@ -99,8 +103,8 @@ function ClinicAppointmentSettingsContent() {
|
||||
<UserGroupIcon style={{ width: 18, height: 18, color: 'var(--primary)' }} />
|
||||
<span style={{ fontWeight: 600 }}>{selectedDoctor?.name}</span>
|
||||
</div>
|
||||
<FreeVisitPrice doctorUuid={selected} />
|
||||
<ScheduleSection doctorUuid={selected} clinicUuid={clinicUuid} />
|
||||
<FreeVisitPrice doctorUuid={selected} readOnly={apptReadOnly} />
|
||||
<ScheduleSection doctorUuid={selected} clinicUuid={clinicUuid} readOnly={apptReadOnly} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user