ปรับสิทธิ์
This commit is contained in:
parent
b356eef92f
commit
c8a9dbb259
3 changed files with 27 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ import { useQuasar } from "quasar";
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
import { useCounterMixin } from "@/stores/mixin";
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
import { setAuthen, authenticated, tokenParsed } from "@/plugins/auth";
|
||||||
|
|
||||||
import type { QTableProps } from "quasar";
|
import type { QTableProps } from "quasar";
|
||||||
import type {
|
import type {
|
||||||
|
|
@ -193,13 +194,13 @@ function fetchUserDetail(id: string) {
|
||||||
function fetchlistRole() {
|
function fetchlistRole() {
|
||||||
http
|
http
|
||||||
.get(config.API.managementRole)
|
.get(config.API.managementRole)
|
||||||
.then((res) => {
|
.then(async (res) => {
|
||||||
roleOptions.value = res.data.filter(
|
const checkToken: any = await tokenParsed();
|
||||||
(e: Roles) =>
|
const roleSuper = await checkToken.role.includes("SUPER_ADMIN");
|
||||||
e.name === "STAFF" ||
|
roleOptions.value = res.data.filter((e: Roles) =>
|
||||||
e.name === "SUPER_ADMIN" ||
|
roleSuper
|
||||||
e.name === "ADMIN" ||
|
? ["STAFF", "SUPER_ADMIN", "ADMIN", "USER"].includes(e.name)
|
||||||
e.name === "USER"
|
: ["STAFF", "USER"].includes(e.name)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { useQuasar } from "quasar";
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
import { useCounterMixin } from "@/stores/mixin";
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
import { setAuthen, authenticated, tokenParsed } from "@/plugins/auth";
|
||||||
|
|
||||||
import type { QTableProps } from "quasar";
|
import type { QTableProps } from "quasar";
|
||||||
import type { Roles } from "@/modules/02_users/interface/request/Main";
|
import type { Roles } from "@/modules/02_users/interface/request/Main";
|
||||||
|
|
@ -25,6 +26,7 @@ const {
|
||||||
|
|
||||||
/** props*/
|
/** props*/
|
||||||
const modal = defineModel<boolean>("modal", { required: true });
|
const modal = defineModel<boolean>("modal", { required: true });
|
||||||
|
const roleSuper = defineModel<boolean>("roleSuper", { required: true });
|
||||||
const userId = defineModel<string>("userId", { required: true });
|
const userId = defineModel<string>("userId", { required: true });
|
||||||
const roles = defineModel<any[]>("roles");
|
const roles = defineModel<any[]>("roles");
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
@ -69,13 +71,12 @@ function fetchlistRole() {
|
||||||
.get(config.API.managementRole)
|
.get(config.API.managementRole)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const rolesIds = roles.value?.map((e) => e.id);
|
const rolesIds = roles.value?.map((e) => e.id);
|
||||||
|
const item = roleSuper.value
|
||||||
|
? ["USER", "ADMIN", "SUPER_ADMIN", "STAFF"]
|
||||||
|
: ["USER", "STAFF"];
|
||||||
|
|
||||||
rows.value = res.data.filter(
|
rows.value = res.data.filter(
|
||||||
(v: Roles) =>
|
(v: Roles) => !rolesIds?.includes(v.id) && item.includes(v.name)
|
||||||
!rolesIds?.includes(v.id) &&
|
|
||||||
(v.name == "USER" ||
|
|
||||||
v.name == "ADMIN" ||
|
|
||||||
v.name == "SUPER_ADMIN" ||
|
|
||||||
v.name == "STAFF")
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { useRouter, useRoute } from "vue-router";
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
import { useCounterMixin } from "@/stores/mixin";
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
import { setAuthen, authenticated, tokenParsed } from "@/plugins/auth";
|
||||||
|
|
||||||
/** importType*/
|
/** importType*/
|
||||||
import type { QTableProps } from "quasar";
|
import type { QTableProps } from "quasar";
|
||||||
|
|
@ -18,6 +19,7 @@ import DialogAddRoleUser from "@/modules/02_users/components/Users/DialogRoleUse
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const roleSuper = ref<boolean>(false);
|
||||||
const { dialogRemove, messageError, showLoader, hideLoader, success } =
|
const { dialogRemove, messageError, showLoader, hideLoader, success } =
|
||||||
useCounterMixin();
|
useCounterMixin();
|
||||||
|
|
||||||
|
|
@ -66,13 +68,11 @@ async function fetchListRoleUser() {
|
||||||
http
|
http
|
||||||
.get(config.API.managementUser + `/role/${userId.value}`)
|
.get(config.API.managementUser + `/role/${userId.value}`)
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
rows.value = await res.data.filter(
|
const item = roleSuper.value
|
||||||
(e: Roles) =>
|
? ["STAFF", "SUPER_ADMIN", "ADMIN", "USER"]
|
||||||
e.name === "STAFF" ||
|
: ["STAFF", "USER"];
|
||||||
e.name === "SUPER_ADMIN" ||
|
|
||||||
e.name === "ADMIN" ||
|
rows.value = await res.data.filter((e: Roles) => item.includes(e.name));
|
||||||
e.name === "USER"
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
messageError($q, err);
|
messageError($q, err);
|
||||||
|
|
@ -118,8 +118,10 @@ function openDialog() {
|
||||||
*
|
*
|
||||||
* โหลดข้อมูลรายการสิทธิ์ที่มี
|
* โหลดข้อมูลรายการสิทธิ์ที่มี
|
||||||
*/
|
*/
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
fetchListRoleUser();
|
const checkToken: any = await tokenParsed();
|
||||||
|
roleSuper.value = await checkToken.role.includes("SUPER_ADMIN");
|
||||||
|
await fetchListRoleUser();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -209,6 +211,7 @@ onMounted(() => {
|
||||||
v-model:modal="modalDialogAdd"
|
v-model:modal="modalDialogAdd"
|
||||||
:userId="userId"
|
:userId="userId"
|
||||||
:roles="rows"
|
:roles="rows"
|
||||||
|
v-model:role-super="roleSuper"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue