mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(ui): resolve team access group grants from team info when the access group list is role-gated
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
f725818f25
commit
5ca75cc590
2 changed files with 78 additions and 12 deletions
|
|
@ -1894,6 +1894,20 @@ describe("TeamInfoView", () => {
|
|||
expect(savedToolPermissions()).toEqual({ wiki: ["read_page"] });
|
||||
});
|
||||
|
||||
it("a team admin without the access group list can still save and keeps the group server allowlist", async () => {
|
||||
const user = userEvent.setup({ delay: null });
|
||||
await renderTeam(user, {
|
||||
accessGroups: [],
|
||||
catalog: [UNIFIED_SERVER],
|
||||
team: { ...unifiedTeam({ wiki: ["read_page"] }), access_group_mcp_server_ids: ["unified-server"] },
|
||||
});
|
||||
|
||||
await renameTeam(user);
|
||||
await save(user);
|
||||
|
||||
expect(savedToolPermissions()).toEqual({ wiki: ["read_page"] });
|
||||
});
|
||||
|
||||
it("drops a server's allowlist when its unified access group is removed while another group stays", async () => {
|
||||
const user = userEvent.setup({ delay: null });
|
||||
await renderTeam(user, { catalog: [UNIFIED_SERVER], team: unifiedTeam({ wiki: ["read_page"] }) });
|
||||
|
|
@ -1904,16 +1918,31 @@ describe("TeamInfoView", () => {
|
|||
expect(savedToolPermissions()).toEqual({});
|
||||
});
|
||||
|
||||
it("refuses to save when a selected unified access group is missing from the loaded list", async () => {
|
||||
it("refuses to save when the access group list is unavailable and the selection changed", async () => {
|
||||
const user = userEvent.setup({ delay: null });
|
||||
await renderTeam(user, {
|
||||
catalog: [UNIFIED_SERVER],
|
||||
accessGroups: [],
|
||||
team: unifiedTeam({ wiki: ["read_page"] }),
|
||||
});
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "remove first unified access group" }));
|
||||
await renameTeam(user);
|
||||
await saveIsRefused(user, /access groups could not be loaded/);
|
||||
});
|
||||
|
||||
it("keeps the loaded group server allowlist when a selected unified access group is missing from the list", async () => {
|
||||
const user = userEvent.setup({ delay: null });
|
||||
await renderTeam(user, {
|
||||
catalog: [UNIFIED_SERVER],
|
||||
accessGroups: [UNIFIED_GROUPS[1]],
|
||||
team: unifiedTeam({ wiki: ["read_page"] }),
|
||||
team: { ...unifiedTeam({ wiki: ["read_page"] }), access_group_mcp_server_ids: ["unified-server"] },
|
||||
});
|
||||
|
||||
await renameTeam(user);
|
||||
await saveIsRefused(user, /access groups could not be loaded/);
|
||||
await save(user);
|
||||
|
||||
expect(savedToolPermissions()).toEqual({ wiki: ["read_page"] });
|
||||
});
|
||||
|
||||
it("refuses to save when the access group list failed to load", async () => {
|
||||
|
|
@ -1973,26 +2002,50 @@ describe("TeamInfoView", () => {
|
|||
[effective("a", "direct"), effective("b", "accessGroup"), effective("c", "toolset")],
|
||||
[],
|
||||
[],
|
||||
{ ids: [], serverIds: [] },
|
||||
),
|
||||
).toEqual({ kind: "resolved", serverIds: new Set(["a", "b", "c"]) });
|
||||
});
|
||||
|
||||
it("does not let a tool-permission entry justify keeping itself", () => {
|
||||
expect(grantedMcpServerIds([effective("stale", "toolPermission")], [], [])).toEqual({
|
||||
expect(grantedMcpServerIds([effective("stale", "toolPermission")], [], [], { ids: [], serverIds: [] })).toEqual({
|
||||
kind: "resolved",
|
||||
serverIds: new Set(),
|
||||
});
|
||||
});
|
||||
|
||||
it("adds only the servers of the unified access groups that are still selected", () => {
|
||||
expect(grantedMcpServerIds([effective("a", "direct")], ["ag-2"], GROUPS)).toEqual({
|
||||
expect(grantedMcpServerIds([effective("a", "direct")], ["ag-2"], GROUPS, { ids: [], serverIds: [] })).toEqual({
|
||||
kind: "resolved",
|
||||
serverIds: new Set(["a", "u3"]),
|
||||
});
|
||||
});
|
||||
|
||||
it("is unresolvable when a selected unified access group is not in the loaded list", () => {
|
||||
expect(grantedMcpServerIds([effective("a", "direct")], ["ag-1", "ag-missing"], GROUPS)).toEqual({
|
||||
expect(
|
||||
grantedMcpServerIds([effective("a", "direct")], ["ag-1", "ag-missing"], GROUPS, { ids: [], serverIds: [] }),
|
||||
).toEqual({
|
||||
kind: "unresolvable",
|
||||
reason: expect.stringMatching(/access groups could not be loaded/),
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the team's loaded access group servers when the list is unavailable and the selection is unchanged", () => {
|
||||
expect(
|
||||
grantedMcpServerIds([effective("a", "direct")], ["ag-1"], [], { ids: ["ag-1"], serverIds: ["u1"] }),
|
||||
).toEqual({
|
||||
kind: "resolved",
|
||||
serverIds: new Set(["a", "u1"]),
|
||||
});
|
||||
});
|
||||
|
||||
it("is unresolvable when the list is unavailable and the selection changed", () => {
|
||||
expect(
|
||||
grantedMcpServerIds([effective("a", "direct")], ["ag-1"], [], {
|
||||
ids: ["ag-1", "ag-2"],
|
||||
serverIds: ["u1"],
|
||||
}),
|
||||
).toEqual({
|
||||
kind: "unresolvable",
|
||||
reason: expect.stringMatching(/access groups could not be loaded/),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -106,20 +106,32 @@ export type McpGrantResolution =
|
|||
| { readonly kind: "resolved"; readonly serverIds: ReadonlySet<string> }
|
||||
| { readonly kind: "unresolvable"; readonly reason: string };
|
||||
|
||||
const sameIdSelection = (a: readonly string[], b: readonly string[]): boolean => {
|
||||
const aSet = new Set(a);
|
||||
const bSet = new Set(b);
|
||||
return aSet.size === bSet.size && [...aSet].every((id) => bSet.has(id));
|
||||
};
|
||||
|
||||
export const grantedMcpServerIds = (
|
||||
effectiveServers: readonly EffectiveMcpServer[],
|
||||
selectedAccessGroupIds: readonly string[],
|
||||
accessGroups: readonly Pick<AccessGroupResponse, "access_group_id" | "access_mcp_server_ids">[],
|
||||
loadedTeamGroups: { readonly ids: readonly string[]; readonly serverIds: readonly string[] },
|
||||
): McpGrantResolution => {
|
||||
const selectedGroups = accessGroups.filter((group) => selectedAccessGroupIds.includes(group.access_group_id));
|
||||
if (selectedAccessGroupIds.some((id) => !selectedGroups.some((group) => group.access_group_id === id))) {
|
||||
return { kind: "unresolvable", reason: "the team's access groups could not be loaded" };
|
||||
}
|
||||
const direct = effectiveServers
|
||||
.filter(({ source }) => source.kind !== "toolPermission")
|
||||
.map(({ server }) => server.server_id);
|
||||
const viaUnifiedGroups = selectedGroups.flatMap((group) => group.access_mcp_server_ids);
|
||||
return { kind: "resolved", serverIds: new Set([...direct, ...viaUnifiedGroups]) };
|
||||
const selectedGroups = accessGroups.filter((group) => selectedAccessGroupIds.includes(group.access_group_id));
|
||||
if (selectedGroups.length === selectedAccessGroupIds.length) {
|
||||
return {
|
||||
kind: "resolved",
|
||||
serverIds: new Set([...direct, ...selectedGroups.flatMap((group) => group.access_mcp_server_ids)]),
|
||||
};
|
||||
}
|
||||
if (sameIdSelection(selectedAccessGroupIds, loadedTeamGroups.ids)) {
|
||||
return { kind: "resolved", serverIds: new Set([...direct, ...loadedTeamGroups.serverIds]) };
|
||||
}
|
||||
return { kind: "unresolvable", reason: "the team's access groups could not be loaded" };
|
||||
};
|
||||
|
||||
export const retainedMcpToolPermissions = (
|
||||
|
|
@ -908,6 +920,7 @@ const TeamInfoView: React.FC<TeamInfoProps> = ({
|
|||
resolveEffectiveMcpServers(effectiveMcpInput),
|
||||
values.access_group_ids || [],
|
||||
allAccessGroups,
|
||||
{ ids: info.access_group_ids ?? [], serverIds: info.access_group_mcp_server_ids ?? [] },
|
||||
);
|
||||
if (mcpResolution.kind === "unresolvable" && Object.keys(submittedToolPermissions).length > 0) {
|
||||
toast.error(mcpUnresolvableSaveError(mcpResolution.reason));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue