From df290aef69bee13704c038211e9ef1cb33004f50 Mon Sep 17 00:00:00 2001 From: Jepp9350 <2jepp9350@gmail.com> Date: Thu, 6 Mar 2025 09:32:11 +0100 Subject: [PATCH] Add order existence check and improve permission logic Added a new reactive property `doesOrderExist` to check and reflect the existence of an order in the DepartmentPosOrder component. Updated permission logic in SessionUser to include superuser checks and default handling for department access. This enhances error handling and ensures broader access control flexibility. --- src/components/session/token/SessionUser.vue | 6 +++--- .../modules/Pos/DepartmentPosOrder.vue | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/session/token/SessionUser.vue b/src/components/session/token/SessionUser.vue index d28a24cf..e029bb4b 100644 --- a/src/components/session/token/SessionUser.vue +++ b/src/components/session/token/SessionUser.vue @@ -147,7 +147,7 @@ export const SessionUser = { }, /** Can access shortcuts */ canAccessAdmin: () => { - return SessionUser.hasPermission('admin'); + return SessionUser.hasPermission('admin') || SessionUser.hasPermission('superuser'); }, canAccessSuperUser: () => { return SessionUser.hasPermission('superuser'); @@ -155,8 +155,8 @@ export const SessionUser = { canAccessUser: () => { return SessionUser.hasPermission('user'); }, - canAccessDepartment: (id) => { - return SessionUser.hasPermission('department_access_' + id); + canAccessDepartment: (id = 0) => { + return (SessionUser.hasPermission('department_access_' + parseInt(id)) || SessionUser.canAccessSuperUser()); }, canAccessDeveloper: () => { // If the url is localhost, we can assume that the user is a developer diff --git a/src/views/dashboards/departmentDashboard/modules/Pos/DepartmentPosOrder.vue b/src/views/dashboards/departmentDashboard/modules/Pos/DepartmentPosOrder.vue index d33e9bc6..3731c724 100644 --- a/src/views/dashboards/departmentDashboard/modules/Pos/DepartmentPosOrder.vue +++ b/src/views/dashboards/departmentDashboard/modules/Pos/DepartmentPosOrder.vue @@ -40,6 +40,7 @@ const AddOrderItemsVisible = ref(false); const draftInvoice = ref([]); const errors = ref([]); const closed_at = ref(null); +const doesOrderExist = ref(false); const loadOrder = async () => { isLoading.value = true; @@ -57,6 +58,9 @@ const loadOrder = async () => { isLoading.value = false; setOrderId(orderId.value); selectCustomer(customer.value.economic_customer); + if (response.data.data.id) { + doesOrderExist.value = true; + } if (economicModule.value.invoice_draft_id) { try { draftInvoice.value = await SessionUser.adminUser.invoices.draft.get(economicModule.value.invoice_draft_id).then((response) => { @@ -148,7 +152,9 @@ const isBookedWithEconomic = () => { title="Kassesystem" subtitle="Transaktion" > - +