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
6 changes: 3 additions & 3 deletions ui/src/permission/model/system-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const systemManage = {
'OR',
),
create: () => false,
modify: (id: string) =>
modify: () =>
hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_EDIT], 'OR'),
paramSetting: (id: string) =>
paramSetting: () =>
hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_EDIT], 'OR'),
delete: (id: string) =>
delete: () =>
hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_DELETE], 'OR'),

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided JavaScript code snippet looks largely correct and functional. However, there are a couple of improvements you could make:

  1. Type Checking: It's generally good practice to add type annotations to function parameters and return types. This can help catch errors at compile time if you're using modern TypeScript.

  2. Remove Unnecessary Parameters: If the modify method does not actually use an id, it might be more appropriate to remove this parameter altogether or document that it's intentionally unused.

Here's how you might refactor the code with these considerations:

const systemManage = {
  'OR': [RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_EDIT],
);

create() {
  // Implement the logic for creating something
  return true;
},

modify() {
  // Optionally implement specific permission checks
  return hasPermission(RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_EDIT);
},

paramSetting(id: string): boolean {
  // Ensure id is used correctly if intended
  return hasPermission(RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_EDIT);
},

delete(id: string): boolean {
  // Ensure id is used correctly if intended
  return hasPermission(RoleConst.ADMIN, PermissionConst.RESOURCE_MODEL_DELETE);
},

folderCreate() {
  // Implement the logic for creating a folder
  return false;  
}

Key Points:

  • Type Annotations: Added (): boolean after each method signature to clearly indicate that they should return a boolean value.
  • Parameter Removal or Documentation: Removed unnecessary id: string parameter from the paramSetting and delete methods unless they truly need it.

These changes improve readability and maintainability while maintaining the functionality of the existing code.

Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/permission/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const PermissionConst = {
SHARED_KNOWLEDGE_DOCUMENT_GENERATE: new Permission('SYSTEM_KNOWLEDGE_DOCUMENT:READ+GENERATE'),
SHARED_KNOWLEDGE_DOCUMENT_MIGRATE: new Permission('SYSTEM_KNOWLEDGE_DOCUMENT:READ+MIGRATE'),
SHARED_KNOWLEDGE_DOCUMENT_EXPORT: new Permission('SYSTEM_KNOWLEDGE_DOCUMENT:READ+EXPORT'),
SHARED_KNOWLEDGE_DOCUMENT_DOWNLOAD_SOURCE_FILE: new Permission('SYSTEM_KNOWLEDGE_DOCUMENT:READ'),
SHARED_KNOWLEDGE_DOCUMENT_DOWNLOAD_SOURCE_FILE: new Permission('SYSTEM_KNOWLEDGE_DOCUMENT:READ+DOWNLOAD'),

SHARED_KNOWLEDGE_PROBLEM_READ: new Permission('SYSTEM_KNOWLEDGE_PROBLEM:READ'),
SHARED_KNOWLEDGE_PROBLEM_CREATE: new Permission('SYSTEM_KNOWLEDGE_PROBLEM:READ+CREATE'),
Copy link
Copy Markdown
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 appears correct and there are no apparent irregularities, potential issues, or optimizations to suggest based on the changes mentioned. The permission constants have been updated appropriately without introducing errors in their syntax or logic.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
type="primary"
text
:title="$t('common.modify')"
v-if="permissionPrecise.modify(row.id)"
v-if="permissionPrecise.modify()"
@click.stop="openEditModel(row)"
>
<el-icon><EditPen /></el-icon>
Expand All @@ -191,7 +191,7 @@
row.model_type === 'LLM' ||
row.model_type === 'IMAGE' ||
row.model_type === 'TTI') &&
permissionPrecise.paramSetting(row.id)
permissionPrecise.paramSetting()
"
@click.stop="openParamSetting(row)"
>
Expand All @@ -205,7 +205,7 @@
type="primary"
text
:title="$t('common.delete')"
v-if="permissionPrecise.delete(row.id)"
v-if="permissionPrecise.delete()"
@click.stop="deleteModel(row)"
>
<el-icon><Delete /></el-icon>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you've provided looks generally clean, but there's one area that can be optimized slightly. Here's an analysis with suggestions:

Changes Suggested

  1. Consistent Permission Check:
    Instead of using permissionPrecise.modify(row.id) in multiple places where only the modify method depends on a specific row ID (row.id), consider calling it once before checking the conditions related to model_type. This way, you avoid unnecessary method calls.

    <!-- Before -->
    <el-button v-if="permissionPrecise.modify(row.id)" />
    
    <!-- After -->
    const modifyPermission = permissionPrecise.modify();
    if (modifyPermission && ...)
        ...
  2. Reusability:
    If these checks are performed frequently, create a helper function to encapsulate them.

    // Helper Function inside script section
    isRowModifiable({ id, data }) {
      return (
        this.permissionPrecise.modify(id) &&
        (data.model_type === "LLM" || 
         data.model_type === "IMAGE" || 
         data.model_type === "TTI")
      );
    }
    
    // Usage in template
    el-button v-if="isRowModifiable({...row})" />
    
    // Optionally in computed property
    get modifiability() {
       return row => this.isRowModifiable({...row});
    }
  3. Type Checking:
    Ensure proper types are being checked. In Vue.js components, $t() returns strings unless explicitly configured. If $t() returns non-string values elsewhere, handle those cases appropriately to avoid runtime errors.

By implementing these changes, you enhance readability and potentially decrease overhead by reducing repetitive code execution.

Expand Down
Loading