Skip to content

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

remove additional field from v1 order by

Thiago Araujo da Silva0217554ce9ca
diff --git a/backend/src/server/routes/v2/identity-router.ts b/backend/src/server/routes/v2/identity-router.ts
index c98a794572..cd8ed0ca4e 100644
--- a/backend/src/server/routes/v2/identity-router.ts
+++ b/backend/src/server/routes/v2/identity-router.ts
@@ -8,7 +8,7 @@ import { CharacterType, zodValidateCharacters } from "@app/lib/validator/validat
import { readLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
-import { OrgIdentityOrderBy, SearchIdentitiesScope } from "@app/services/identity/identity-types";
+import { OrgIdentitySearchOrderBy, SearchIdentitiesScope } from "@app/services/identity/identity-types";
const searchResourceZodValidate = zodValidateCharacters([
CharacterType.AlphaNumeric,
@@ -85,8 +85,8 @@ export const registerIdentityRouter = async (server: FastifyZodProvider) => {
.describe(IDENTITIES.SEARCH_V2.scope)
.optional(),
orderBy: z
- .nativeEnum(OrgIdentityOrderBy)
- .default(OrgIdentityOrderBy.Name)
+ .nativeEnum(OrgIdentitySearchOrderBy)
+ .default(OrgIdentitySearchOrderBy.Name)
.describe(IDENTITIES.SEARCH_V2.orderBy)
.optional(),
orderDirection: z
diff --git a/backend/src/services/identity/identity-org-dal.ts b/backend/src/services/identity/identity-org-dal.ts
index 52a33d83eb..e118982c2f 100644
--- a/backend/src/services/identity/identity-org-dal.ts
+++ b/backend/src/services/identity/identity-org-dal.ts
@@ -28,6 +28,7 @@ import { OrderByDirection } from "@app/lib/types";
import {
accessScopeToSearchIdentitiesScope,
OrgIdentityOrderBy,
+ OrgIdentitySearchOrderBy,
SearchIdentitiesScope,
TCountIdentitiesV2DAL,
TListOrgIdentitiesByOrgIdDTO,
@@ -706,7 +707,7 @@ export const identityOrgDALFactory = (db: TDbClient) => {
{
limit,
offset = 0,
- orderBy = OrgIdentityOrderBy.Name,
+ orderBy = OrgIdentitySearchOrderBy.Name,
orderDirection = OrderByDirection.ASC,
searchFilter,
orgId,
@@ -781,9 +782,9 @@ export const identityOrgDALFactory = (db: TDbClient) => {
});
}
- if (orderBy === OrgIdentityOrderBy.Role) {
+ if (orderBy === OrgIdentitySearchOrderBy.Role) {
void searchedMemberships.orderBy("roleSort", orderDirection, "last");
- } else if (orderBy === OrgIdentityOrderBy.LastLogin) {
+ } else if (orderBy === OrgIdentitySearchOrderBy.LastLogin) {
// Never-used identities (lastLoginTime IS NULL) are always pushed to the bottom
// regardless of sort direction so the visible page is dominated by real activity.
void searchedMemberships.orderBy("lastLoginSort", orderDirection, "last");
@@ -920,9 +921,9 @@ export const identityOrgDALFactory = (db: TDbClient) => {
.select(db.ref("description").as("crDescription").withSchema(TableName.Role))
.select(db.ref("permissions").as("crPermission").withSchema(TableName.Role));
- if (orderBy === OrgIdentityOrderBy.Role) {
+ if (orderBy === OrgIdentitySearchOrderBy.Role) {
void query.orderBy("searchedMemberships.roleSort", orderDirection, "last");
- } else if (orderBy === OrgIdentityOrderBy.LastLogin) {
+ } else if (orderBy === OrgIdentitySearchOrderBy.LastLogin) {
void query.orderBy("searchedMemberships.lastLoginSort", orderDirection, "last");
} else {
void query.orderBy("searchedMemberships.identityName", orderDirection);
diff --git a/backend/src/services/identity/identity-types.ts b/backend/src/services/identity/identity-types.ts
index b6ff0334c4..291645f539 100644
--- a/backend/src/services/identity/identity-types.ts
+++ b/backend/src/services/identity/identity-types.ts
@@ -47,6 +47,16 @@ export type TListOrgIdentitiesByOrgIdDTO = {
} & TOrgPermission;
export enum OrgIdentityOrderBy {
+ Name = "name",
+ Role = "role"
+}
+
+// The v2 search endpoint joins Membership and can sort by lastLoginTime; the legacy
+// v1 search / v2 identity-memberships endpoints bind orderBy straight into an
+// `identity.<col>` SQL fragment and would fail with a 500 on LastLogin since the
+// identities table has no such column. Keep this enum separate so the legacy paths
+// reject lastLogin at the Zod boundary.
+export enum OrgIdentitySearchOrderBy {
Name = "name",
Role = "role",
LastLogin = "lastLogin"
@@ -88,7 +98,7 @@ export const accessScopeToSearchIdentitiesScope = (scope: string): SearchIdentit
export type TSearchIdentitiesV2DAL = {
limit?: number;
offset?: number;
- orderBy?: OrgIdentityOrderBy;
+ orderBy?: OrgIdentitySearchOrderBy;
orderDirection?: OrderByDirection;
orgId: string;
scope: SearchIdentitiesScope[];
@@ -102,7 +112,7 @@ export type TSearchIdentitiesV2DAL = {
export type TSearchIdentitiesV2DTO = {
limit?: number;
offset?: number;
- orderBy?: OrgIdentityOrderBy;
+ orderBy?: OrgIdentitySearchOrderBy;
orderDirection?: OrderByDirection;
scope: SearchIdentitiesScope[];
searchFilter?: Partial<{