-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Knowledge workflow permission #4434
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 |
|---|---|---|
|
|
@@ -44,8 +44,8 @@ class KnowledgeWorkflowVersionView(APIView): | |
| responses=KnowledgeVersionListAPI.get_response(), | ||
| tags=[_('Knowledge/Version')] # type: ignore | ||
| ) | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_READ.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_READ.get_workspace_permission_workspace_manage_role(), | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_WORKFLOW_READ.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_WORKFLOW_READ.get_workspace_permission_workspace_manage_role(), | ||
| ViewPermission([RoleConstants.USER.get_workspace_role()], | ||
| [PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()], | ||
| CompareConstants.AND), | ||
|
|
@@ -68,8 +68,8 @@ class Page(APIView): | |
| responses=KnowledgeVersionPageAPI.get_response(), | ||
| tags=[_('Knowledge/Version')] # type: ignore | ||
| ) | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_READ.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_READ.get_workspace_permission_workspace_manage_role(), | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_WORKFLOW_READ.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_WORKFLOW_READ.get_workspace_permission_workspace_manage_role(), | ||
| ViewPermission([RoleConstants.USER.get_workspace_role()], | ||
| [PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()], | ||
| CompareConstants.AND), | ||
|
|
@@ -93,8 +93,8 @@ class Operate(APIView): | |
| responses=KnowledgeVersionOperateAPI.get_response(), | ||
| tags=[_('Knowledge/Version')] # type: ignore | ||
| ) | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_EDIT.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_EDIT.get_workspace_permission_workspace_manage_role(), | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_WORKFLOW_READ.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_WORKFLOW_READ.get_workspace_permission_workspace_manage_role(), | ||
| ViewPermission([RoleConstants.USER.get_workspace_role()], | ||
| [PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()], | ||
| CompareConstants.AND), | ||
|
|
@@ -115,8 +115,8 @@ def get(self, request: Request, workspace_id: str, knowledge_id: str, knowledge_ | |
| responses=KnowledgeVersionOperateAPI.get_response(), | ||
| tags=[_('Knowledge/Version')] # type: ignore | ||
| ) | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_EDIT.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_EDIT.get_workspace_permission_workspace_manage_role(), | ||
| @has_permissions(PermissionConstants.KNOWLEDGE_WORKFLOW_EDIT.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_WORKFLOW_EDIT.get_workspace_permission_workspace_manage_role(), | ||
| ViewPermission([RoleConstants.USER.get_workspace_role()], | ||
| [PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()], | ||
| CompareConstants.AND), | ||
|
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. There do not appear to be obvious issues or opportunities for optimization in this code snippet related to permissions handling. Each view is correctly decorated with However, there are some areas where you might want additional validation or clarification:
Overall, the code looks functionally correct assuming it aligns well with the broader application's security policies regarding permission management. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,10 @@ | |
| </el-button> | ||
| <template #dropdown> | ||
| <el-dropdown-menu> | ||
| <el-dropdown-item @click.stop="openEditVersion(row)"> | ||
| <el-dropdown-item | ||
| v-if="permissionPrecise.workflow_edit(id)" | ||
| @click.stop="openEditVersion(row)" | ||
| > | ||
| <AppIcon iconName="app-edit" class="color-secondary"></AppIcon> | ||
| {{ $t('common.edit') }} | ||
| </el-dropdown-item> | ||
|
|
@@ -75,9 +78,11 @@ import { datetimeFormat } from '@/utils/time' | |
| import { MsgSuccess, MsgError } from '@/utils/message' | ||
| import { t } from '@/locales' | ||
| import { loadSharedApi } from '@/utils/dynamics-api/shared-api' | ||
| import permissionMap from '@/permission' | ||
|
|
||
| const route = useRoute() | ||
| const { | ||
| params: { id }, | ||
| params: { id, folderId }, | ||
| } = route as any | ||
| const apiType = computed(() => { | ||
| if (route.path.includes('shared')) { | ||
|
|
@@ -89,6 +94,10 @@ const apiType = computed(() => { | |
| } | ||
| }) | ||
|
|
||
| const permissionPrecise = computed(() => { | ||
| return permissionMap['knowledge'][apiType.value] | ||
| }) | ||
|
|
||
| const emit = defineEmits(['click', 'refreshVersion']) | ||
| const loading = ref(false) | ||
| const LogData = ref<any[]>([]) | ||
|
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. This code is generally well-written and follows standard practices. However, there are a few minor adjustments and optimizations you might consider:
Here’s how you can revise the code with these considerations: // Import necessary components and dependencies at the top
const route = useRoute()
const {
params: { id, folderId },
} = route as { params: { id?: string; folderId?: string } };
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'shared';
}
});
const permissionMap = {
knowledge: new Map([
['published', () => true], // Example map value
['draft', () => false],
// Add other rules as needed
]),
};
const permissionPrecise = computed(() => {
return permissionMap[knowledge][apiType.value];
});
const emit = defineEmits(['click', 'refreshVersion']);
const loading = ref(false);
const LogData = ref<any[]>([]);Key Adjustments:
These changes improve clarity, maintainability, and reduce potential pitfalls such as runtime errors due to incorrect type assumptions. |
||
|
|
||
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 snippet you provided is primarily a series of views defined in an API using Django Rest Framework (DRF). I've made a brief analysis to identify any irregularities, issues, or optimizations:
Issues
Duplicated
authentication_classes: Each view has the sameauthentication_classes, which can be redundant unless there's specific context where each view should have different authentication strategies.Unused Import Statements:
These imports might not actually be used in this section if they're intended for other parts of the project. They could be removed without affecting functionality.
Lack of Type Hinting on Return Types:
While Python supports type hinting through PEP 484 and later versions, these details are not shown here. It's advisable to add explicit typing if available.
Potential Duplicates:
The last
@has_permissionsdecorator call seems identical to one further up, possibly indicating a copy-paste error when copying permissions across methods.Suggestions
Consistent Authentication Classes:
If all views need similar types of authentication, consider centralizing these at either the application level (in settings) or using middleware.
Remove Unused Imports:
Review the entire file for unused imports and remove them to keep it clean and efficient.
Type Hints:
If you have access to type hints, add them for better readability and maintainability.
Review Permissions Across Methods:
Ensure that permission logic is consistent within each method, especially when handling similar functionalities.
Here's a simplified version with some suggested improvements:
This example removes unnecessary imports, standardizes authentication classes, adds basic comments, and includes simple response structures for demonstration purposes.