-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Knowledge workflow edit permission #4418
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 |
|---|---|---|
|
|
@@ -572,6 +572,21 @@ const workspace = { | |
| ], | ||
| 'OR', | ||
| ), | ||
| workflow_edit: (source_id: string) => | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(source_id)], | ||
| [], | ||
| 'AND', | ||
| ), | ||
| RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, | ||
| PermissionConst.KNOWLEDGE_WORKFLOW_EDIT.getKnowledgeWorkspaceResourcePermission(source_id), | ||
| PermissionConst.KNOWLEDGE_WORKFLOW_EDIT.getWorkspacePermissionWorkspaceManageRole, | ||
| ], | ||
| 'OR', | ||
| ), | ||
| hit_test: () => false, | ||
| } | ||
|
|
||
|
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. The code provided is mostly clean and well-structured. However, there are a few suggestions to improve clarity and maintainability:
Here's an updated version with some comments added: const workspace = {
// Function to check if user has permission to edit the given knowledge workspace
workflow_edit: (source_id: string) => {
return hasPermission(
[
new ComplexPermission(
[RoleConst.USER], // Check if the role is a user
[PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(source_id)],
[], // No additional conditions required
'AND', // All specified permissions must be met
),
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, // Check if the role allows workspace management
PermissionConst.KNOWLEDGE_WORKFLOW_EDIT.getKnowledgeWorkspaceResourcePermission(source_id),
PermissionConst.KNOWLEDGE_WORKFLOW_EDIT.getWorkspacePermissionWorkspaceManageRole,
], // OR condition implies any one of these conditions must be true
'OR'
);
},
// Placeholder for HIT test functionality
hit_test: () => false
};
// Example usage:
console.log(workspace.workflow_edit('example_source_id')); // Use this to determine if the user can edit a specific knowledge spaceSummary of Changes:
These changes should enhance both the quality and maintainability of the codebase. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,10 @@ import applicationApi from '@/api/application/application' | |
| import KnowledgeBase from '@/views/knowledge-workflow/component/action/KnowledgeBase.vue' | ||
| import { WorkflowType } from '@/enums/application' | ||
| import { loadSharedApi } from '@/utils/dynamics-api/shared-api.ts' | ||
| import permissionMap from '@/permission' | ||
| import { MsgError } from '@/utils/message' | ||
| import { t } from '@/locales' | ||
|
|
||
| import { useRoute, useRouter } from 'vue-router' | ||
| provide('upload', (file: any, loading?: Ref<boolean>) => { | ||
| return applicationApi.postUploadFile(file, id, 'KNOWLEDGE', loading) | ||
|
|
@@ -128,8 +132,14 @@ const up = () => { | |
| active.value = 'data_source' | ||
| }) | ||
| } | ||
|
|
||
| const permissionPrecise = computed(() => { | ||
| return permissionMap['knowledge'][apiType.value] | ||
| }) | ||
|
|
||
| const upload = () => { | ||
| ActionRef.value.validate().then(() => { | ||
| if (permissionPrecise.value.doc_create(id)) { | ||
| ActionRef.value.validate().then(() => { | ||
| form_data.value[active.value] = ActionRef.value.get_data() | ||
| loadSharedApi({ type: 'knowledge', systemType: apiType.value }) | ||
| .workflowAction(id, form_data.value, loading) | ||
|
|
@@ -138,6 +148,9 @@ const upload = () => { | |
| active.value = 'result' | ||
| }) | ||
| }) | ||
| } else { | ||
| MsgError(t('views.application.tip.noDocPermission')) | ||
| } | ||
| } | ||
| const continueImporting = () => { | ||
| action_id.value = undefined | ||
|
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. Here are some points to consider and potential improvements:
Here's a revised version of the function incorporating these suggestions: const upload = () => {
const permissionPrecise = computed(() => {
return permissionMap['knowledge'][apiType.value];
});
// Check if document creation privilege exists before validating form
if (permissionPrecise && permissionPrecise.doc_create(id)) {
ActionRef.value.validate().then(() => {
form_data.value[active.value] = ActionRef.value.get_data();
loadSharedApi({ type: 'knowledge', systemType: apiType.value })
.workflowAction(id, form_data.value, loading)
.finally(() => {
active.value = 'result';
});
});
} else {
MsgError(t('views.application.tip.noDocPermission'));
}
};By making these adjustments, you improve code safety, maintainability, and readability. |
||
|
|
||
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 has a few issues and can be optimized:
Issues:
Repeated Methods:
Publishmethod is copied and pasted within the same class with minor modifications. This redundancy can be removed to improve readability and maintainability.Permissions:
Comments vs. Docstrings:
_('Knowledge Base')) should be replaced with regular double quotes ("").Function Annotations:
Optimizations:
Consolidated Permissions:
Removed Redundant Method Copies:
By consolidating permissions and removing redundant method copies, you make the code cleaner, more maintainable, and less prone to errors.