Fix: add role authorization in Resume
This commit is contained in:
@@ -19,9 +19,17 @@ import Confirmation from '~/components/pub/my-ui/confirmation/confirmation.vue'
|
|||||||
import type { ExposedForm } from '~/types/form'
|
import type { ExposedForm } from '~/types/form'
|
||||||
import { VerificationSchema } from '~/schemas/verification.schema'
|
import { VerificationSchema } from '~/schemas/verification.schema'
|
||||||
import DocPreviewDialog from '~/components/pub/my-ui/modal/doc-preview-dialog.vue'
|
import DocPreviewDialog from '~/components/pub/my-ui/modal/doc-preview-dialog.vue'
|
||||||
|
import type { PagePermission } from '~/models/role'
|
||||||
|
import { PAGE_PERMISSIONS } from '~/lib/page-permission'
|
||||||
|
import { unauthorizedToast } from '~/lib/utils'
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
|
|
||||||
|
// #region Permission
|
||||||
|
const roleAccess: PagePermission = PAGE_PERMISSIONS['/rehab/encounter']
|
||||||
|
const { getPagePermissions } = useRBAC()
|
||||||
|
const pagePermission = getPagePermissions(roleAccess)
|
||||||
|
|
||||||
// #region State
|
// #region State
|
||||||
const { data, isLoading, paginationMeta, searchInput, handlePageChange, handleSearch, fetchData } = usePaginatedList({
|
const { data, isLoading, paginationMeta, searchInput, handlePageChange, handleSearch, fetchData } = usePaginatedList({
|
||||||
fetchFn: (params) => getPatients({ ...params, includes: ['person', 'person-Addresses'] }),
|
fetchFn: (params) => getPatients({ ...params, includes: ['person', 'person-Addresses'] }),
|
||||||
@@ -55,11 +63,13 @@ provide('isCaptchaValid', isCaptchaValid)
|
|||||||
const headerPrep: HeaderPrep = {
|
const headerPrep: HeaderPrep = {
|
||||||
title: "Resume",
|
title: "Resume",
|
||||||
icon: 'i-lucide-newspaper',
|
icon: 'i-lucide-newspaper',
|
||||||
addNav: {
|
}
|
||||||
label: "Resume",
|
if (pagePermission.canCreate) {
|
||||||
onClick: () => navigateTo('/resume/add'),
|
headerPrep.addNav = {
|
||||||
},
|
label: "Resume",
|
||||||
}
|
onClick: () => navigateTo('/resume/add'),
|
||||||
|
}
|
||||||
|
}
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region Lifecycle Hooks
|
// #region Lifecycle Hooks
|
||||||
@@ -146,17 +156,25 @@ provide('table_data_loader', isLoading)
|
|||||||
|
|
||||||
// #region Watchers
|
// #region Watchers
|
||||||
watch([recId, recAction], () => {
|
watch([recId, recAction], () => {
|
||||||
switch (recAction.value) {
|
switch (recAction.value) {
|
||||||
case ActionEvents.showVerify:
|
case ActionEvents.showVerify:
|
||||||
isVerifyDialogOpen.value = true
|
if(pagePermission.canUpdate) {
|
||||||
break
|
isVerifyDialogOpen.value = true
|
||||||
case ActionEvents.showValidate:
|
} else {
|
||||||
isRecordConfirmationOpen.value = true
|
unauthorizedToast()
|
||||||
break
|
}
|
||||||
case ActionEvents.showPrint:
|
break
|
||||||
isDocPreviewDialogOpen.value = true
|
case ActionEvents.showValidate:
|
||||||
break
|
if(pagePermission.canUpdate) {
|
||||||
}
|
isRecordConfirmationOpen.value = true
|
||||||
|
} else {
|
||||||
|
unauthorizedToast()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case ActionEvents.showPrint:
|
||||||
|
isDocPreviewDialogOpen.value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// #endregion
|
// #endregion
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import type { Permission, RoleAccess } from '~/models/role'
|
import type { Permission, RoleAccess } from '~/models/role'
|
||||||
|
|
||||||
|
export interface PageOperationPermission {
|
||||||
|
canRead: boolean
|
||||||
|
canCreate: boolean
|
||||||
|
canUpdate: boolean
|
||||||
|
canDelete: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if user has access to a page
|
* Check if user has access to a page
|
||||||
*/
|
*/
|
||||||
@@ -36,6 +44,14 @@ export function useRBAC() {
|
|||||||
const hasUpdateAccess = (roleAccess: RoleAccess) => checkPermission(roleAccess, 'U')
|
const hasUpdateAccess = (roleAccess: RoleAccess) => checkPermission(roleAccess, 'U')
|
||||||
const hasDeleteAccess = (roleAccess: RoleAccess) => checkPermission(roleAccess, 'D')
|
const hasDeleteAccess = (roleAccess: RoleAccess) => checkPermission(roleAccess, 'D')
|
||||||
|
|
||||||
|
const getPagePermissions = (roleAccess: RoleAccess): PageOperationPermission => ({
|
||||||
|
canRead : hasReadAccess(roleAccess),
|
||||||
|
canCreate: hasCreateAccess(roleAccess),
|
||||||
|
canUpdate: hasUpdateAccess(roleAccess),
|
||||||
|
canDelete: hasDeleteAccess(roleAccess),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
checkRole,
|
checkRole,
|
||||||
checkPermission,
|
checkPermission,
|
||||||
@@ -44,5 +60,7 @@ export function useRBAC() {
|
|||||||
hasReadAccess,
|
hasReadAccess,
|
||||||
hasUpdateAccess,
|
hasUpdateAccess,
|
||||||
hasDeleteAccess,
|
hasDeleteAccess,
|
||||||
|
getPagePermissions,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { ClassValue } from 'clsx'
|
import type { ClassValue } from 'clsx'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
import { toast } from '~/components/pub/ui/toast'
|
||||||
|
|
||||||
export interface SelectOptionType<_T = string> {
|
export interface SelectOptionType<_T = string> {
|
||||||
value: string
|
value: string
|
||||||
@@ -104,3 +105,11 @@ export function calculateAge(birthDate: Date | string | null | undefined): strin
|
|||||||
return `${years} tahun ${months} bulan`
|
return `${years} tahun ${months} bulan`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function unauthorizedToast() {
|
||||||
|
toast({
|
||||||
|
title: 'Unauthorized',
|
||||||
|
description: 'You are not authorized to perform this action.',
|
||||||
|
variant: 'destructive',
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user