Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

remove role filter and search matches name and roles

Thiago Araujo da Silva04af2d189477
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 2990749c7c..35d74ea9fc 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -218,7 +218,7 @@ export const IDENTITIES_V2 = {
search: {
desc: "The filters to apply to the search.",
name: "The name of the identity to filter by.",
- role: "The role of the identity to filter by."
+ role: "The role to filter by. Matches against the role name or slug for custom roles and the role type for predefined roles."
},
offset: "The offset to start from. If you enter 10, it will start from the 10th identity.",
limit: "The number of identities to return.",
@@ -231,7 +231,7 @@ export const IDENTITIES_V2 = {
search: {
desc: "The filters to apply when counting.",
name: "The name of the identity to filter by.",
- role: "The role of the identity to filter by."
+ role: "The role to filter by. Matches against the role name or slug for custom roles and the role type for predefined roles."
}
}
} as const;
diff --git a/backend/src/server/routes/v2/identity-router.ts b/backend/src/server/routes/v2/identity-router.ts
index ba24ce88d6..00df08e93b 100644
--- a/backend/src/server/routes/v2/identity-router.ts
+++ b/backend/src/server/routes/v2/identity-router.ts
@@ -119,6 +119,10 @@ export const registerIdentityRouter = async (server: FastifyZodProvider) => {
z
.object({
[SearchResourceOperators.$eq]: searchResourceZodValidate(z.string().max(255), "Role $eq"),
+ [SearchResourceOperators.$contains]: searchResourceZodValidate(
+ z.string().max(255),
+ "Role $contains"
+ ),
[SearchResourceOperators.$in]: searchResourceZodValidate(z.string().max(255), "Role $in").array()
})
.partial()
@@ -203,6 +207,10 @@ export const registerIdentityRouter = async (server: FastifyZodProvider) => {
z
.object({
[SearchResourceOperators.$eq]: searchResourceZodValidate(z.string().max(255), "Role $eq"),
+ [SearchResourceOperators.$contains]: searchResourceZodValidate(
+ z.string().max(255),
+ "Role $contains"
+ ),
[SearchResourceOperators.$in]: searchResourceZodValidate(z.string().max(255), "Role $in").array()
})
.partial()
diff --git a/backend/src/services/identity-v2/identity-membership-dal.ts b/backend/src/services/identity-v2/identity-membership-dal.ts
index 1e577e6176..205d0dd181 100644
--- a/backend/src/services/identity-v2/identity-membership-dal.ts
+++ b/backend/src/services/identity-v2/identity-membership-dal.ts
@@ -134,7 +134,7 @@ export const identityMembershipV2DALFactory = (db: TDbClient) => {
buildKnexFilterForSearchResource(searchedMemberships, searchFilter, (attr) => {
switch (attr) {
case "role":
- return [`${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
+ return [`${TableName.Role}.name`, `${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
case "name":
return `${TableName.Identity}.name`;
default:
@@ -440,7 +440,7 @@ export const identityMembershipV2DALFactory = (db: TDbClient) => {
buildKnexFilterForSearchResource(query, searchFilter, (attr) => {
switch (attr) {
case "role":
- return [`${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
+ return [`${TableName.Role}.name`, `${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
case "name":
return `${TableName.Identity}.name`;
default:
@@ -496,7 +496,7 @@ export const identityMembershipV2DALFactory = (db: TDbClient) => {
buildKnexFilterForSearchResource(query, searchFilter, (attr) => {
switch (attr) {
case "role":
- return [`${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
+ return [`${TableName.Role}.name`, `${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
case "name":
return `${TableName.Identity}.name`;
default:
diff --git a/frontend/src/hooks/api/identities/types.ts b/frontend/src/hooks/api/identities/types.ts
index 473adfdde7..fcb586cf5e 100644
--- a/frontend/src/hooks/api/identities/types.ts
+++ b/frontend/src/hooks/api/identities/types.ts
@@ -954,6 +954,15 @@ export enum SearchIdentitiesScope {
ProjectScope = "project"
}
+type IdentitySearchFilter = {
+ name?: { $contains: string };
+ role?: { $contains: string };
+ $or?: Array<{
+ name?: { $contains: string };
+ role?: { $contains: string };
+ }>;
+};
+
export type TSearchIdentitiesDTO = {
orgId: string;
limit?: number;
@@ -961,19 +970,13 @@ export type TSearchIdentitiesDTO = {
orderBy?: OrgIdentityOrderBy;
orderDirection?: OrderByDirection;
scope?: SearchIdentitiesScope[];
- search: {
- name?: { $contains: string };
- role?: { $in: string[] };
- };
+ search: IdentitySearchFilter;
};
export type TCountIdentitiesDTO = {
orgId: string;
scope: SearchIdentitiesScope[];
- search: {
- name?: { $contains: string };
- role?: { $in: string[] };
- };
+ search: IdentitySearchFilter;
};
export type TIdentityMembershipCounts = {
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTable.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTable.tsx
index b34c522f40..ac37240fda 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTable.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityTable.tsx
@@ -1,14 +1,7 @@
-import { useCallback, useState } from "react";
+import { useState } from "react";
import { useNavigate } from "@tanstack/react-router";
import { formatDistanceToNow } from "date-fns";
-import {
- ChevronDownIcon,
- EditIcon,
- FilterIcon,
- MoreHorizontalIcon,
- SearchIcon,
- TrashIcon
-} from "lucide-react";
+import { ChevronDownIcon, EditIcon, MoreHorizontalIcon, SearchIcon, TrashIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { LastLoginSection } from "@app/components/organization/LastLoginSection";
@@ -16,10 +9,8 @@ import { OrgPermissionCan } from "@app/components/permissions";
import {
Badge,
DropdownMenu,
- DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuLabel,
DropdownMenuTrigger,
Empty,
EmptyDescription,
@@ -59,7 +50,6 @@ import { usePagination, useResetPageHelper } from "@app/hooks";
import {
identityAuthToNameMap,
useCountOrgIdentityMemberships,
- useGetOrgRoles,
useSearchOrgIdentityMemberships
} from "@app/hooks/api";
import { OrderByDirection } from "@app/hooks/api/generic/types";
@@ -79,10 +69,6 @@ type Props = {
) => void;
};
-type Filter = {
- roles: string[];
-};
-
type ScopeTab = "all" | "organization" | "project";
const TAB_TO_SCOPE: Record<ScopeTab, SearchIdentitiesScope[]> = {
@@ -400,14 +386,15 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
setUserTablePreference("identityTable", PreferenceKey.PerPage, newPerPage);
};
- const [filter, setFilter] = useState<Filter>({ roles: [] });
-
const organizationId = currentOrg?.id || "";
- const searchPayload = {
- name: debouncedSearch ? { $contains: debouncedSearch } : undefined,
- role: filter.roles?.length ? { $in: filter.roles } : undefined
- };
+ // A single search term matches either the identity name or any of its role names/slugs,
+ // so name + role are OR'd rather than AND'd (top-level keys would otherwise combine with AND).
+ const searchPayload = debouncedSearch
+ ? {
+ $or: [{ name: { $contains: debouncedSearch } }, { role: { $contains: debouncedSearch } }]
+ }
+ : {};
const { data, isPending } = useSearchOrgIdentityMemberships({
orgId: organizationId,
@@ -435,8 +422,6 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
const { totalCount = 0 } = data ?? {};
useResetPageHelper({ totalCount, offset, setPage });
- const { data: roles } = useGetOrgRoles(organizationId);
-
const handleSort = (column: OrgIdentityOrderBy) => {
if (column === orderBy) {
setOrderDirection((prev) =>
@@ -452,26 +437,10 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
);
};
- const handleRoleToggle = useCallback(
- (roleSlug: string) =>
- setFilter((state) => {
- const currentRoles = state.roles || [];
- return {
- ...state,
- roles: currentRoles.includes(roleSlug)
- ? currentRoles.filter((role) => role !== roleSlug)
- : [...currentRoles, roleSlug]
- };
- }),
- []
- );
-
- const isTableFiltered = filter.roles.length > 0;
- const isFiltered = debouncedSearch.trim().length > 0 || isTableFiltered;
+ const isFiltered = debouncedSearch.trim().length > 0;
const isEmpty = !isPending && !data?.identities?.length;
const orgWord = isSubOrganization ? "sub-organization" : "organization";
- const orgVariant = isSubOrganization ? "sub-org" : "org";
const isProjectTab = scopeTab === "project";
const scopeLabel = isProjectTab ? "project" : orgWord;
@@ -480,9 +449,9 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
if (isFiltered) {
emptyTitle =
scopeTab === "all"
- ? "No machine identities match search filter"
- : `No ${scopeLabel} machine identities match search filter`;
- emptyDescription = "Adjust your search or filter criteria.";
+ ? "No machine identities match your search"
+ : `No ${scopeLabel} machine identities match your search`;
+ emptyDescription = "Try adjusting your search.";
} else if (isProjectTab) {
emptyTitle = "No project machine identities found";
emptyDescription = "Machine identities scoped to a project will appear here.";
@@ -515,42 +484,16 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
<TabsTrigger value="all">All{renderTabCount(allScopeCount)}</TabsTrigger>
</TabsList>
</Tabs>
- <div className="flex w-1/2 justify-end gap-2">
- <InputGroup className="flex-1">
- <InputGroupAddon>
- <SearchIcon />
- </InputGroupAddon>
- <InputGroupInput
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- placeholder={`Search ${isSubOrganization ? "sub-organization " : ""}machine identities by name...`}
- />
- </InputGroup>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton variant={isTableFiltered ? orgVariant : "outline"}>
- <FilterIcon />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="max-h-80 overflow-y-auto">
- <DropdownMenuLabel>
- Filter by {isSubOrganization ? "Sub-" : ""}Organization Role
- </DropdownMenuLabel>
- {roles?.map(({ id, slug, name }) => (
- <DropdownMenuCheckboxItem
- key={id}
- checked={filter.roles.includes(slug)}
- onClick={(e) => {
- e.preventDefault();
- handleRoleToggle(slug);
- }}
- >
- {name}
- </DropdownMenuCheckboxItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
+ <InputGroup className="w-1/2">
+ <InputGroupAddon>
+ <SearchIcon />
+ </InputGroupAddon>
+ <InputGroupInput
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ placeholder={`Search ${isSubOrganization ? "sub-organization " : ""}machine identities by name or role...`}
+ />
+ </InputGroup>
</div>
{isEmpty ? (
<Empty className="border">