Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix roles overflow
Thiago Araujo da Silvade82f4e114fa
diff --git a/backend/e2e-test/routes/v1/org-user-access.spec.ts b/backend/e2e-test/routes/v1/org-user-access.spec.tsindex c23dc22d5a..0d0760f119 100644--- a/backend/e2e-test/routes/v1/org-user-access.spec.ts+++ b/backend/e2e-test/routes/v1/org-user-access.spec.ts@@ -21,6 +21,8 @@ describe("Organization user access listing", () => {let groupOnlyUser: { userId: string; username: string };let adminGroupId: string;let memberGroupId: string;+ let linkedGroupId: string;+ let cleanupParentOrg: () => Promise<void>;const listUserAccess = async () => {const res = await testServer.inject({@@ -34,6 +36,8 @@ describe("Organization user access listing", () => {beforeAll(async () => {({ orgId, authToken, cleanup } = await createIsolatedOrgAndProject("user-access"));+ const parentOrg = await createIsolatedOrgAndProject("user-access-parent");+ cleanupParentOrg = parentOrg.cleanup;directUser = await createUser("direct");directAndGroupUser = await createUser("direct-and-group");@@ -55,14 +59,26 @@ describe("Organization user access listing", () => {temporaryRole: { role: OrgMembershipRole.Admin, endsAt: new Date(Date.now() + HOUR_MS) }});+ // Same name and the same role pair as qa-team, so its rows interleave with that group's unless the+ // query keeps each group's rows together.+ linkedGroupId = await createOrgGroup({+ orgId,+ ownerOrgId: parentOrg.orgId,+ name: "qa-team",+ role: OrgMembershipRole.Member,+ temporaryRole: { role: OrgMembershipRole.Admin, endsAt: new Date(Date.now() + HOUR_MS) }+ });+await addUsersToGroup(adminGroupId, [directAndGroupUser.userId, groupOnlyUser.userId]);await addUsersToGroup(memberGroupId, [groupOnlyUser.userId]);+ await addUsersToGroup(linkedGroupId, [groupOnlyUser.userId]);});- // Deleting the org cascades the groups.+ // Deleting the orgs cascades the groups.afterAll(async () => {await deleteUsers([directUser.userId, directAndGroupUser.userId, groupOnlyUser.userId]);await cleanup();+ await cleanupParentOrg();});test("lists direct members with their groups and users who reach the org only through a group", async () => {@@ -84,20 +100,30 @@ describe("Organization user access listing", () => {const groupOnly = byUserId.get(groupOnlyUser.userId);expect(groupOnly?.user.username).toBe(groupOnlyUser.username);expect(groupOnly?.membership).toBeNull();- expect(groupOnly?.groups.map((group) => group.id).sort()).toEqual([adminGroupId, memberGroupId].sort());+ expect(groupOnly?.groups.map((group) => group.id).sort()).toEqual(+ [adminGroupId, memberGroupId, linkedGroupId].sort()+ );});- test("lists every active role of a group and leaves expired temporary roles out", async () => {+ test("lists every active role of a group, permanent first, and leaves expired temporary roles out", async () => {const users = await listUserAccess();const groupOnly = users.find((row) => row.user.id === groupOnlyUser.userId);const roleSlugs = (groupId: string) =>- groupOnly?.groups- .find((group) => group.id === groupId)- ?.roles.map((role) => role.role)- .sort();+ groupOnly?.groups.find((group) => group.id === groupId)?.roles.map((role) => role.role);expect(roleSlugs(adminGroupId)).toEqual([OrgMembershipRole.Admin]);- expect(roleSlugs(memberGroupId)).toEqual([OrgMembershipRole.Admin, OrgMembershipRole.Member]);+ expect(roleSlugs(memberGroupId)).toEqual([OrgMembershipRole.Member, OrgMembershipRole.Admin]);+ });++ test("keeps the roles of two groups with the same name apart", async () => {+ const users = await listUserAccess();+ const groupOnly = users.find((row) => row.user.id === groupOnlyUser.userId);+ const sameName = groupOnly?.groups.filter((group) => group.name === "qa-team");++ expect(sameName).toHaveLength(2);+ sameName?.forEach((group) => {+ expect(group.roles.map((role) => role.role)).toEqual([OrgMembershipRole.Member, OrgMembershipRole.Admin]);+ });});test("leaves the direct membership list unchanged", async () => {diff --git a/backend/e2e-test/testUtils/groups.ts b/backend/e2e-test/testUtils/groups.tsindex 1e06f87aa4..5063771281 100644--- a/backend/e2e-test/testUtils/groups.ts+++ b/backend/e2e-test/testUtils/groups.ts@@ -1,14 +1,17 @@import { AccessScope, OrgMembershipRole, TableName } from "@app/db/schemas";// Inserts rows directly: the group API refuses users with no org membership, which is exactly who these specs test.+// `ownerOrgId` puts the group row in another org while its membership stays in `orgId`, the shape a parent+// org's group takes when it is linked into a sub-org.export const createOrgGroup = async (dto: {orgId: string;+ ownerOrgId?: string;name: string;role: OrgMembershipRole;temporaryRole?: { role: OrgMembershipRole; endsAt: Date };}) => {const [group] = await testDb(TableName.Groups)- .insert({ orgId: dto.orgId, name: dto.name, slug: dto.name })+ .insert({ orgId: dto.ownerOrgId ?? dto.orgId, name: dto.name, slug: dto.name }).returning("id");const groupId = (group as { id: string }).id;diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 94a5336fb7..e330b45a84 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -883,7 +883,7 @@ export const ORGANIZATIONS = {membership:"The user's direct organization membership, or null when they only reach the organization through groups.",groups: "The groups holding an organization membership that the user belongs to.",- groupRoles: "The group's active organization roles. Expired temporary roles are left out.",+ groupRoles: "The group's active organization roles, permanent roles first. Expired temporary roles are left out.",groupRole: "The role slug, or 'custom' when it is a custom role.",groupRoleId: "The ID of the custom role, or null for a built-in role."},diff --git a/backend/src/services/org/org-dal.ts b/backend/src/services/org/org-dal.tsindex 7ecd1e7171..d4e422ebd1 100644--- a/backend/src/services/org/org-dal.ts+++ b/backend/src/services/org/org-dal.ts@@ -559,7 +559,11 @@ export const orgDALFactory = (db: TDbClient) => {};// Users with no direct org row never show up in findAllOrgMembers, so this is the only place they come- // from. Expired temporary roles are skipped to match isActiveRole.+ // from. Expired temporary roles are skipped to match isActiveRole. Roles come back permanent first so+ // the one a client shows when it has room for only one is never the one about to expire. The group id+ // breaks name ties: a sub-org can hold a local group and a linked parent group with the same name, and+ // sqlNestRelationships nests each role under the group it last appended, so a group's rows must stay+ // contiguous.const findAllOrgGroupUserAccess = async (orgId: string) => {try {const rows = await db@@ -591,7 +595,13 @@ export const orgDALFactory = (db: TDbClient) => {db.ref("role").withSchema(TableName.MembershipRole),db.ref("customRoleId").withSchema(TableName.MembershipRole).as("roleId"))- .orderBy(`${TableName.Groups}.name`);+ .orderBy([+ { column: `${TableName.Groups}.name` },+ { column: `${TableName.Groups}.id` },+ { column: `${TableName.MembershipRole}.isTemporary` },+ { column: `${TableName.MembershipRole}.temporaryAccessEndTime` },+ { column: `${TableName.MembershipRole}.role` }+ ]);return sqlNestRelationships({data: rows,diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/GroupAccessPopover.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/GroupAccessPopover.tsxindex 9724bf5593..6775d5b43a 100644--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/GroupAccessPopover.tsx+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/GroupAccessPopover.tsx@@ -8,7 +8,10 @@ import {Popover,PopoverContent,PopoverTrigger,- Separator+ Separator,+ Tooltip,+ TooltipContent,+ TooltipTrigger} from "@app/components/v3";import { TOrgUserAccessGroup, TOrgUserAccessGroupRole } from "@app/hooks/api/users/types";@@ -19,6 +22,58 @@ type Props = {getRoleName: (role: TOrgUserAccessGroupRole) => string;};+const MAX_VISIBLE_ROLES = 1;++const RoleBadge = ({ name }: { name: string }) => (+ <Badge variant="neutral" isTruncatable className="max-w-[8rem]">+ {name}+ </Badge>+);++const GroupRoleBadges = ({+ roles,+ getRoleName+}: {+ roles: TOrgUserAccessGroupRole[];+ getRoleName: (role: TOrgUserAccessGroupRole) => string;+}) => {+ const visible = roles.slice(0, MAX_VISIBLE_ROLES);+ const overflow = roles.slice(MAX_VISIBLE_ROLES);++ return (+ <div className="flex shrink-0 items-center gap-1.5">+ {visible.map((role) => (+ <RoleBadge key={role.roleId ?? role.role} name={getRoleName(role)} />+ ))}+ {overflow.length > 0 && (+ <Popover>+ <Tooltip>+ <TooltipTrigger className="flex h-4 items-center">+ <PopoverTrigger asChild>+ <Badge variant="neutral" asChild>+ <button type="button" onClick={(e) => e.stopPropagation()}>+ +{overflow.length}+ </button>+ </Badge>+ </PopoverTrigger>+ </TooltipTrigger>+ <TooltipContent>Click to view additional roles</TooltipContent>+ </Tooltip>+ <PopoverContent+ side="right"+ className="flex w-auto max-w-sm flex-wrap gap-1.5"+ onClick={(e) => e.stopPropagation()}+ >+ {overflow.map((role) => (+ <RoleBadge key={role.roleId ?? role.role} name={getRoleName(role)} />+ ))}+ </PopoverContent>+ </Popover>+ )}+ </div>+ );+};+export const GroupAccessPopover = ({ orgId, groups, hasDirectAccess, getRoleName }: Props) => {const [isOpen, setIsOpen] = useState(false);@@ -64,18 +119,7 @@ export const GroupAccessPopover = ({ orgId, groups, hasDirectAccess, getRoleName{group.name}</span></Link>- <div className="flex shrink-0 items-center gap-1.5">- {group.roles.map((role) => (- <Badge- key={role.roleId ?? role.role}- variant="neutral"- isTruncatable- className="max-w-[8rem]"- >- {getRoleName(role)}- </Badge>- ))}- </div>+ <GroupRoleBadges roles={group.roles} getRoleName={getRoleName} /></li>))}</ul>