Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/src/permission/application/system-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ const systemManage = {
PermissionConst.RESOURCE_APPLICATION_CHAT_USER_READ
],'OR'
),
chat_user_edit: () =>false,

chat_log_read: () =>
hasPermission(
[
Copy link
Contributor Author

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:

  1. Syntax Error: The second line of the code should be indented more to form part of the PermissionConst object.

  2. Inconsistent Use of Commas: There's an extra comma after 'OR'.

  3. 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:

const { PermissionConst } = require('your-permission-package'); // Assuming this exists

const systemManage = {
  chat_user_read: () =>
    hasPermission([
      PermissionConst.RESOURCE_APPLICATION_CHAT_USER_READ,
      'other_permission_key'
    ]),
  chat_user_edit: () => false,
  chat_log_read: () =>
    hasPermission([
      // List other required permissions here
    ]),
};

Optimization Suggestions:

  • If there are multiple similar functions like chat_user_read, consider creating a helper function or using template literals for cleaner readability.
  • Ensure that hasPermission function 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 where PermissionConst is defined. This will help ensure all referenced constants and functions are available and correctly used.

Expand Down
2 changes: 2 additions & 0 deletions ui/src/permission/knowledge/system-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ const systemManage = {
PermissionConst.RESOURCE_KNOWLEDGE_PROBLEM_EDIT
],'OR'
),
chat_user_edit: () =>false,


auth: () => false,
folderCreate: () => false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

  1. Incorrect Use of PermissionConst:

    • The function signatures for groupRole are incorrect. They should return either an array or a boolean value based on the permission logic.
  2. Function Definition with No Return Statement:

    • The functions chat_user_edit, folder_create, and auth do not have explicit return statements. This might lead to unexpected behavior if they need to handle more complex conditions.
  3. Code Formatting and Readability:

    • Consistent use of spaces around operators and indentation makes the code easier to read. However, it's already well-formatted in this case.
  4. Potential Missing Error Handling:

    • Since none of these functions return error values, there is no mechanism to handle errors or invalid inputs properly. It might be worth adding checks where necessary.

Optimization Suggestions

  1. Inline Condition for permission.user.edit (if applicable):
    • If PermissionConst.USER_EDIT exists and has a simple condition, you can inline it within the function without defining another separate function.

Updated Code

Here’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

  • Inline Function Logic: Removed unnecessary function definitions for user_role.
  • Error Handling: Added comments indicating where additional error handling could be implemented.
  • Consistency: Ensured consistent function syntax across all permissions and non-permission related functions.
  • Logical Flow: Simplified some expressions and added appropriate comments for clarity about their purpose.

Expand Down
2 changes: 2 additions & 0 deletions ui/src/permission/knowledge/system-share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ const share = {
],
'OR'
),
chat_user_edit: () =>false,

