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
4 changes: 4 additions & 0 deletions ui/src/permission/modules/tool/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const workspace = {
* 工作空间「工具」导入权限
*/
import: () => can(P.TOOL_IMPORT),
/**
* 工作空间「工具」文件夹创建权限
*/
folderCreateWorkspace: () => can(P.TOOL_FOLDER_CREATE),
debug: () => false,
authToWorkspace: () => 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.

Here is the review of the code snippet:

Irregularities & Issues

  1. Indentation & Formatting: The new /** ... */ comment block and the folderCreateWorkspace method are indented with spaces, while the existing import method appears to be at the base level (or differently indented depending on context). This inconsistency reduces readability. Ensure consistent indentation (usually 2 or 4 spaces) across all object properties.
  2. Comment Style Consistency: The comment format (/** ... */) is consistent, but verify if other methods in the workspace object use the same JSDoc style. If others use single-line comments //, consider standardizing.

Optimization Suggestions

  1. Naming Convention: folderCreateWorkspace is verbose. Since this is already within a workspace context, createFolder or folderCreate would be more concise and standard.
    • Suggested Name: createFolder: () => can(P.TOOL_FOLDER_CREATE),
  2. Redundancy: The term "Workspace" in the method name is redundant because the object itself is named workspace. Remove it for cleaner API usage (e.g., workspace.createFolder() vs workspace.folderCreateWorkspace()).

Corrected Example

const workspace = {
  /**
   * 工作空间「工具」导入权限
   */
  import: () => can(P.TOOL_IMPORT),

  /**
   * 工作空间「工具」文件夹创建权限
   */
  createFolder: () => can(P.TOOL_FOLDER_CREATE), // Renamed for brevity and clarity

  debug: () => false,
  authToWorkspace: () => false,
};

Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/tool/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import ButtonCreateTool from './components/ButtonCreateTool.vue'
import ButtonToolStore from './components/ButtonToolStore.vue'
import EditToolForm from '@/views/tool/tool-form/EditToolForm.vue'
import perm from '@/permission/index.ts'
import { getWorkspaceId } from '@/utils/resource-context.ts'

/* 当前文件夹 */

Expand Down Expand Up @@ -223,7 +222,7 @@ onMounted(() => {
<template #aside="{ title, Header }">
<component :is="Header">
<h4>{{ title }}</h4>
<MkTooltip v-if="perm.tool.workspace.folderCreate(getWorkspaceId() || '')" content="创建文件夹" placement="top">
<MkTooltip v-if="perm.tool.workspace.folderCreateWorkspace()" content="创建文件夹" placement="top">
<el-button @click="handleCreateFolder" text type="primary" class="-mr-1">
<MkIcon name="icon_add-folder_outlined" :size="18" />
</el-button>

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 diff shows a change that likely breaks functionality. The getWorkspaceId import is removed, but the original logic depended on getWorkspaceId() to create a dynamic permission token (e.g., perm.tool.workspace.folderCreate('id')).

Issues:

  1. Logical Regression: The new code calls perm.tool.workspace.folderCreateWorkspace(), which appears to be a different method key than the original folderCreate. Unless folderCreateWorkspace takes no arguments and handles internal state retrieval itself, this replaces a dynamic check with a static one. If the underlying permission system still requires an ID in the key, the button might always show or hide incorrectly.
  2. Orphaned Logic: If folderCreateWorkspace does not internally fetch the workspace ID like getWorkspaceId() did, the context of which workspace’s folder creation is being perm-checked is lost. This could lead to security issues (showing the button for unauthorized workspaces) or UX bugs.

Suggestion:
Ensure that perm.tool.workspace.folderCreateWorkspace() correctly encapsulates the logic previously done by folderCreate(getWorkspaceId())). If it doesn’t, retrieve the workspace ID inside the component or pass it explicitly:

<MkTooltip v-if="perm.tool.workspace.folderCreate(currentWorkspaceId)" ...>

Verify that the perm object actually exposes folderCreateWorkspace as intended.

Expand Down
Loading