π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix: gate the agent config entries on both halves of configure access (#17881)
Rdmclin2d490099539d2
diff --git a/src/routes/(main)/agent/profile/features/Header/index.test.tsx b/src/routes/(main)/agent/profile/features/Header/index.test.tsxindex 4d28318069d..f88822b0e14 100644--- a/src/routes/(main)/agent/profile/features/Header/index.test.tsx+++ b/src/routes/(main)/agent/profile/features/Header/index.test.tsx@@ -36,6 +36,10 @@ const mocks = vi.hoisted(() => ({removeAgent: vi.fn(),},navigate: vi.fn(),+ // The two independent halves of "may configure this agent": the workspace+ // role permission and this agent's General Access level.+ permission: { allowed: true },+ resourceAccess: { canEditResource: true, canManageResource: true },profileState: {editor: undefined as { getDocument: (format: string) => string | undefined } | undefined,lockState: { holderId: null as string | null, lockedByOther: false, pending: false },@@ -49,18 +53,22 @@ vi.mock('@lobechat/const', async (importOriginal) => ({interface MockDropdownItem {children?: MockDropdownItem[];+ disabled?: boolean;key?: string;label?: ReactNode;onClick?: () => void;type?: string;}+// `disabled` is forwarded rather than dropped: the permission entries below are+// deliberately rendered-but-disabled, so a harness that ignores the flag would+// report them as available and pass no matter what the component decides.const renderMenuItems = (items: MockDropdownItem[]) =>items.filter((item) => item.type !== 'divider').map((item) => (<div key={item.key}>- <button type="button" onClick={item.onClick}>+ <button disabled={item.disabled} type="button" onClick={item.onClick}>{item.label}</button>{item.children && <div>{renderMenuItems(item.children)}</div>}@@ -160,8 +168,12 @@ vi.mock('@/features/ResourcePermission/AccessLevelTag', () => ({),}));+vi.mock('@/hooks/usePermission', () => ({+ usePermission: () => mocks.permission,+}));+vi.mock('@/features/ResourcePermission/useResourceAccess', () => ({- useResourceAccess: () => ({ canEditResource: true, canManageResource: true }),+ useResourceAccess: () => mocks.resourceAccess,}));vi.mock('@/features/NavHeader', () => ({@@ -259,6 +271,37 @@ describe('Agent profile Header', () => {mocks.agentState.visibility = 'public';mocks.globalState.showAgentBuilderPanel = false;mocks.profileState.editor = undefined;+ mocks.permission.allowed = true;+ mocks.resourceAccess.canEditResource = true;+ mocks.resourceAccess.canManageResource = true;+ });++ // `ResourceConfigAccessGate` requires the role permission AND resource-level+ // edit access. A member whose role cannot edit content but who holds `edit`+ // General Access on this agent satisfies only the second half β offering them+ // an enabled entry sends them to a page that immediately bounces them back.+ it.each([+ ['the role cannot edit content', { canEditResource: true, permission: false }],+ ['General Access is view-only', { canEditResource: false, permission: true }],+ ])('disables the config entries when %s', (_label, { canEditResource, permission }) => {+ mocks.permission.allowed = permission;+ mocks.resourceAccess.canEditResource = canEditResource;+ // No global mock reset in this file, so the shared spy carries calls in+ // from earlier cases; a "never navigated" assertion has to start clean.+ mocks.navigate.mockClear();++ render(<Header />);++ const settings = screen.getByRole('button', { name: 'advancedSettings' });+ const permissionEntry = screen.getByRole('button', { name: 'permission.page.entry' });++ expect(settings).toBeDisabled();+ expect(permissionEntry).toBeDisabled();++ // The handler guards independently of the `disabled` prop, since the real+ // menu renders through a component that may still deliver the click.+ fireEvent.click(permissionEntry);+ expect(mocks.navigate).not.toHaveBeenCalledWith('/agent/agent-1/permission');});it.each([false, true])(diff --git a/src/routes/(main)/agent/profile/features/Header/index.tsx b/src/routes/(main)/agent/profile/features/Header/index.tsxindex b6a70b121d9..4d930ed8a23 100644--- a/src/routes/(main)/agent/profile/features/Header/index.tsx+++ b/src/routes/(main)/agent/profile/features/Header/index.tsx@@ -145,6 +145,11 @@ const Header = memo(() => {// affordance must not be offered at all.const isBuiltinAgent = useAgentStore(builtinAgentSelectors.isBuiltinAgent(activeAgentId));const canManage = hasEditPermission && canManageResource && !isBuiltinAgent;+ // Both halves, in the same order `ResourceConfigAccessGate` applies them: a+ // role that cannot edit content is refused even where this agent's General+ // Access says `edit`. Checking only the resource half would re-open the+ // dead-end click for exactly that member.+ const canConfigure = hasEditPermission && canEditResource;const handleDelete = useCallback(() => {if (!canManage || !activeAgentId) return;@@ -227,12 +232,12 @@ const Header = memo(() => {{// View/use-level members can't edit the agent config β keep the entry// visible but disabled (project convention: disabled, not hidden).- disabled: !canEditResource,+ disabled: !canConfigure,icon: <Icon icon={Settings2Icon} />,key: 'advanced-settings',label: t('advancedSettings', { ns: 'setting' }),onClick: () => {- if (!canEditResource) return;+ if (!canConfigure) return;settingsModalRef.current?.close();settingsModalRef.current = openAgentSettingsModal();},@@ -251,12 +256,12 @@ const Header = memo(() => {// without edit-level access it redirects straight back with a// toast, so an enabled entry here is a click into a dead end.// Disabled, not hidden β the member can still see the action exists.- disabled: !canEditResource,+ disabled: !canConfigure,icon: <Icon icon={UsersIcon} />,key: 'permission',label: t('permission.page.entry', { ns: 'setting' }),onClick: () => {- if (!canEditResource) return;+ if (!canConfigure) return;if (activeAgentId) navigate(`/agent/${activeAgentId}/permission`);},}@@ -318,7 +323,7 @@ const Header = memo(() => {}, [activeAgentId,authorName,- canEditResource,+ canConfigure,canManage,createdAt,dateLocale,