auth: () => false,
folderCreate: () => false,
folderEdit: () => false,
Expand Down
1 change: 1 addition & 0 deletions ui/src/permission/knowledge/workspace-share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const workspaceShare = {
problem_relate: () => false,
problem_delete: () => false,
problem_edit: () => false,
chat_user_edit: () =>false,

folderCreate: () => false,
folderEdit: () => false,
Expand Down
10 changes: 10 additions & 0 deletions ui/src/permission/knowledge/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

  1. Function Name Consistency: The function chat_user_edit might benefit from using more descriptive names if additional functionality could evolve.

  2. Inline Comments: Adding comments to each line of the function would help clarify its purpose and logic.

  3. Variable Renaming: Consider renaming the parameter source_id to something more specific, such as workspaceId, to improve readability.

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:

  • Function Naming: Changed chat_user_edit to chatUserEdit to make it more descriptive and easier to understand at first glance.
  • Comments: Added inline comments to explain the purpose of each part of the permission check.
  • Renamed Parameter: Chained .getWorkspaceRole() before calling new ComplexPermission() to ensure the role is properly instantiated without needing parentheses inside the array.

These changes should enhance both the readibility and maintainability of the code.

Expand Down
149 changes: 40 additions & 109 deletions ui/src/views/chat-user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@
<div class="user-left border-r">
<div class="p-24 pb-0">
<h4 class="medium mb-12">{{ $t('views.chatUser.group.title') }}</h4>
<el-input
v-model="filterText"
:placeholder="$t('common.search')"
prefix-icon="Search"
clearable
/>
<el-input v-model="filterText" :placeholder="$t('common.search')" prefix-icon="Search" clearable />
</div>
<div class="list-height-left">
<el-scrollbar v-loading="loading">
<div class="p-16">
<common-list
:data="filterList"
@click="clickUserGroup"
:default-active="current?.id"
>
<common-list :data="filterList" @click="clickUserGroup" :default-active="current?.id">
<template #default="{ row }">
<span class="ellipsis-1" :title="row.name">{{ row.name }}</span>
</template>
Expand Down Expand Up @@ -57,58 +48,30 @@
</span>
</div>

<div
class="flex align-center"
v-if="
route.path.includes('share/')
? false
: hasPermission(permissionObj[currentPermissionKey], 'OR')
"
>
<div class="flex align-center" v-if="
route.path.includes('share/')
? false
: permissionObj[currentPermissionKey]
">
<div class="color-secondary mr-8">{{ $t('views.chatUser.autoAuthorization') }}</div>
<el-switch
size="small"
:model-value="current?.is_auth"
@click="changeAuth"
:loading="loading"
></el-switch>
<el-switch size="small" :model-value="current?.is_auth" @click="changeAuth"
:loading="loading"></el-switch>
</div>
</div>

<div class="flex-between mb-16" style="margin-top: 18px">
<div class="flex complex-search">
<el-select class="complex-search__left" v-model="searchType" style="width: 120px">
<el-option :label="$t('views.login.loginForm.username.label')" value="username" />
<el-option
:label="$t('views.userManage.userForm.nick_name.label')"
value="nick_name"
/>
<el-option :label="$t('views.userManage.userForm.nick_name.label')" value="nick_name" />
<el-option :label="$t('views.userManage.source.label')" value="source" />
</el-select>
<el-input
v-if="searchType === 'username'"
v-model="searchForm.username"
@change="getList"
:placeholder="$t('common.inputPlaceholder')"
style="width: 220px"
clearable
/>
<el-input
v-else-if="searchType === 'nick_name'"
v-model="searchForm.nick_name"
@change="getList"
:placeholder="$t('common.inputPlaceholder')"
style="width: 220px"
clearable
/>
<el-select
v-else-if="searchType === 'source'"
v-model="searchForm.source"
@change="getList"
:placeholder="$t('common.selectPlaceholder')"
style="width: 220px"
clearable
>
<el-input v-if="searchType === 'username'" v-model="searchForm.username" @change="getList"
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
<el-input v-else-if="searchType === 'nick_name'" v-model="searchForm.nick_name" @change="getList"
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
<el-select v-else-if="searchType === 'source'" v-model="searchForm.source" @change="getList"
:placeholder="$t('common.selectPlaceholder')" style="width: 220px" clearable>
<el-option :label="$t('views.userManage.source.local')" value="LOCAL" />
<el-option label="CAS" value="CAS" />
<el-option label="LDAP" value="LDAP" />
Expand All @@ -119,31 +82,18 @@
<el-option :label="$t('views.userManage.source.dingtalk')" value="dingtalk" />
</el-select>
</div>
<el-button
type="primary"
:disabled="current?.is_auth"
@click="handleSave"
v-if="
route.path.includes('share/')
? false
: hasPermission(permissionObj[currentPermissionKey], 'OR')
"
>
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave" v-if="
route.path.includes('share/')
? false
: permissionObj[currentPermissionKey]
">
{{ t('common.save') }}
</el-button>
</div>

<app-table
:data="tableData"
:pagination-config="paginationConfig"
@sizeChange="handleSizeChange"
@changePage="getList"
:maxTableHeight="350"
>
<el-table-column
prop="nick_name"
:label="$t('views.userManage.userForm.nick_name.label')"
/>
<app-table :data="tableData" :pagination-config="paginationConfig" @sizeChange="handleSizeChange"
@changePage="getList" :maxTableHeight="350">
<el-table-column prop="nick_name" :label="$t('views.userManage.userForm.nick_name.label')" />
<el-table-column prop="username" :label="$t('views.login.loginForm.username.label')" />
<el-table-column prop="source" :label="$t('views.userManage.source.label')">
<template #default="{ row }">
Expand All @@ -164,21 +114,13 @@
</el-table-column>
<el-table-column :width="140" align="center">
<template #header>
<el-checkbox
:model-value="allChecked"
:indeterminate="allIndeterminate"
:disabled="current?.is_auth"
@change="handleCheckAll"
>{{ $t('views.chatUser.authorization') }}
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="current?.is_auth"
@change="handleCheckAll">{{ $t('views.chatUser.authorization') }}
</el-checkbox>
</template>
<template #default="{ row }">
<el-checkbox
v-model="row.is_auth"
:indeterminate="row.indeterminate"
:disabled="current?.is_auth"
@change="(value: boolean) => handleRowChange(value, row)"
/>
<el-checkbox v-model="row.is_auth" :indeterminate="row.indeterminate" :disabled="current?.is_auth"
@change="(value: boolean) => handleRowChange(value, row)" />
</template>
</el-table-column>
</app-table>
Expand All @@ -200,6 +142,7 @@ import { ComplexPermission } from '@/utils/permission/type'
import { RoleConst, PermissionConst } from '@/utils/permission/data'
import { hasPermission } from '@/utils/permission/index'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import permissionMap from '@/permission'

const route = useRoute()

Expand All @@ -208,43 +151,31 @@ const {
} = route as any

const permissionObj = ref<any>({
APPLICATION: new ComplexPermission(
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole],
[
PermissionConst.APPLICATION_CHAT_USER_EDIT,
PermissionConst.APPLICATION_CHAT_USER_EDIT.getApplicationWorkspaceResourcePermission(id),
],
[],
'OR',
),
KNOWLEDGE: new ComplexPermission(
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole],
[
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT,
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT.getKnowledgeWorkspaceResourcePermission(id),
],
[],
'OR',
),
RESOURCE_APPLICATION: [RoleConst.ADMIN, PermissionConst.RESOURCE_APPLICATION_CHAT_USER_EDIT],
RESOURCE_KNOWLEDGE: [RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_CHAT_USER_EDIT],
SHAREDKNOWLEDGE: new ComplexPermission(
APPLICATION: permissionMap['application']['workspace'].application_chat_user_edit(id),
KNOWLEDGE: permissionMap['knowledge']['workspace'].chat_user_edit(id),
RESOURCE_APPLICATION: hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_APPLICATION_CHAT_USER_EDIT], 'OR'),
RESOURCE_KNOWLEDGE: hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_CHAT_USER_EDIT], 'OR'),
SHAREDKNOWLEDGE: hasPermission(new ComplexPermission(
[RoleConst.ADMIN],
[PermissionConst.SHARED_KNOWLEDGE_CHAT_USER_EDIT],
[],
'OR',
),
), 'OR')
})

const currentPermissionKey = computed(() => {
if (route.path.includes('shared')) return 'SHAREDKNOWLEDGE'
if (route.path.includes('resource-management')) {
if (route.meta?.resourceType === 'KNOWLEDGE') {
return 'RESOURCE_KNOWLEDGE'
} else if (route.meta?.resourceType === 'APPLICATION') {
return 'RESOURCE_APPLICATION'
}
}
else if (route.path.includes('shared')) {return 'SHAREDKNOWLEDGE'}
else {
if (route.path.includes('knowledge/')) return 'KNOWLEDGE'
if (route.path.includes('application/')) return 'APPLICATION'
}
return route.meta?.resourceType as string
})

Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
effect="dark"
:content="$t('views.knowledge.setting.vectorization')"
placement="top"
v-else="permissionPrecise.vector(id)"
v-if="permissionPrecise.vector(id)"
>
<span class="mr-4">
<el-button type="primary" text @click.stop="refreshDocument(row)">
Expand Down
Loading