2023-04-10 09:29:10 +08:00
|
|
|
import { useAuthStore } from '../stores';
|
|
|
|
import { IGroup } from '../models/auth';
|
2021-10-29 07:18:28 +08:00
|
|
|
|
2022-04-01 04:29:09 +08:00
|
|
|
function hasRights(action: string, objectName: string) {
|
2023-04-10 09:29:10 +08:00
|
|
|
const authStore = useAuthStore();
|
2021-10-29 07:18:28 +08:00
|
|
|
|
2023-04-10 09:29:10 +08:00
|
|
|
const groups = authStore.auth?.user?.groups;
|
2022-03-07 04:39:34 +08:00
|
|
|
|
2023-04-10 09:29:10 +08:00
|
|
|
if (!groups || groups?.length == 0) return false;
|
2021-10-29 07:18:28 +08:00
|
|
|
|
2023-04-10 09:29:10 +08:00
|
|
|
const group = groups![0] as IGroup;
|
|
|
|
|
|
|
|
if (group) {
|
|
|
|
if (group.permissions) {
|
|
|
|
return group.permissions?.some(perm => perm.action == action && perm.target == objectName);
|
|
|
|
}
|
|
|
|
return false;
|
2021-10-29 07:18:28 +08:00
|
|
|
}
|
|
|
|
|
2023-04-10 09:29:10 +08:00
|
|
|
return false;
|
2021-10-29 07:18:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default hasRights;
|