fix: debug plugin permission setting not work (#38197)

This commit is contained in:
非法操作 2026-06-30 15:29:20 +08:00 committed by GitHub
parent 03d59dba47
commit 4303103304
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 5 deletions

View File

@ -128,7 +128,7 @@ describe('useReferenceSetting Hook', () => {
expect(result.current.canDebugger).toBe(true)
})
it('should ignore legacy admin permission for managers without plugin keys', () => {
it('should allow debug for managers with legacy admin permission when RBAC is disabled', () => {
vi.mocked(useAppContext).mockReturnValue({
isCurrentWorkspaceManager: true,
isCurrentWorkspaceOwner: false,
@ -146,10 +146,10 @@ describe('useReferenceSetting Hook', () => {
const { result } = renderHook(() => useReferenceSetting(PluginCategoryEnum.tool))
expect(result.current.canManagement).toBe(false)
expect(result.current.canDebugger).toBe(false)
expect(result.current.canDebugger).toBe(true)
})
it('should ignore legacy admin permission for owners without plugin keys', () => {
it('should allow debug for owners with legacy admin permission when RBAC is disabled', () => {
vi.mocked(useAppContext).mockReturnValue({
isCurrentWorkspaceManager: false,
isCurrentWorkspaceOwner: true,
@ -167,7 +167,30 @@ describe('useReferenceSetting Hook', () => {
const { result } = renderHook(() => useReferenceSetting(PluginCategoryEnum.tool))
expect(result.current.canManagement).toBe(false)
expect(result.current.canDebugger).toBe(false)
expect(result.current.canDebugger).toBe(true)
})
it('should allow debug for normal users when legacy debug permission is everyone and RBAC is disabled', () => {
vi.mocked(useAppContext).mockReturnValue({
isCurrentWorkspaceManager: false,
isCurrentWorkspaceOwner: false,
langGeniusVersionInfo: { current_version: '1.0.0', latest_version: '', version: '' },
workspacePermissionKeys: ['plugin.install'],
} as ReturnType<typeof useAppContext>)
vi.mocked(usePluginPermissionSettings).mockReturnValue({
data: {
install_permission: PermissionType.everyone,
debug_permission: PermissionType.everyone,
},
} as ReturnType<typeof usePluginPermissionSettings>)
const { result } = renderHook(() => useReferenceSetting(PluginCategoryEnum.tool), {
systemFeatures: { rbac_enabled: false },
})
expect(result.current.canDebugPlugin).toBe(true)
expect(result.current.canDebugger).toBe(true)
})
it('should use plugin keys even when legacy admin permission is configured and RBAC is enabled', () => {

View File

@ -52,7 +52,9 @@ export const usePluginSettingsAccess = () => {
const canInstallPlugin = hasPermission(workspacePermissionKeys, 'plugin.install') && legacyCanInstallPlugin
const canUpdatePlugin = hasPermission(workspacePermissionKeys, 'plugin.install') && legacyCanInstallPlugin
const canDeletePlugin = hasPermission(workspacePermissionKeys, 'plugin.delete') && legacyCanInstallPlugin
const canDebugPlugin = hasPermission(workspacePermissionKeys, 'plugin.debug') && legacyCanDebugPlugin
const canDebugPlugin = rbacEnabled
? hasPermission(workspacePermissionKeys, 'plugin.debug')
: legacyCanDebugPlugin
return {
permission: permissions,