中文:收口权限与中心/立项配置改造
This commit is contained in:
@@ -2,6 +2,7 @@ import { computed } from "vue";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { TEXT } from "../locales";
|
||||
import { getProjectRole, isSystemAdmin } from "./roles";
|
||||
|
||||
const PERMISSIONS: Record<string, string[]> = {
|
||||
"subject.create": ["ADMIN", "PM", "CRA"],
|
||||
@@ -37,13 +38,11 @@ export const usePermission = () => {
|
||||
const auth = useAuthStore();
|
||||
const study = useStudyStore();
|
||||
|
||||
const userRole = computed(() => auth.user?.role || null);
|
||||
const projectRole = computed(
|
||||
() => study.currentStudyRole || (study.currentStudy as any)?.role_in_study || auth.user?.role || null
|
||||
);
|
||||
const systemAdmin = computed(() => isSystemAdmin(auth.user));
|
||||
const projectRole = computed(() => getProjectRole(study.currentStudy, study.currentStudyRole));
|
||||
|
||||
const can = (action: string): boolean => {
|
||||
if (userRole.value === "ADMIN") return true;
|
||||
if (systemAdmin.value) return true;
|
||||
const allowList = PERMISSIONS[action];
|
||||
if (!allowList) return false;
|
||||
if (!projectRole.value) return false;
|
||||
@@ -51,7 +50,7 @@ export const usePermission = () => {
|
||||
};
|
||||
|
||||
const reason = (action: string): string => {
|
||||
if (userRole.value === "ADMIN") return "";
|
||||
if (systemAdmin.value) return "";
|
||||
return REASONS[action] || TEXT.modules.permissions.default;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user