-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Knowledge workflow back route permission #4412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,7 +153,7 @@ import { KnowledgeWorkFlowInstance } from '@/workflow/common/validate' | |
| import { hasPermission } from '@/utils/permission' | ||
| import DebugVue from './component/DebugDrawer.vue' | ||
| import { t } from '@/locales' | ||
| import { ComplexPermission } from '@/utils/permission/type' | ||
| import { ComplexPermission, Permission } from '@/utils/permission/type' | ||
| import { EditionConst, PermissionConst, RoleConst } from '@/utils/permission/data' | ||
| import permissionMap from '@/permission' | ||
| import { WorkflowMode } from '@/enums/application' | ||
|
|
@@ -464,21 +464,75 @@ function saveknowledge(bool?: boolean, back?: boolean) { | |
| }) | ||
| } | ||
| const go = () => { | ||
| if (route.path.includes('workspace')) { | ||
| if (route.path.includes('resource-management')) { | ||
| return router.push({ path: get_resource_management_route() }) | ||
| } else if (route.path.includes('shared')) { | ||
| return router.push({ path: get_shared_route() }) | ||
| } else { | ||
| return router.push({ path: get_route() }) | ||
| } | ||
| } | ||
|
|
||
| const get_shared_route = () => { | ||
| if (hasPermission([RoleConst.ADMIN, PermissionConst.SHARED_KNOWLEDGE_DOCUMENT_READ], 'OR')) { | ||
| return `knowledge/${id}/shared/4/document` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.SHARED_KNOWLEDGE_PROBLEM_READ], 'OR')) { | ||
| return `/knowledge/${id}/shared/4/problem` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.SHARED_KNOWLEDGE_HIT_TEST_READ], 'OR')) { | ||
| return `/knowledge/${id}/shared/4/hit-test` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.SHARED_KNOWLEDGE_CHAT_USER_READ], 'OR')) { | ||
| return `/knowledge/${id}/shared/4/chat-user` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.SHARED_KNOWLEDGE_EDIT], 'OR')) { | ||
| return `/knowledge/${id}/shared/4/setting` | ||
| } else { | ||
| return router.push({ path: get_resource_management_route() }) | ||
| return `/system/shared/knowledge` | ||
| } | ||
| } | ||
|
|
||
| const get_resource_management_route = () => { | ||
| return `/knowledge/${id}/${folderId}/4/document` | ||
|
|
||
| // return `/system/resource-management/knowledge` 没有权限的时候返回resource-management的列表 | ||
| if (hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_DOCUMENT_READ],'OR')) { | ||
| return `/knowledge/${id}/resource-management/4/document` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_PROBLEM_READ], 'OR')) { | ||
| return `/knowledge/${id}/resource-management/4/problem` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_HIT_TEST], 'OR')) { | ||
| return `/knowledge/${id}/resource-management/4/hit-test` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_CHAT_USER_READ], 'OR')) { | ||
| return `/knowledge/${id}/resource-management/4/chat-user` | ||
| } else if (hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_EDIT], 'OR')) { | ||
| return `/knowledge/${id}/resource-management/4/setting` | ||
| } else { | ||
| return `/system/resource-management/knowledge` | ||
| } | ||
| } | ||
|
|
||
| const get_route = () => { | ||
| return `/knowledge/${id}/${folderId}/4/document` | ||
| const checkPermission = (permissionConst: Permission) => { | ||
| return hasPermission([ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(id)], | ||
| [], | ||
| 'AND' | ||
| ), | ||
| RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, | ||
| permissionConst.getWorkspacePermissionWorkspaceManageRole, | ||
| permissionConst.getKnowledgeWorkspaceResourcePermission(id), | ||
| ],'OR' | ||
| ) | ||
| } | ||
| if (checkPermission(PermissionConst.KNOWLEDGE_DOCUMENT_READ)) { | ||
| return `/knowledge/${id}/${folderId}/4/document` | ||
| } else if (checkPermission(PermissionConst.KNOWLEDGE_PROBLEM_READ)) { | ||
| return `/knowledge/${id}/${folderId}/4/problem` | ||
| } else if (checkPermission(PermissionConst.KNOWLEDGE_HIT_TEST_READ)) { | ||
| return `/knowledge/${id}/${folderId}/4/hit-test` | ||
| } else if (checkPermission(PermissionConst.KNOWLEDGE_CHAT_USER_READ)) { | ||
| return `/knowledge/${id}/${folderId}/4/chat-user` | ||
| } else if (checkPermission(PermissionConst.KNOWLEDGE_EDIT)) { | ||
| return `/knowledge/${id}/${folderId}/4/setting` | ||
| } else { | ||
| return `/knowledge` | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your code has several issues that need to be addressed:
Here's an improved version of your code with suggestions for addressing these issues: import { ComplexPermission, Permission } from '@/utils/permission/type';
import { KnowledgeWorkFlowInstance } from '@/workflow/common/validate';
import { hasPermission } from '@/utils/permission';
const DebugVue = './component/DebugDrawer.vue';
import { t } from '@/locales';
import { EditionConst, PermissionConst, RoleConst } from '@/utils/permission/data';
import permissionMap from '@/permission';
import { WorkflowMode } from '@/enums/application';
function saveknowledge(bool?: boolean, back?: boolean) {
// Implementation here
}
const go = () => {
if (route.path.includes('resource-management') || route.path.includes('shared')) {
return router.push(get_route());
} else {
return router.push('/knowledge');
}
};
const get_route = () => {
const checkPermission = (permissionConst: Permission) => {
return hasPermission([
new ComplexPermission([RoleConst.USER], [permissionConst.getWorkspacePermission(workspaceId)], [], 'AND'),
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
workspaceId && permissionConst.getWorkspacePermission(workspaceId).includes(RoleConst.WORKSPACE_MANAGE),
permissionConst.getKnowledgeWorkspaceResourcePermission(workspaceId),
], 'OR',
);
};
const knowledgePermissions = [
PermissionConst.KNOWLEDGE_DOCUMENT_READ,
PermissionConst.KNOWLEDGE_PROBLEM_READ,
PermissionConst.KNOWLEDGE_HIT_TEST_READ,
PermissionConst.KNOWLEDGE_CHAT_USER_READ,
PermissionConst.KNOWLEDGE_EDIT,
];
for (let perm of knowledgePermissions) {
if (checkPermission(perm)) {
return `/knowledge/${workspaceId}/document`;
}
}
return `/knowledge`;
};Key Changes Made:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippet appears to be an enumeration of permission constants with different roles and access levels for users. Here are some potential issues and optimizations:
Potential Duplicate: The
RESOURCE_KNOWLEDGE_WORKFLOW_EDITconstant has both aREADand anEDIToperation on the same set of parents, which might not be intended if only one action (e.g., editing) should override reading.Role List Consistency: The
parent_groupfield referencesResource.Knowledge, but theRESOURCE_KNOWLEDGE_WORKFLOW_EDITis associated withSYSTEM_RES_KNOWLEDGE_WORKFLOW. This inconsistency could potentially lead to unexpected behavior in certain applications that rely on this information.Code Readability and Maintainability: Having duplicate entries like
RESOURCE_KNOWLEDGE_WORKFLOW_EDITcan make the code harder to understand and maintain. Consider removing unnecessary duplicates or using more descriptive names where applicable.Here's a slightly optimized version with these considerations addressed:
In this updated version:
RESOURCE_KNOWLEDGE_WRITEconstant is renamed toRESOURCE_KNOWLEDGE_MANAGEto reflect its broader scope rather than being limited to just read operations.operateattribute is changed toOperate.ALLto allow all specified roles ([RoleConstants.ADMIN]) to perform edit actions without needing separate READ permissions.These changes enhance readability, maintainability, and the clarity of the permission structure.