mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Fix: Requested changes
This commit is contained in:
@@ -458,7 +458,6 @@ export const registerRoutes = async (
|
||||
userDAL,
|
||||
authService: loginService,
|
||||
serverCfgDAL: superAdminDAL,
|
||||
orgDAL,
|
||||
orgService,
|
||||
keyStore
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
trustSamlEmails: z.boolean().optional(),
|
||||
trustLdapEmails: z.boolean().optional(),
|
||||
trustOidcEmails: z.boolean().optional(),
|
||||
defaultAuthOrgSlug: z.string().optional().nullable()
|
||||
defaultAuthOrgId: z.string().optional().nullable()
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName, TSuperAdmin } from "@app/db/schemas";
|
||||
import { TableName, TSuperAdmin, TSuperAdminUpdate } from "@app/db/schemas";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
|
||||
export type TSuperAdminDALFactory = ReturnType<typeof superAdminDALFactory>;
|
||||
|
||||
export const superAdminDALFactory = (db: TDbClient) => {
|
||||
const orm = ormify(db, TableName.SuperAdmin);
|
||||
const superAdminOrm = ormify(db, TableName.SuperAdmin);
|
||||
|
||||
const findById = async (id: string) => {
|
||||
const config = await db(TableName.SuperAdmin)
|
||||
const findById = async (id: string, tx?: Knex) => {
|
||||
const config = await (tx || db)(TableName.SuperAdmin)
|
||||
.where(`${TableName.SuperAdmin}.id`, id)
|
||||
.leftJoin(TableName.Organization, `${TableName.SuperAdmin}.defaultAuthOrgId`, `${TableName.Organization}.id`)
|
||||
.select(
|
||||
@@ -23,8 +25,20 @@ export const superAdminDALFactory = (db: TDbClient) => {
|
||||
} as TSuperAdmin & { defaultAuthOrgSlug: string | null };
|
||||
};
|
||||
|
||||
const updateById = async (id: string, data: TSuperAdminUpdate, tx?: Knex) => {
|
||||
const updatedConfig = await superAdminOrm.transaction(async (trx) => {
|
||||
await superAdminOrm.updateById(id, data, tx || trx);
|
||||
const config = await findById(id, tx || trx);
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
return updatedConfig;
|
||||
};
|
||||
|
||||
return {
|
||||
...orm,
|
||||
findById
|
||||
...superAdminOrm,
|
||||
findById,
|
||||
updateById
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
import bcrypt from "bcrypt";
|
||||
|
||||
import { TOrganizations, TSuperAdmin } from "@app/db/schemas";
|
||||
import { TSuperAdmin, TSuperAdminUpdate } from "@app/db/schemas";
|
||||
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
||||
import { getConfig } from "@app/lib/config/env";
|
||||
import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
||||
import { getUserPrivateKey } from "@app/lib/crypto/srp";
|
||||
import { BadRequestError } from "@app/lib/errors";
|
||||
import { omit } from "@app/lib/fn";
|
||||
|
||||
import { TAuthLoginFactory } from "../auth/auth-login-service";
|
||||
import { AuthMethod } from "../auth/auth-type";
|
||||
import { TOrgDALFactory } from "../org/org-dal";
|
||||
import { TOrgServiceFactory } from "../org/org-service";
|
||||
import { TUserDALFactory } from "../user/user-dal";
|
||||
import { TSuperAdminDALFactory } from "./super-admin-dal";
|
||||
import { TAdminSignUpDTO, TUpdateServerCfgDTO } from "./super-admin-types";
|
||||
import { TAdminSignUpDTO } from "./super-admin-types";
|
||||
|
||||
type TSuperAdminServiceFactoryDep = {
|
||||
serverCfgDAL: TSuperAdminDALFactory;
|
||||
orgDAL: Pick<TOrgDALFactory, "findOne">;
|
||||
userDAL: TUserDALFactory;
|
||||
authService: Pick<TAuthLoginFactory, "generateUserTokens">;
|
||||
orgService: Pick<TOrgServiceFactory, "createOrganization">;
|
||||
@@ -36,7 +33,6 @@ const ADMIN_CONFIG_DB_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
export const superAdminServiceFactory = ({
|
||||
serverCfgDAL,
|
||||
orgDAL,
|
||||
userDAL,
|
||||
authService,
|
||||
orgService,
|
||||
@@ -76,33 +72,11 @@ export const superAdminServiceFactory = ({
|
||||
return newCfg;
|
||||
};
|
||||
|
||||
const updateServerCfg = async (data: TUpdateServerCfgDTO) => {
|
||||
let organization: TOrganizations | undefined;
|
||||
if (data.defaultAuthOrgSlug) {
|
||||
organization = await orgDAL.findOne({
|
||||
slug: data.defaultAuthOrgSlug
|
||||
});
|
||||
const updateServerCfg = async (data: TSuperAdminUpdate) => {
|
||||
const updatedServerCfg = await serverCfgDAL.updateById(ADMIN_CONFIG_DB_UUID, data);
|
||||
|
||||
if (!organization) {
|
||||
throw new BadRequestError({
|
||||
name: "Update server config",
|
||||
message: "Failed to find default organization"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const updatedServerCfg = await serverCfgDAL.updateById(ADMIN_CONFIG_DB_UUID, {
|
||||
...omit(data, ["defaultAuthOrgSlug"]),
|
||||
defaultAuthOrgId: organization?.id || null
|
||||
});
|
||||
|
||||
const result = {
|
||||
...updatedServerCfg,
|
||||
defaultAuthOrgSlug: organization?.slug || null
|
||||
};
|
||||
|
||||
await keyStore.setItemWithExpiry(ADMIN_CONFIG_KEY, ADMIN_CONFIG_KEY_EXP, JSON.stringify(result));
|
||||
return result;
|
||||
await keyStore.setItemWithExpiry(ADMIN_CONFIG_KEY, ADMIN_CONFIG_KEY_EXP, JSON.stringify(updatedServerCfg));
|
||||
return updatedServerCfg;
|
||||
};
|
||||
|
||||
const adminSignUp = async ({
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { TSuperAdminUpdate } from "@app/db/schemas";
|
||||
|
||||
export type TAdminSignUpDTO = {
|
||||
email: string;
|
||||
password: string;
|
||||
@@ -17,7 +15,3 @@ export type TAdminSignUpDTO = {
|
||||
ip: string;
|
||||
userAgent: string;
|
||||
};
|
||||
|
||||
export type TUpdateServerCfgDTO = Omit<TSuperAdminUpdate, "defaultAuthOrgId"> & {
|
||||
defaultAuthOrgSlug?: string | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user