按业务模块拆分附件权限
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<div class="header">
|
||||
<span>{{ headerTitle }}</span>
|
||||
<AttachmentUploader
|
||||
v-if="!readonly"
|
||||
v-if="canCreate"
|
||||
:study-id="studyId"
|
||||
:entity-type="entityType"
|
||||
:entity-id="entityId"
|
||||
@@ -68,9 +68,10 @@ import { formatFileSize } from "./attachmentUtils";
|
||||
import { useAuthStore } from "../../store/auth";
|
||||
import { useStudyStore } from "../../store/study";
|
||||
import { isSystemAdmin } from "../../utils/roles";
|
||||
import { usePermission } from "../../utils/permission";
|
||||
import { listMembers } from "../../api/members";
|
||||
import { displayDateTime, displayUser, getMemberDisplayName, getUserDisplayName } from "../../utils/display";
|
||||
import { getAttachmentPermissionKey } from "../../utils/attachmentPermissions";
|
||||
import { isApiPermissionAllowed } from "../../utils/apiPermissionValue";
|
||||
import { TEXT } from "../../locales";
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -85,7 +86,6 @@ const attachments = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const auth = useAuthStore();
|
||||
const study = useStudyStore();
|
||||
const permission = usePermission();
|
||||
const members = ref<any[]>([]);
|
||||
const previewVisible = ref(false);
|
||||
const previewUrl = ref("");
|
||||
@@ -96,6 +96,20 @@ const previewError = ref("");
|
||||
const previewLoading = ref(false);
|
||||
const headerTitle = computed(() => props.title || TEXT.common.labels.attachments);
|
||||
|
||||
const currentRolePermissions = computed(() => {
|
||||
const role = study.currentStudyRole || (study.currentStudy as any)?.role_in_study;
|
||||
return role ? study.currentPermissions?.[role] : null;
|
||||
});
|
||||
|
||||
const canUseAttachmentPermission = (action: "create" | "read" | "delete") => {
|
||||
if (isSystemAdmin(auth.user)) return true;
|
||||
const operationKey = getAttachmentPermissionKey(props.entityType, action);
|
||||
if (!operationKey) return false;
|
||||
return isApiPermissionAllowed(currentRolePermissions.value?.[operationKey]);
|
||||
};
|
||||
|
||||
const canCreate = computed(() => !props.readonly && canUseAttachmentPermission("create"));
|
||||
|
||||
const load = async () => {
|
||||
if (!props.studyId || !props.entityId) return;
|
||||
loading.value = true;
|
||||
@@ -205,8 +219,7 @@ const preview = (row: any) => {
|
||||
|
||||
const canDelete = (row: any) => {
|
||||
if (props.readonly) return false;
|
||||
const action = props.entityType === "knowledge_note" ? "shared.library.write" : "file.attachment.delete";
|
||||
return isSystemAdmin(auth.user) || permission.can(action);
|
||||
return canUseAttachmentPermission("delete");
|
||||
};
|
||||
|
||||
const remove = async (row: any) => {
|
||||
|
||||
Reference in New Issue
Block a user