mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 11:38:55 +00:00
refactor: move overview resource env determination logic to the client side to preserve ordering of resources
This commit is contained in:
@@ -411,14 +411,20 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
||||
.where("isReserved", false)
|
||||
.where((bd) => {
|
||||
if (search) {
|
||||
void bd.whereILike("name", `%${search}%`);
|
||||
void bd.whereILike(`${TableName.SecretFolder}.name`, `%${search}%`);
|
||||
}
|
||||
})
|
||||
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
||||
.select(
|
||||
selectAllTableCols(TableName.SecretFolder),
|
||||
db.raw(`DENSE_RANK() OVER (ORDER BY "name" ${orderDirection ?? OrderByDirection.ASC}) as rank`)
|
||||
db.raw(
|
||||
`DENSE_RANK() OVER (ORDER BY ${TableName.SecretFolder}."name" ${
|
||||
orderDirection ?? OrderByDirection.ASC
|
||||
}) as rank`
|
||||
),
|
||||
db.ref("slug").withSchema(TableName.Environment).as("environment")
|
||||
)
|
||||
.orderBy(orderBy, orderDirection);
|
||||
.orderBy(`${TableName.SecretFolder}.${orderBy}`, orderDirection);
|
||||
|
||||
if (limit) {
|
||||
const rankOffset = offset + 1; // ranks start from 1
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ForbiddenError, subject } from "@casl/ability";
|
||||
import path from "path";
|
||||
import { v4 as uuidv4, validate as uuidValidate } from "uuid";
|
||||
|
||||
import { TSecretFolders, TSecretFoldersInsert } from "@app/db/schemas";
|
||||
import { TSecretFoldersInsert } from "@app/db/schemas";
|
||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||
import { TSecretSnapshotServiceFactory } from "@app/ee/services/secret-snapshot/secret-snapshot-service";
|
||||
@@ -446,13 +446,12 @@ export const secretFolderServiceFactory = ({
|
||||
await permissionService.getProjectPermission(actor, actorId, projectId, actorAuthMethod, actorOrgId);
|
||||
|
||||
const envs = await projectEnvDAL.findBySlugs(projectId, environments);
|
||||
const data: { [key: string]: TSecretFolders[] } = {};
|
||||
|
||||
if (!envs.length)
|
||||
throw new BadRequestError({ message: "Environment(s) not found", name: "get project folder count" });
|
||||
|
||||
const parentFolders = await folderDAL.findBySecretPathMultiEnv(projectId, environments, secretPath);
|
||||
if (!parentFolders.length) return data;
|
||||
if (!parentFolders.length) return [];
|
||||
|
||||
const folders = await folderDAL.findByMultiEnv({
|
||||
environmentIds: envs.map((env) => env.id),
|
||||
@@ -460,14 +459,7 @@ export const secretFolderServiceFactory = ({
|
||||
...params
|
||||
});
|
||||
|
||||
// reorganize folders into respective envs
|
||||
const envMap: Map<string, string> = new Map(envs.map((env) => [env.id, env.slug]));
|
||||
folders.forEach((folder) => {
|
||||
const slug = envMap.get(folder.envId);
|
||||
data[slug!] = [...(data[slug!] ?? []), folder];
|
||||
});
|
||||
|
||||
return data;
|
||||
return folders;
|
||||
};
|
||||
|
||||
// get the unique count of folders within a project path
|
||||
|
||||
@@ -550,14 +550,8 @@ export const secretV2BridgeServiceFactory = ({
|
||||
|
||||
const folders = await folderDAL.findBySecretPathMultiEnv(projectId, environments, path);
|
||||
|
||||
const data: { [key: string]: typeof decryptedSecrets } = {};
|
||||
|
||||
if (!folders.length) {
|
||||
environments.forEach((env) => {
|
||||
data[env] = [];
|
||||
});
|
||||
|
||||
return data;
|
||||
return [];
|
||||
}
|
||||
|
||||
paths = folders.map((folder) => ({ folderId: folder.id, path, environment: folder.environment.slug }));
|
||||
@@ -593,11 +587,7 @@ export const secretV2BridgeServiceFactory = ({
|
||||
)
|
||||
);
|
||||
|
||||
decryptedSecrets.forEach((secret) => {
|
||||
data[secret.environment] = [...(data[secret.environment] ?? []), secret];
|
||||
});
|
||||
|
||||
return data;
|
||||
return decryptedSecrets;
|
||||
};
|
||||
|
||||
const getSecrets = async ({
|
||||
|
||||
Reference in New Issue
Block a user