fix: fetch permission.attrOwnership
This commit is contained in:
parent
17c05d60d7
commit
503d111634
1 changed files with 50 additions and 27 deletions
|
|
@ -9,6 +9,7 @@ import { useRoute, useRouter } from "vue-router";
|
|||
import { checkPermission } from "@/utils/permissions";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { usePlacementDataStore } from "@/modules/05_placement/store";
|
||||
import { useMenuDataStore } from "@/stores/menuList";
|
||||
import avatar from "@/assets/avatar_user.jpg";
|
||||
|
||||
import type { PartialTableName } from "@/modules/05_placement/interface/request/placement";
|
||||
|
|
@ -27,6 +28,7 @@ import DialogPreviewCommand from "@/modules/18_command/components/DialogPreviewC
|
|||
|
||||
const $q = useQuasar(); // show dialog
|
||||
const DataStore = usePlacementDataStore();
|
||||
const storeMenu = useMenuDataStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง
|
||||
|
|
@ -55,7 +57,14 @@ const command = ref<string>("");
|
|||
const commandId = ref<string>("");
|
||||
const commandCitizenId = ref<string>("");
|
||||
|
||||
let roleAdmin = ref<boolean>(false);
|
||||
// เปลี่ยนจาก ref เป็น computed property
|
||||
const roleAdmin = computed(() => {
|
||||
if (!storeMenu.permissions) return false;
|
||||
|
||||
const permission = checkPermission(route);
|
||||
return DataStore.isOfficer || permission?.attrOwnership == "OWNER";
|
||||
});
|
||||
|
||||
const edit = ref<boolean>(true);
|
||||
const modalPersonal = ref<boolean>(false);
|
||||
const modal = ref<boolean>(false); //modal ขอผ่อนผัน + สละสิทธิ์
|
||||
|
|
@ -92,6 +101,18 @@ const personal_selected = ref<any>([]);
|
|||
const filterlistAdd = ref<string>("");
|
||||
const paging = ref<boolean>(true);
|
||||
|
||||
// เพิ่ม watcher สำหรับ roleAdmin
|
||||
watch(
|
||||
roleAdmin,
|
||||
(newValue) => {
|
||||
const permission = checkPermission(route);
|
||||
if (!newValue && permission?.attrOwnership !== "OWNER") {
|
||||
displayAdd.value = false;
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// เช็ตสถานะการเลือกคนไปยังหน่วยงาน
|
||||
const checkSelected = computed(() => {
|
||||
if (selected.value.length === 0) {
|
||||
|
|
@ -248,16 +269,17 @@ const columnsBase = ref<QTableProps["columns"]>([
|
|||
},
|
||||
]);
|
||||
|
||||
const columns = computed(() =>
|
||||
roleAdmin.value || checkPermission(route)?.attrOwnership == "OWNER"
|
||||
const columns = computed(() => {
|
||||
const permission = checkPermission(route);
|
||||
return roleAdmin.value || permission?.attrOwnership == "OWNER"
|
||||
? columnsBase.value
|
||||
: columnsBase.value?.filter(
|
||||
(col) =>
|
||||
col.name !== "no" &&
|
||||
col.name !== "draft" &&
|
||||
col.name !== "refCommandNo"
|
||||
)
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* แปลงสถานะพนักงาน
|
||||
|
|
@ -406,8 +428,9 @@ async function getTable() {
|
|||
rowsAll.value.push(rowData);
|
||||
});
|
||||
|
||||
const permission = checkPermission(route);
|
||||
const rowData = await (roleAdmin.value ||
|
||||
checkPermission(route)?.attrOwnership == "OWNER"
|
||||
permission?.attrOwnership == "OWNER"
|
||||
? rowsAll.value
|
||||
: rowsAll.value.filter((x: any) => x.isDraft === true));
|
||||
|
||||
|
|
@ -554,8 +577,9 @@ function getClass(val: boolean) {
|
|||
* @param draft status
|
||||
*/
|
||||
function selectData(pid: string, draft: string) {
|
||||
const permission = checkPermission(route);
|
||||
if (
|
||||
(roleAdmin.value || checkPermission(route)?.attrOwnership == "OWNER") &&
|
||||
(roleAdmin.value || permission?.attrOwnership == "OWNER") &&
|
||||
draft === "ส่งตัวแล้ว"
|
||||
) {
|
||||
personalId.value = pid;
|
||||
|
|
@ -858,34 +882,33 @@ async function filterRowsMain(type: string, pos: string) {
|
|||
});
|
||||
}
|
||||
|
||||
// Helper function รอให้ permissions load เสร็จ
|
||||
function waitForPermissions(): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const checkPermissions = () => {
|
||||
if (storeMenu.permissions) {
|
||||
resolve();
|
||||
} else {
|
||||
setTimeout(checkPermissions, 100); // เช็คทุก 100ms
|
||||
}
|
||||
};
|
||||
checkPermissions();
|
||||
});
|
||||
}
|
||||
|
||||
// ปรับปรุง getWorkFlow function
|
||||
async function getWorkFlow() {
|
||||
showLoader();
|
||||
|
||||
// รอให้ permissions load เสร็จก่อน
|
||||
await waitForPermissions();
|
||||
|
||||
await http
|
||||
.get(config.API.workflowKeycloakSystem("SYS_PLACEMENT_PASS"))
|
||||
.then(async (res) => {
|
||||
const data = await res.data.result;
|
||||
DataStore.isOfficer = data.isOfficer;
|
||||
DataStore.isStaff = data.isStaff;
|
||||
roleAdmin.value =
|
||||
data.isOfficer || checkPermission(route)?.attrOwnership == "OWNER";
|
||||
if (
|
||||
roleAdmin.value === false &&
|
||||
checkPermission(route)?.attrOwnership !== "OWNER"
|
||||
) {
|
||||
displayAdd.value = false;
|
||||
// visibleColumns.value = [
|
||||
// "position",
|
||||
// "fullName",
|
||||
// "examNumber",
|
||||
// "idCard",
|
||||
// "positionNumber",
|
||||
// "organizationName",
|
||||
// "reportingDate",
|
||||
// "bmaOfficer",
|
||||
// "statusName",
|
||||
// "positionCandidate",
|
||||
// ];
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue