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.
This commit is contained in:
Jepp9350
2025-03-06 09:32:11 +01:00
parent 6a36244fd0
commit df290aef69
2 changed files with 10 additions and 4 deletions
+3 -3
View File
@@ -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
@@ -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"
>
<notFoundFallBackPageWrapper :exists="(customer_name || isLoading) && (SessionUser.functions.getDepartmentIdFromUrl() > 1 && SessionUser.canAccessDepartment(SessionUser.functions.getDepartmentIdFromUrl()))" error="Denne handel findes ikke, eller du har ikke adgang til at se den.">
<notFoundFallBackPageWrapper
v-bind:exists="doesOrderExist || isLoading"
error="Denne handel findes ikke, eller du har ikke adgang til at se den.">
<div class="columns">
<div class="column is-8-desktop" v-if="AddOrderItemsVisible">
<SelectProductsFormPOS class="mt-3" category="products" />