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
9 changes: 8 additions & 1 deletion ui/src/views/application-detail/setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import { getResourceScope, isSystemResource } from '@/utils/resource-context'
import { useApplicationDetailContext } from '../context'
import { createSettings, createSettingsPayload, type ApplicationSettings, type SelectedKnowledge, type LongTermSettingData } from './settings'
import ButtonKnowledgeSetting from './components/ButtonKnowledgeSetting.vue'
import perm from '@/permission/index.ts'

type ApplicationSettingPermissionMethod = 'publish'
function applicationSettingPermission(method: ApplicationSettingPermissionMethod): boolean {
if (isSystem.value) return Boolean(perm.application.system[method]())
return Boolean(perm.application.workspace[method](applicationId.value))
}

defineProps<ResourceDetailPageProps>()
defineExpose({ customHeader: true })
Expand Down Expand Up @@ -245,7 +252,7 @@ onMounted(() => {
保存
</el-button>
<!-- 保存并发布智能体 -->
<el-button type="primary" :disabled="saving" @click="publish">发布</el-button>
<el-button v-if="applicationSettingPermission('publish')" type="primary" :disabled="saving" @click="publish">发布</el-button>
</div>
</div>
</Teleport>
Expand Down
9 changes: 8 additions & 1 deletion ui/src/views/workflow/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import { showWorkflowValidateError } from '../components/validate-error'
import { MsgConfirm, MsgError, MsgSuccess } from '@/utils/message'
import { getResourceScope, isSystemResource } from '@/utils/resource-context.ts'
import { goBack } from './navigation'
import perm from '@/permission/index.ts'

type ApplicationWorkflowPermissionMethod = 'publish'
function applicationWorkflowPermission(method: ApplicationWorkflowPermissionMethod): boolean {
if (isSystemResource()) return Boolean(perm.application.system[method]())
return Boolean(perm.application.workspace[method](applicationId))
}

defineOptions({ name: 'ApplicationWorkflowView' })
const requestApi = isSystemResource() ? SystemResourceApplicationApi : WorkspaceApplicationApi
Expand Down Expand Up @@ -372,7 +379,7 @@ onBeforeUnmount(() => stopAutoSave())
</MkTooltip>

<!-- 发布 -->
<el-button type="primary" :disabled="loading" @click="handleOpenPublish">发布</el-button>
<el-button v-if="applicationWorkflowPermission('publish')" type="primary" :disabled="loading" @click="handleOpenPublish">发布</el-button>
<!-- 更多操作 -->
<MkDropdown trigger="click" placement="bottom-end" class="ml-2" persistent>
<el-button text class="h-7! w-7! px-0!">

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.

Code Review

Issues / Irregularities

  1. applicationId dependency risk – applicationWorkflowPermission references applicationId from the outer scope. Make sure it's declared before this function in <script setup> order, otherwise you'll get a temporal dead zone (ReferenceError) at init. Also consider passing it explicitly as a parameter for clarity/testability:

    function applicationWorkflowPermission(method: ..., id: string): boolean
  2. Function called in template – re-evaluated on every render. Since permissions rarely change reactively (and perm.application.system[method]() looks like a non-reactive call), wrap it in a computed:

    const canPublish = computed(() => applicationWorkflowPermission('publish'))

    Then use v-if="canPublish".

  3. Inconsistent meaning of the API – perm.application.system[method]() is called as a function, while perm.application.workspace[method](applicationId) takes an argument. Verify both are actually functions (the type is only a string union; TS can't check these dynamic accesses). If perm has typed methods, prefer direct calls: perm.application.system.publish() — safer and no string indexing.

  4. Import style inconsistency – elsewhere imports drop the .ts extension ('@/utils/resource-context.ts' also has it, but './navigation' doesn't). Standardize — typically omit extensions for module resolution consistency and bundler compatibility.

  5. Redundant Boolean() – if the permission functions already return booleans, Boolean(...) wrapping is unnecessary noise. If they may return undefined/truthy values, the cast is fine — but note it explicitly in the permission module's typing instead.

Optimization Suggestions

  • UX consideration: hiding the button with v-if vs. disabling with :disabled + tooltip ("no permission"). Hiding is cleaner security-wise, but confirm designers intend hidden (some teams prefer disabled-with-reason).
  • Naming: ApplicationWorkflowPermissionMethod is verbose; something like type WorkflowAction = 'publish' is clearer.
  • Generalization: if more buttons will need checks (dropdown "more actions" menu likely), export a small composable, e.g. useApplicationWorkflowPermission(applicationId) returning { canPublish, canDelete, ... }, to avoid repeating helper calls in the template.

Overall the change is functionally sound; the main real risks are #1 (declaration order) and #3 (unverified dynamic method existence).

Expand Down
Loading