-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Resource application permission #3787
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 |
|---|---|---|
|
|
@@ -33,7 +33,16 @@ const ApplicationDetailRouter = { | |
| return PermissionConst.APPLICATION_OVERVIEW_READ.getApplicationWorkspaceResourcePermission( | ||
| to ? to.params.id : '', | ||
| ) | ||
| } | ||
| }, | ||
| () => { | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) {return RoleConst.ADMIN} | ||
| }, | ||
| () => { | ||
| const to: any = get_next_route() | ||
| console.log('ss',to) | ||
| if (to.path.includes('resource-management')) { return PermissionConst.RESOURCE_APPLICATION_OVERVIEW_READ} | ||
| }, | ||
| ] | ||
| }, | ||
| component: () => import('@/views/application-overview/index.vue'), | ||
|
|
@@ -59,7 +68,15 @@ const ApplicationDetailRouter = { | |
| return PermissionConst.APPLICATION_EDIT.getApplicationWorkspaceResourcePermission( | ||
| to ? to.params.id : '', | ||
| ) | ||
| } | ||
| }, | ||
| () => { | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) {return RoleConst.ADMIN} | ||
| }, | ||
| ()=>{ | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) { return PermissionConst.RESOURCE_APPLICATION_EDIT} | ||
| }, | ||
| ] | ||
| }, | ||
| component: () => import('@/views/application/ApplicationSetting.vue'), | ||
|
|
@@ -84,6 +101,14 @@ const ApplicationDetailRouter = { | |
| return PermissionConst.APPLICATION_ACCESS_READ.getApplicationWorkspaceResourcePermission( | ||
| to ? to.params.id : '',) | ||
| }],[EditionConst.IS_EE, EditionConst.IS_PE],'OR'), | ||
| () => { | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) {return RoleConst.ADMIN} | ||
| }, | ||
| ()=>{ | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) { return PermissionConst.RESOURCE_APPLICATION_ACCESS_READ} | ||
| }, | ||
| ] | ||
| }, | ||
| component: () => import('@/views/application/ApplicationAccess.vue'), | ||
|
|
@@ -109,7 +134,15 @@ const ApplicationDetailRouter = { | |
| const to: any = get_next_route() | ||
| return new ComplexPermission([],[PermissionConst.APPLICATION_CHAT_USER_READ.getApplicationWorkspaceResourcePermission( | ||
| to ? to.params.id : '',)],[EditionConst.IS_EE, EditionConst.IS_PE],'OR') | ||
| } | ||
| }, | ||
| () => { | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) {return RoleConst.ADMIN} | ||
| }, | ||
| ()=>{ | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) { return PermissionConst.RESOURCE_APPLICATION_CHAT_USER_READ} | ||
| }, | ||
| ] | ||
| }, | ||
| component: () => import('@/views/chat-user/index.vue'), | ||
|
|
@@ -135,7 +168,15 @@ const ApplicationDetailRouter = { | |
| return PermissionConst.APPLICATION_CHAT_LOG_READ.getApplicationWorkspaceResourcePermission( | ||
| to ? to.params.id : '', | ||
| ) | ||
| } | ||
| }, | ||
| () => { | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) {return RoleConst.ADMIN} | ||
| }, | ||
| ()=>{ | ||
| const to: any = get_next_route() | ||
| if (to.path.includes('resource-management')) { return PermissionConst.RESOURCE_APPLICATION_CHAT_LOG_READ} | ||
| }, | ||
| ] | ||
| }, | ||
| component: () => import('@/views/chat-log/index.vue'), | ||
|
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 is an implementation of Vue Router routes with permission checks on resource-based access. Here's a breakdown of some suggestions and potential improvements:
Here's an improved version incorporating these suggestions: const ApplicationDetailRouter = [
{
path: '/application/:id/overview',
meta: {
permissionCheckers: (to) => {
const hasResourceManagementPath =
// Implement logic here to determine if there is a specific path related to Resource Management
false; // Replace with actual logic
return [
() =>
!hasResourceManagementPath ||
PermissionConst.APPLICATION_OVERVIEW_READ.getApplicationWorkspaceResourcePermission(to?.params.id),
() => (!hasResourceManagementPath || RoleConst.ADMIN),
() =>
!hasResourceManagementPath ||
PermissionConst.RESOURCE_APPLICATION_OVERVIEW_READ,
];
},
},
component: () => import('@/views/application-overview/index.vue'),
},
{
path: '/application/:id/edit',
meta: {
permissionCheckers: (to) => {
const hasResourceManagementPath =
// Implement logic here to determine if there is a specific path related to Resource Management
false;
return [
() => !hasResourceManagementPath ||
PermissionConst.APPLICATION_EDIT.getApplicationWorkspaceResourcePermission(to?.params.id),
() => (!hasResourceManagementPath || RoleConst.ADMIN),
() =>
!hasResourceManagementPath ||
PermissionConst.RESOURCE_APPLICATION_EDIT,
];
},
},
component: () => import('@/views/application/ApplicationSetting.vue'),
},
{
// Rest of the routes remain unchanged but apply the same logic through their respective meta.permissionsChecker
}
];Note: The above suggestion assumes you have a specific way to identify paths associated with "Resource Management." Adjust the logic accordingly based on your application structure. By addressing redundant function calls and consolidating duplicate logic, we can make the code cleaner and potentially enhance performance, given the complexity involved in routing and security checks within applications. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,19 +241,26 @@ | |
| effect="dark" | ||
| :content="$t('views.system.resource_management.management')" | ||
| placement="top" | ||
| v-if="managePermission()" | ||
| > | ||
| <span class="mr-8"> | ||
| <el-button | ||
| type="primary" | ||
| text | ||
| :title="$t('views.system.resource_management.management')" | ||
| @click="goApp(row)" | ||
| @click=" | ||
| router.push({ | ||
| path: `/application/resource-management/${row.id}/${row.type}/overview`, | ||
| }) | ||
| " | ||
| > | ||
| <AppIcon iconName="app-admin-operation"></AppIcon> | ||
| </el-button> | ||
| </span> | ||
| </el-tooltip> | ||
| <el-dropdown trigger="click"> | ||
| <el-dropdown trigger="click" | ||
| v-if="MoreFilledPermission()" | ||
| > | ||
| <el-button text @click.stop> | ||
| <el-icon> | ||
| <MoreFilled /> | ||
|
|
@@ -295,9 +302,6 @@ import { datetimeFormat } from '@/utils/time' | |
| import { loadPermissionApi } from '@/utils/dynamics-api/permission-api.ts' | ||
| import { isWorkFlow } from '@/utils/application.ts' | ||
| import UserApi from '@/api/user/user.ts' | ||
| import { hasPermission } from '@/utils/permission' | ||
| import { ComplexPermission } from '@/utils/permission/type' | ||
| import { EditionConst, PermissionConst, RoleConst } from '@/utils/permission/data' | ||
| import permissionMap from '@/permission' | ||
| import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message' | ||
|
|
||
|
|
@@ -309,6 +313,19 @@ const permissionPrecise = computed(() => { | |
| return permissionMap['application']['systemManage'] | ||
| }) | ||
|
|
||
| const managePermission = () => { | ||
| return permissionPrecise.value.overview_read() || | ||
| permissionPrecise.value.access_read() || | ||
| permissionPrecise.value.edit() || | ||
| permissionPrecise.value.chat_log_read() || | ||
| permissionPrecise.value.chat_user_read() | ||
| } | ||
|
|
||
| const MoreFilledPermission = () => { | ||
| return permissionPrecise.value.export() || | ||
| permissionPrecise.value.delete() | ||
| } | ||
|
|
||
| const apiInputParams = ref([]) | ||
| function toChat(row: any) { | ||
| row?.work_flow?.nodes | ||
|
|
@@ -396,131 +413,6 @@ const paginationConfig = reactive({ | |
| total: 0, | ||
| }) | ||
|
|
||
| const goApp = (item: any) => { | ||
| router.push({ path: get_route(item) }) | ||
| } | ||
|
|
||
| const get_route = (item: any) => { | ||
| if ( | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.APPLICATION.getApplicationWorkspaceResourcePermission(item.id)], | ||
| [], | ||
| 'AND', | ||
| ), | ||
| RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, | ||
| PermissionConst.APPLICATION_OVERVIEW_READ.getWorkspacePermissionWorkspaceManageRole, | ||
| PermissionConst.APPLICATION_OVERVIEW_READ.getApplicationWorkspaceResourcePermission( | ||
| item.id, | ||
| ), | ||
| ], | ||
| 'OR', | ||
| ) | ||
| ) { | ||
| return `/application/resource-management/${item.id}/${item.type}/overview` | ||
| } else if ( | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.APPLICATION.getApplicationWorkspaceResourcePermission(item.id)], | ||
| [], | ||
| 'AND', | ||
| ), | ||
| RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, | ||
| PermissionConst.APPLICATION_EDIT.getWorkspacePermissionWorkspaceManageRole, | ||
| PermissionConst.APPLICATION_EDIT.getApplicationWorkspaceResourcePermission(item.id), | ||
| ], | ||
| 'OR', | ||
| ) | ||
| ) { | ||
| if (item.type == 'WORK_FLOW') { | ||
| return `/application/resource-management/${item.id}/workflow` | ||
| } else { | ||
| return `/application/resource-management/${item.id}/${item.type}/setting` | ||
| } | ||
| } else if ( | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.APPLICATION.getApplicationWorkspaceResourcePermission(item.id)], | ||
| [EditionConst.IS_EE, EditionConst.IS_PE], | ||
| 'AND', | ||
| ), | ||
| new ComplexPermission( | ||
| [RoleConst.WORKSPACE_MANAGE.getWorkspaceRole], | ||
| [PermissionConst.APPLICATION_ACCESS_READ.getWorkspacePermissionWorkspaceManageRole], | ||
| [EditionConst.IS_EE, EditionConst.IS_PE], | ||
| 'OR', | ||
| ), | ||
| new ComplexPermission( | ||
| [], | ||
| [ | ||
| PermissionConst.APPLICATION_ACCESS_READ.getApplicationWorkspaceResourcePermission( | ||
| item.id, | ||
| ), | ||
| ], | ||
| [EditionConst.IS_EE, EditionConst.IS_PE], | ||
| 'OR', | ||
| ), | ||
| ], | ||
| 'OR', | ||
| ) | ||
| ) { | ||
| return `/application/resource-management/${item.id}/${item.type}/access` | ||
| } else if ( | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.APPLICATION.getApplicationWorkspaceResourcePermission(item.id)], | ||
| [EditionConst.IS_EE, EditionConst.IS_PE], | ||
| 'AND', | ||
| ), | ||
| new ComplexPermission( | ||
| [RoleConst.WORKSPACE_MANAGE.getWorkspaceRole], | ||
| [PermissionConst.APPLICATION_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole], | ||
| [EditionConst.IS_EE, EditionConst.IS_PE], | ||
| 'OR', | ||
| ), | ||
| new ComplexPermission( | ||
| [], | ||
| [ | ||
| PermissionConst.APPLICATION_CHAT_USER_READ.getApplicationWorkspaceResourcePermission( | ||
| item.id, | ||
| ), | ||
| ], | ||
| [EditionConst.IS_EE, EditionConst.IS_PE], | ||
| 'OR', | ||
| ), | ||
| ], | ||
| 'OR', | ||
| ) | ||
| ) { | ||
| return `/application/resource-management/${item.id}/${item.type}/chat-user` | ||
| } else if ( | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission( | ||
| [RoleConst.USER], | ||
| [PermissionConst.APPLICATION.getApplicationWorkspaceResourcePermission(item.id)], | ||
| [], | ||
| 'AND', | ||
| ), | ||
| PermissionConst.APPLICATION_CHAT_LOG_READ.getWorkspacePermissionWorkspaceManageRole, | ||
| PermissionConst.APPLICATION_CHAT_LOG_READ.getApplicationWorkspaceResourcePermission( | ||
| item.id, | ||
| ), | ||
| ], | ||
| 'OR', | ||
| ) | ||
| ) { | ||
| return `/application/resource-management/${item.id}/${item.type}/chat-log` | ||
| } else return `/system/resource-management/application/` | ||
| } | ||
|
|
||
| const workspaceOptions = ref<any[]>([]) | ||
| const workspaceVisible = ref(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. In this code snippet, there are several improvements can be made:
|
||
|
|
||
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 snippet is a simplified representation of defining permission management logic within a system interface using Role-based Access Control (RBAC). You've highlighted several potential improvements:
Potential Issues/Improvements:
Code Duplicity: The methods
overview_read,access_read,chat_user_read, andchat_log_readessentially repeat similar logic with only slight variations. This can lead to redundancy and maintenance challenges.Repetition of Role Check: There appears to be repetition in hardcoding roles like
RoleConst.ADMIN. Consider storing these constants elsewhere to prevent duplication and make changes easily if needed.Variable Initialization: Although it's minimal in this case, initializing variables at the top can sometimes clean up the function body and make it more readable.
Method Naming: While descriptive, some method names (
overview_read,access_read) may not clearly convey their functionality. Consider renaming them to better reflect the operations they perform.Function Arguments: Currently, all functions take an array of permissions as their third argument, which could benefit from being documented or made consistent across all implementations.
Return Type Expectation: Ensure that each function returns a boolean indicating whether the user has read access based on the role(s) specified.
Here’s an optimized version of the code with some suggestions applied:
Key Improvements:
hasPermissionsencapsulates the role-checking logic, making it easier to modify the logic for checking multiple conditions in one place.