-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Resource tool permission #3765
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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import {hasPermission} from '@/utils/permission/index' | ||
| import {ComplexPermission} from '@/utils/permission/type' | ||
| import {EditionConst, PermissionConst, RoleConst} from '@/utils/permission/data' | ||
|
|
||
| const systemManage = { | ||
| create: () => false, | ||
| folderCreate: () => false, | ||
| edit: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_EDIT | ||
| ], | ||
| 'OR' | ||
| ), | ||
| folderEdit: () => false, | ||
| export: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_EXPORT | ||
| ], | ||
| 'OR' | ||
| ), | ||
| delete: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_DELETE | ||
| ], | ||
| 'OR' | ||
| ), | ||
| folderDelete: () => false, | ||
| overview_embed: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_OVERVIEW_EMBED | ||
| ], | ||
| 'OR' | ||
| ), | ||
| overview_access: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_OVERVIEW_ACCESS | ||
| ], | ||
| 'OR' | ||
| ), | ||
| overview_display: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_OVERVIEW_DISPLAY | ||
| ], | ||
| 'OR' | ||
| ), | ||
| overview_api_key: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_OVERVIEW_API_KEY | ||
| ], | ||
| 'OR' | ||
| ), | ||
| access_edit: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_ACCESS_EDIT | ||
| ], | ||
| 'OR' | ||
| ), | ||
| application_chat_user_edit: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_CHAT_USER_EDIT | ||
| ], | ||
| 'OR' | ||
| ), | ||
| chat_log_clear: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_CHAT_LOG_CLEAR_POLICY | ||
| ], | ||
| 'OR' | ||
| ), | ||
| chat_log_export: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_CHAT_LOG_EXPORT | ||
| ], | ||
| 'OR' | ||
| ), | ||
| chat_log_add_knowledge: () => | ||
| hasPermission( | ||
| [ | ||
| RoleConst.ADMIN, | ||
| PermissionConst.RESOURCE_APPLICATION_CHAT_LOG_ADD_KNOWLEDGE | ||
| ], | ||
| 'OR' | ||
| ), | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,7 +227,9 @@ | |
| </el-button> | ||
| </span> | ||
| </el-tooltip> | ||
| <el-dropdown trigger="click"> | ||
| <el-dropdown trigger="click" | ||
| v-if="MoreFilledPermission(row)" | ||
| > | ||
| <el-button text @click.stop> | ||
| <el-icon> | ||
| <MoreFilled /> | ||
|
|
@@ -314,6 +316,12 @@ const permissionPrecise = computed(() => { | |
| return permissionMap['tool']['systemManage'] | ||
| }) | ||
|
|
||
| const MoreFilledPermission = (row: any) => { | ||
| return permissionPrecise.value.export() || | ||
| permissionPrecise.value.delete() || | ||
| (row.init_field_list?.length > 0 && permissionPrecise.value.edit()) | ||
| } | ||
|
|
||
| function exportTool(row: any) { | ||
| ToolResourceApi.exportTool(row.id, row.name, loading).catch((e: any) => { | ||
| if (e.response.status !== 403) { | ||
|
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 seems mostly aligned with good practices. Here are some minor suggestions and improvements:
Here's a slightly improved version with these considerations: // Import statements should be at the top
import { ref, computed } from 'vue';
import { ElTooltip, MoreFilled, ToolResourceApi } from '@/plugins'; // Adjust module paths accordingly
export default {
components: {
ElTooltip,
MoreFilled,
},
setup() {
const moreFilledPermission = (row) => permissionPrecise.value.export() ||
permissionPrecise.value.delete() ||
(row.initFieldList.length > 0 && permissionPrecise.value.edit());
const exportTool = async (row) => {
try {
await ToolResourceApi.exportTool(row.id, row.name);
} catch (e) {
if (e.response.status !== 403) {
console.error('Error exporting tool:', e.message);
}
} finally {
// Clear loading state if needed
loading.value = false;
}
};
return {
exportTool,
MoreFilledPermission,
};
},
};Key Changes:
These changes make the code cleaner, more readable, and maintainable. |
||
|
|
||
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 defines permission functions for various operations related to system management. It utilizes a utility function
hasPermissionthat checks if a user has any of the specified permissions based on an OR condition. However, there are a few areas where improvements can be made:Duplicate Methods: There are duplicate methods named
folderCreate,folderEdit,delete,folderDelete, etc., with almost identical implementation. Instead, these could be consolidated into one generic method that accepts different action types.Consistent Return Values: The return values should be consistent across all actions. If all permissions allow access, returning
truemakes more sense than not returning anything (which is ambiguous).Comments: Adding comments to describe what each method does would improve readability and maintainability.
Here's a revised version with optimizations:
Key Changes:
handleOperation): This function allows setting up common logic for handling permissions based on operation type.