-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Permission of chat_user #3929
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 |
|---|---|---|
|
|
@@ -150,6 +150,8 @@ const systemManage = { | |
| PermissionConst.RESOURCE_KNOWLEDGE_PROBLEM_EDIT | ||
| ],'OR' | ||
| ), | ||
| chat_user_edit: () =>false, | ||
|
|
||
|
|
||
| auth: () => false, | ||
| folderCreate: () => 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 provided code snippet contains a few potential issues that need to be addressed: Potential Issues
Optimization Suggestions
Updated CodeHere’s an improved version of the code with some suggestions incorporated: const systemManage = {
permission_check: () => {
// Add your permission checking logic here
return [PermissionConst.RESOURCE_A, PermissionConst.RESOURCE_B];
},
group_role: role_id => {
const user_roles = ['admin', 'editor'];
// Check roles against user_roles list
if (!user_roles.includes(role_id)) {
return [];
}
switch (role_id) {
case 'admin':
return [
PermissionConst.AND(PermissionConst.RESOURCE_USER_LIST),
PermissionConst.OR(
PermissionConst.RESOURCE_A,
PermissionConst.RESOURCE_B
)
];
default:
return [
PermissionConst.AND(),
PermissionConst.NOT(PermissionConst.ALL())
];
}
},
chat_user_edit: () => false,
auth: () => false,
folder_create: () => false,
};Explanation of Improvements
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,6 +272,16 @@ const workspace = { | |
| ], | ||
| 'OR', | ||
| ), | ||
| chat_user_edit: (source_id:string) => | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission([RoleConst.USER],[PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(source_id)],[],'AND'), | ||
| RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, | ||
| PermissionConst.KNOWLEDGE_CHAT_USER_EDIT.getKnowledgeWorkspaceResourcePermission(source_id), | ||
| PermissionConst.KNOWLEDGE_CHAT_USER_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 provided code for handling permissions in a React component appears to be correctly structured. However, there are a few minor improvements that can be made for clarity and maintainability:
Here's an updated version with these considerations: const workspace = {
// ... other functions ...
chat_user_edit(workspaceId: string): boolean {
return hasPermission([
new ComplexPermission([RoleConst.USER], [PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(workspaceId)], [], 'AND'),
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole(),
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT.getKnowledgeWorkspaceResourcePermission(workspaceId),
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT.getWorkspacePermissionWorkspaceManageRole()
], 'OR');
},
hit_test(): boolean {
return false;
},
};Explanation:
These changes should enhance both the readibility and maintainability of the code. |
||
|
|
||
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 incomplete and contains a few issues:
Syntax Error: The second line of the code should be indented more to form part of the
PermissionConstobject.Inconsistent Use of Commas: There's an extra comma after
'OR'.Function Definition within Object: It seems there might be a function definition outside the context of the permission management object structure, which could cause confusion.
Here’s how you can correct these issues:
Optimization Suggestions:
chat_user_read, consider creating a helper function or using template literals for cleaner readability.hasPermissionfunction is defined elsewhere in your application, as it is called but not shown in this snippet.Replace
'your-permission-package'with the actual package name wherePermissionConstis defined. This will help ensure all referenced constants and functions are available and correctly used.