-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: Resource knowledge permission #3778
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 |
---|---|---|
|
@@ -61,7 +61,15 @@ const DocumentRouter = { | |
const to: any = get_next_route() | ||
if(to.params.folderId == 'share') { | ||
return RoleConst.USER.getWorkspaceRole() } | ||
} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return RoleConst.ADMIN} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return PermissionConst.RESOURCE_KNOWLEDGE_DOCUMENT_READ} | ||
}, | ||
], | ||
}, | ||
component: () => import('@/views/document/index.vue'), | ||
|
@@ -108,7 +116,15 @@ const DocumentRouter = { | |
const to: any = get_next_route() | ||
if(to.params.folderId == 'share') { | ||
return RoleConst.USER.getWorkspaceRole() } | ||
} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return RoleConst.ADMIN} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return PermissionConst.RESOURCE_KNOWLEDGE_PROBLEM_READ} | ||
}, | ||
], | ||
}, | ||
component: () => import('@/views/problem/index.vue'), | ||
|
@@ -154,7 +170,15 @@ const DocumentRouter = { | |
const to: any = get_next_route() | ||
if(to.params.folderId == 'share') { | ||
return RoleConst.USER.getWorkspaceRole() } | ||
} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return RoleConst.ADMIN} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return PermissionConst.RESOURCE_KNOWLEDGE_HIT_TEST} | ||
}, | ||
], | ||
}, | ||
component: () => import('@/views/hit-test/index.vue'), | ||
|
@@ -211,7 +235,15 @@ const DocumentRouter = { | |
const to: any = get_next_route() | ||
if(to.params.folderId == 'share') { | ||
return RoleConst.USER.getWorkspaceRole() } | ||
} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return RoleConst.ADMIN} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return PermissionConst.RESOURCE_KNOWLEDGE_CHAT_USER_READ} | ||
}, | ||
] | ||
}, | ||
component: () => import('@/views/chat-user/index.vue'), | ||
|
@@ -258,7 +290,15 @@ const DocumentRouter = { | |
const to: any = get_next_route() | ||
if(to.params.folderId == 'share') { | ||
return RoleConst.USER.getWorkspaceRole() } | ||
} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return RoleConst.ADMIN} | ||
}, | ||
()=>{ | ||
const to: any = get_next_route() | ||
if (to.params.folderId == 'resource-management') { return PermissionConst.RESOURCE_KNOWLEDGE_EDIT} | ||
}, | ||
], | ||
}, | ||
component: () => import('@/views/knowledge/KnowledgeSetting.vue'), | ||
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. The code looks mostly correct but has repetitive logic for handling different function getRoleBasedOnFolder(folderId) {
switch (folderId) {
case 'share':
return RoleConst.USER.getWorkspaceRole();
case 'resource-management':
return [
RoleConst.ADMIN,
PermissionConst.RESOURCE_KNOWLEDGE_DOCUMENT_READ,
// Add more permissions as needed
];
default:
return null; // Return appropriate value for other cases
}
} Then you can use this function within the respective route definitions: const DocumentRouter = {
routes: [
{
path: '/document',
redirect: to => ({ ...to, query: { type: 'knowledge-document' } }),
children: [
{
name: 'DocumentIndex',
path: '',
meta: {
requiresAuth: true
},
component: () => import('@/views/document/index.vue'),
beforeEnter: (to, from, next) => {
if (getRoleBasedOnFolder(to.query.type)[0] === RoleConst.ANONYMOUS) {
router.push('/');
} else {
next();
}
}
},
// Repeat similar structures for ProblemRoute and HitTestRoute
]
},
// Other routes ...
],
}; This approach ensures consistency and reduces redundancy in the code. If there are specific requirements for certain roles or permissions not handled here, additional conditions should be added inside the |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,9 @@ | |
:content="$t('views.system.resource_management.management')" | ||
placement="top" | ||
> | ||
<span class="mr-8"> | ||
<span class="mr-8" | ||
v-if="ManagePermission()" | ||
> | ||
<el-button | ||
type="primary" | ||
text | ||
|
@@ -178,7 +180,9 @@ | |
</el-button> | ||
</span> | ||
</el-tooltip> | ||
<el-dropdown trigger="click"> | ||
<el-dropdown trigger="click" | ||
v-if="MoreFilledPermission()" | ||
> | ||
<el-button text @click.stop> | ||
<el-icon> | ||
<MoreFilled /> | ||
|
@@ -264,6 +268,23 @@ const permissionPrecise = computed(() => { | |
return permissionMap['knowledge']['systemManage'] | ||
}) | ||
|
||
const ManagePermission = () => { | ||
return permissionPrecise.value.doc_read() || | ||
permissionPrecise.value.problem_read() || | ||
permissionPrecise.value.edit() || | ||
permissionPrecise.value.knowledge_chat_user_read() || | ||
permissionPrecise.value.hit_test() | ||
} | ||
// sync generete edit export delete | ||
const MoreFilledPermission = () => { | ||
return permissionPrecise.value.sync() || | ||
permissionPrecise.value.generate() || | ||
permissionPrecise.value.edit() || | ||
permissionPrecise.value.export() || | ||
permissionPrecise.value.delete() | ||
} | ||
|
||
|
||
const search_type = ref('name') | ||
const search_form = ref<any>({ | ||
name: '', | ||
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. The provided code snippet seems mostly clean, but there are some minor improvements that can be made:
Here's the revised version with these suggestions: --- a/views/system/resource_management/components/common/management.vue
+++ b/views/system/resource_management/components/common/management.vue
@@ -146,7 +146,9 @@
:content="$t('views.system.resource_management.management')"
placement="top"
>
- <span class="mr-8">
+ <span class="mr-8" v-if="canManage()">{{ // Button will only appear if user has manage permission }}
<el-button
type="primary"
text
@@ -178,7 +180,9 @@
</button>
</span>
</el-tooltip>
- <el-dropdown trigger="click">
+ <el-dropdown trigger="click" v-if="canMoreFilled()">
<el-button text @click.stop>
<el-icon>
<MoreFilled />
@@ -264,6 +268,27 @@ const permissionPrecise = computed(() => {
return permissionMap['knowledge']['systemManage']
})
+/**
+ * Determines if the current user has the 'manage' permission.
+ */
+const canManage = () => {
+ return (
+ permissionPrecise.value.doc_read ||
+ permissionPrecise.value.problem_read ||
+ permissionPrecise.value.edit ||
+ permissionPrecise.value.knowledge_chat_user_read ||
+ permissionPrecise.value.hit_test
+ );
+}
+
+/**
+ * Determines if the current user has any of the 'more filled' permissions.
+ */
+const canMoreFilled = () => {
+ return (
+ permissionPrecise.value.sync ||
+ permissionPrecise.value.generate ||
+ permissionPrecise.value.edit ||
+ permissionPrecise.value.export ||
+ permissionPrecise.value.delete
+ );
+}
const search_type = ref('name');
const search_form = ref({ These changes make the code easier to read and understand while maintaining its functionality. The added comments provide context for each function, enhancing maintainability. |
||
|
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 code you provided appears to be an API function that checks user permissions for various actions related to knowledge management and problems. However, there are several areas where the code can be improved:
Function Naming: The naming convention for functions like
doc_read
could benefit from being more consistent with other similar functions.Code Organization: While not a major issue, the order of conditions within each permission check might not always make sense, especially if the roles or permissions change frequently.
Documentation: It would be helpful to add comments describing what each part of the code does, particularly around complex logic (like the use of
'OR'
).Default Values and Edge Cases: Ensure that default values are properly handled, especially in cases where certain operations don't require explicit permissions.
Here's an optimized version of the code with some suggested improvements:
Explanation of Changes:
knowledge_chat_user_read
,problem_read
, etc., to match the pattern used in other functions.While this is still quite compact, it provides a clear structure for managing permissions in your application.