refactor: implement role-based access control for customer edit actions in BranchPage and MainPage components
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s

This commit is contained in:
puriphatt 2025-07-03 13:32:21 +07:00
parent aaa448fa0c
commit c991e9e03f
2 changed files with 19 additions and 8 deletions

View file

@ -9,7 +9,7 @@ import { baseUrl } from 'src/stores/utils';
import useCustomerStore from 'stores/customer'; import useCustomerStore from 'stores/customer';
import useFlowStore from 'stores/flow'; import useFlowStore from 'stores/flow';
import useOptionStore from 'stores/options'; import useOptionStore from 'stores/options';
import { dialog } from 'stores/utils'; import { dialog, canAccess } from 'stores/utils';
import { Status } from 'stores/types'; import { Status } from 'stores/types';
import { Employee } from 'stores/employee/types'; import { Employee } from 'stores/employee/types';
@ -285,7 +285,7 @@ watch(
<template> <template>
<FloatingActionButton <FloatingActionButton
style="z-index: 999" style="z-index: 999"
v-if="$route.name !== 'CustomerManagement'" v-if="$route.name !== 'CustomerManagement' && canAccess('customer', 'edit')"
@click="openEmployerBranchForm('create')" @click="openEmployerBranchForm('create')"
hide-icon hide-icon
></FloatingActionButton> ></FloatingActionButton>
@ -615,7 +615,7 @@ watch(
<div class="text-center"> <div class="text-center">
<TableEmpoloyee <TableEmpoloyee
:prefix-id="props.row.registerName || props.row.firstName" :prefix-id="props.row.registerName || props.row.firstName"
add-button :add-button="canAccess('customer', 'edit')"
in-table in-table
:list-employee="listEmployee" :list-employee="listEmployee"
:columns-employee="columnsEmployee" :columns-employee="columnsEmployee"
@ -751,7 +751,7 @@ watch(
}) })
" "
> >
<template #before> <template #before v-if="canAccess('customer', 'edit')">
<EditButton <EditButton
icon-only icon-only
v-if="customerBranchFormState.dialogType === 'info'" v-if="customerBranchFormState.dialogType === 'info'"

View file

@ -6,7 +6,7 @@ import { useRoute, useRouter } from 'vue-router';
import { getUserId, getRole } from 'src/services/keycloak'; import { getUserId, getRole } from 'src/services/keycloak';
import { baseUrl, setPrefixName, waitAll } from 'src/stores/utils'; import { baseUrl, setPrefixName, waitAll } from 'src/stores/utils';
import { dateFormat } from 'src/utils/datetime'; import { dateFormat } from 'src/utils/datetime';
import { dialogCheckData } from 'stores/utils'; import { dialogCheckData, canAccess } from 'stores/utils';
import useOcrStore from 'stores/ocr'; import useOcrStore from 'stores/ocr';
import useCustomerStore from 'stores/customer'; import useCustomerStore from 'stores/customer';
@ -658,7 +658,7 @@ const emptyCreateDialog = ref(false);
<FloatingActionButton <FloatingActionButton
style="z-index: 999" style="z-index: 999"
:hide-icon="currentTab === 'employee'" :hide-icon="currentTab === 'employee'"
v-if="$route.name === 'CustomerManagement'" v-if="$route.name === 'CustomerManagement' && canAccess('customer', 'edit')"
@click=" @click="
() => { () => {
if (currentTab === 'employee') { if (currentTab === 'employee') {
@ -1391,6 +1391,7 @@ const emptyCreateDialog = ref(false);
/> />
<KebabAction <KebabAction
v-if="canAccess('customer', 'edit')"
:id-name=" :id-name="
props.row.branch[0].customerName || props.row.branch[0].customerName ||
props.row.branch[0].firstName props.row.branch[0].firstName
@ -1639,6 +1640,7 @@ const emptyCreateDialog = ref(false);
</template> </template>
<template v-slot:action> <template v-slot:action>
<KebabAction <KebabAction
v-if="canAccess('customer', 'edit')"
:status="props.row.status" :status="props.row.status"
:id-name="props.row.name" :id-name="props.row.name"
@view=" @view="
@ -1889,6 +1891,7 @@ const emptyCreateDialog = ref(false);
" "
> >
<TooltipComponent <TooltipComponent
v-if="canAccess('customer', 'edit')"
class="self-end q-ma-md" class="self-end q-ma-md"
:title="'general.noData'" :title="'general.noData'"
:caption="'general.clickToCreate'" :caption="'general.clickToCreate'"
@ -1900,6 +1903,7 @@ const emptyCreateDialog = ref(false);
style="flex-grow: 1" style="flex-grow: 1"
> >
<EmptyAddButton <EmptyAddButton
v-if="canAccess('customer', 'edit')"
:label="'general.add'" :label="'general.add'"
:i18n-args="{ :i18n-args="{
text: $t(`customer.${currentTab}`), text: $t(`customer.${currentTab}`),
@ -1914,6 +1918,7 @@ const emptyCreateDialog = ref(false);
} }
" "
/> />
<NoData v-else />
</div> </div>
</template> </template>
</div> </div>
@ -3865,6 +3870,7 @@ const emptyCreateDialog = ref(false);
:on-create="customerFormState.dialogModal" :on-create="customerFormState.dialogModal"
:default-url="customerFormState.defaultCustomerImageUrl" :default-url="customerFormState.defaultCustomerImageUrl"
:hidden-footer="!customerFormState.isImageEdit" :hidden-footer="!customerFormState.isImageEdit"
:change-disabled="!canAccess('customer', 'edit')"
@add-image=" @add-image="
async (v) => { async (v) => {
if (!v) return; if (!v) return;
@ -4115,6 +4121,7 @@ const emptyCreateDialog = ref(false);
> >
<ProfileBanner <ProfileBanner
v-if="customerFormData.customerBranch !== undefined" v-if="customerFormData.customerBranch !== undefined"
:readonly="!canAccess('customer', 'edit')"
:prefix="customerFormData.registeredBranchId" :prefix="customerFormData.registeredBranchId"
:active="customerFormData.status !== 'INACTIVE'" :active="customerFormData.status !== 'INACTIVE'"
hide-fade hide-fade
@ -4228,7 +4235,8 @@ const emptyCreateDialog = ref(false);
v-if=" v-if="
customerFormState.branchIndex === -1 && customerFormState.branchIndex === -1 &&
!!customerFormState.editCustomerId && !!customerFormState.editCustomerId &&
customerFormState.dialogType !== 'create' customerFormState.dialogType !== 'create' &&
canAccess('customer', 'edit')
" "
:disabled="!customerFormState.readonly" :disabled="!customerFormState.readonly"
/> />
@ -4412,7 +4420,10 @@ const emptyCreateDialog = ref(false);
prefix-id="info" prefix-id="info"
v-if="!!customerFormState.editCustomerId" v-if="!!customerFormState.editCustomerId"
:index="idx" :index="idx"
:hide-action="customerFormData.status === 'INACTIVE'" :hide-action="
customerFormData.status === 'INACTIVE' ||
!canAccess('customer', 'edit')
"
v-model:customer="customerFormData" v-model:customer="customerFormData"
v-model:customer-branch=" v-model:customer-branch="
customerFormData.customerBranch[idx] customerFormData.customerBranch[idx]