Skip to content

Commit e5ca3ae

Browse files
committed
🐛 Bugfix: Fix various issues when the Agent's permissions are set to READ_ONLY. #2510 #2551
[Specification Details] 1. When the Agent permission is READ_ONLY, agents cannot be deleted, and versions cannot be published or edited. 2. List of tools that can be disabled when Agent permission is READ_ONLY
1 parent 6fe86f9 commit e5ca3ae

3 files changed

Lines changed: 89 additions & 12 deletions

File tree

frontend/app/[locale]/agents/AgentVersionCard.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
DescriptionsProps,
2929
Modal,
3030
Dropdown,
31+
Tooltip,
3132
theme
3233
} from "antd";
3334
import { ExclamationCircleFilled } from '@ant-design/icons';
@@ -149,6 +150,13 @@ export function VersionCardItem({
149150
const { tools: toolList } = useToolList();
150151
const { agents: agentList } = useAgentList(user?.tenantId ?? null);
151152

153+
// Get current agent's permission from agent list
154+
const currentAgent = useMemo(() => {
155+
return agentList.find((a: Agent) => a.id === String(agentId));
156+
}, [agentList, agentId]);
157+
158+
const isReadOnly = currentAgent?.permission === "READ_ONLY";
159+
152160
// Modal state
153161
const [compareModalOpen, setCompareModalOpen] = useState(false);
154162
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
@@ -366,25 +374,44 @@ export function VersionCardItem({
366374
items: [
367375
{
368376
key: 'edit',
369-
label: t("common.edit"),
377+
label: isReadOnly ? (
378+
<Tooltip title={t("agent.noEditPermission")}>
379+
<span>{t("common.edit")}</span>
380+
</Tooltip>
381+
) : (
382+
t("common.edit")
383+
),
370384
icon: <Edit size={14} />,
385+
disabled: isReadOnly,
371386
onClick: () => setEditModalOpen(true)
372387
},
373388
{
374389
key: 'rollback',
375-
label: t("agent.version.rollback"),
390+
label: isReadOnly ? (
391+
<Tooltip title={t("agent.noEditPermission")}>
392+
<span>{t("agent.version.rollback")}</span>
393+
</Tooltip>
394+
) : (
395+
t("agent.version.rollback")
396+
),
376397
icon: <RotateCcw size={14} />,
377-
disabled: isCurrentVersion || version.status.toLowerCase() === "disabled",
398+
disabled: isReadOnly || isCurrentVersion || version.status.toLowerCase() === "disabled",
378399
onClick: handleRollbackClick
379400
},
380401
{
381402
type: 'divider',
382403
},
383404
{
384405
key: 'delete',
385-
label: t("common.delete"),
406+
label: isReadOnly ? (
407+
<Tooltip title={t("agent.noEditPermission")}>
408+
<span>{t("common.delete")}</span>
409+
</Tooltip>
410+
) : (
411+
t("common.delete")
412+
),
386413
icon: <Trash2 size={14} />,
387-
disabled: isCurrentVersion,
414+
disabled: isReadOnly || isCurrentVersion,
388415
danger: true,
389416
onClick: handleDeleteClick,
390417
},

frontend/app/[locale]/agents/components/agentConfig/ToolManagement.tsx

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ export default function ToolManagement({
7575
const { t } = useTranslation("common");
7676
const queryClient = useQueryClient();
7777

78-
const editable = currentAgentId || isCreatingMode;
78+
// Get current agent permission from store
79+
const currentAgentPermission = useAgentConfigStore(
80+
(state) => state.currentAgentPermission
81+
);
82+
83+
// Check if current agent is read-only (only when agent is selected and permission is READ_ONLY)
84+
const isReadOnly = !isCreatingMode && currentAgentId !== undefined && currentAgentPermission === "READ_ONLY";
85+
86+
const editable = (currentAgentId || isCreatingMode) && !isReadOnly;
7987

8088
// Get state from store
8189
const originalSelectedTools = useAgentConfigStore(
@@ -423,8 +431,16 @@ export default function ToolManagement({
423431
);
424432
const isDisabledDueToVlm = isToolDisabledDueToVlm(tool.name, isVlmConfigured);
425433
const isDisabledDueToEmbedding = isToolDisabledDueToEmbedding(tool.name, isEmbeddingConfigured);
426-
const isDisabled = isDisabledDueToVlm || isDisabledDueToEmbedding;
427-
return (
434+
const isDisabled = isDisabledDueToVlm || isDisabledDueToEmbedding || isReadOnly;
435+
// Tooltip priority: permission > VLM > Embedding
436+
const tooltipTitle = isReadOnly
437+
? t("agent.noEditPermission")
438+
: isDisabledDueToVlm
439+
? t("toolPool.vlmDisabledTooltip")
440+
: isDisabledDueToEmbedding
441+
? t("toolPool.embeddingDisabledTooltip")
442+
: undefined;
443+
const toolCard = (
428444
<div
429445
key={tool.id}
430446
className={`border-2 rounded-md p-2 flex items-center justify-between transition-all duration-300 ease-in-out min-h-[52px] shadow-sm ${
@@ -491,6 +507,13 @@ export default function ToolManagement({
491507
/>
492508
</div>
493509
);
510+
return tooltipTitle ? (
511+
<Tooltip key={tool.id} title={tooltipTitle}>
512+
{toolCard}
513+
</Tooltip>
514+
) : (
515+
toolCard
516+
);
494517
})}
495518
</div>
496519
),
@@ -513,8 +536,16 @@ export default function ToolManagement({
513536
const isSelected = originalSelectedToolIdsSet.has(tool.id);
514537
const isDisabledDueToVlm = isToolDisabledDueToVlm(tool.name, isVlmConfigured);
515538
const isDisabledDueToEmbedding = isToolDisabledDueToEmbedding(tool.name, isEmbeddingConfigured);
516-
const isDisabled = isDisabledDueToVlm || isDisabledDueToEmbedding;
517-
return (
539+
const isDisabled = isDisabledDueToVlm || isDisabledDueToEmbedding || isReadOnly;
540+
// Tooltip priority: permission > VLM > Embedding
541+
const tooltipTitle = isReadOnly
542+
? t("agent.noEditPermission")
543+
: isDisabledDueToVlm
544+
? t("toolPool.vlmDisabledTooltip")
545+
: isDisabledDueToEmbedding
546+
? t("toolPool.embeddingDisabledTooltip")
547+
: undefined;
548+
const toolCard = (
518549
<div
519550
key={tool.id}
520551
className={`border-2 rounded-md p-2 flex items-center justify-between transition-all duration-300 ease-in-out min-h-[52px] shadow-sm ${
@@ -579,6 +610,13 @@ export default function ToolManagement({
579610
/>
580611
</div>
581612
);
613+
return tooltipTitle ? (
614+
<Tooltip key={tool.id} title={tooltipTitle}>
615+
{toolCard}
616+
</Tooltip>
617+
) : (
618+
toolCard
619+
);
582620
})}
583621
</div>
584622
)}

frontend/app/[locale]/agents/components/agentManage/AgentList.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,34 @@ export default function AgentList({
506506
</span>
507507
</Tooltip>
508508

509-
<Tooltip title={t("agent.contextMenu.delete")}>
509+
<Tooltip
510+
title={
511+
agent.permission === "READ_ONLY"
512+
? t("agent.noEditPermission")
513+
: t("agent.contextMenu.delete")
514+
}
515+
>
510516
<span>
511517
<Button
512518
type="text"
513519
size="small"
514520
icon={
515521
<Trash2
516522
className="w-4 h-4"
517-
style={{ color: token.colorError }}
523+
style={{
524+
color:
525+
agent.permission === "READ_ONLY"
526+
? token.colorTextDisabled
527+
: token.colorError,
528+
}}
518529
/>
519530
}
520531
onClick={(e) => {
521532
e.preventDefault();
522533
e.stopPropagation();
523534
handleDeleteAgentWithConfirm(agent);
524535
}}
536+
disabled={agent.permission === "READ_ONLY"}
525537
className="agent-action-button agent-action-button-red"
526538
/>
527539
</span>

0 commit comments

Comments
 (0)