mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Updated "defaultOrgId" and "defaultOrgSlug" to "defaultAuthOrgId" and "defaultAuthOrgSlug"
This commit is contained in:
@@ -2,26 +2,26 @@ import { Knex } from "knex";
|
||||
|
||||
import { TableName } from "../schemas";
|
||||
|
||||
const DEFAULT_ORG_ID_FIELD = "defaultOrgId";
|
||||
const DEFAULT_AUTH_ORG_ID_FIELD = "defaultAuthOrgId";
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
const hasDefaultOrgColumn = await knex.schema.hasColumn(TableName.SuperAdmin, DEFAULT_ORG_ID_FIELD);
|
||||
const hasDefaultOrgColumn = await knex.schema.hasColumn(TableName.SuperAdmin, DEFAULT_AUTH_ORG_ID_FIELD);
|
||||
|
||||
await knex.schema.alterTable(TableName.SuperAdmin, (t) => {
|
||||
if (!hasDefaultOrgColumn) {
|
||||
t.uuid(DEFAULT_ORG_ID_FIELD).nullable();
|
||||
t.foreign(DEFAULT_ORG_ID_FIELD).references("id").inTable(TableName.Organization).onDelete("SET NULL");
|
||||
t.uuid(DEFAULT_AUTH_ORG_ID_FIELD).nullable();
|
||||
t.foreign(DEFAULT_AUTH_ORG_ID_FIELD).references("id").inTable(TableName.Organization).onDelete("SET NULL");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
const hasDefaultOrgColumn = await knex.schema.hasColumn(TableName.SuperAdmin, DEFAULT_ORG_ID_FIELD);
|
||||
const hasDefaultOrgColumn = await knex.schema.hasColumn(TableName.SuperAdmin, DEFAULT_AUTH_ORG_ID_FIELD);
|
||||
|
||||
await knex.schema.alterTable(TableName.SuperAdmin, (t) => {
|
||||
if (hasDefaultOrgColumn) {
|
||||
t.dropForeign([DEFAULT_ORG_ID_FIELD]);
|
||||
t.dropColumn(DEFAULT_ORG_ID_FIELD);
|
||||
t.dropForeign([DEFAULT_AUTH_ORG_ID_FIELD]);
|
||||
t.dropColumn(DEFAULT_AUTH_ORG_ID_FIELD);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export const SuperAdminSchema = z.object({
|
||||
trustSamlEmails: z.boolean().default(false).nullable().optional(),
|
||||
trustLdapEmails: z.boolean().default(false).nullable().optional(),
|
||||
trustOidcEmails: z.boolean().default(false).nullable().optional(),
|
||||
defaultOrgId: z.string().uuid().nullable().optional()
|
||||
defaultAuthOrgId: z.string().uuid().nullable().optional()
|
||||
});
|
||||
|
||||
export type TSuperAdmin = z.infer<typeof SuperAdminSchema>;
|
||||
|
||||
@@ -22,7 +22,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
200: z.object({
|
||||
config: SuperAdminSchema.omit({ createdAt: true, updatedAt: true }).extend({
|
||||
isMigrationModeOn: z.boolean(),
|
||||
defaultOrgSlug: z.string().nullable(),
|
||||
defaultAuthOrgSlug: z.string().nullable(),
|
||||
isSecretScanningDisabled: z.boolean()
|
||||
})
|
||||
})
|
||||
@@ -54,12 +54,12 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
trustSamlEmails: z.boolean().optional(),
|
||||
trustLdapEmails: z.boolean().optional(),
|
||||
trustOidcEmails: z.boolean().optional(),
|
||||
defaultOrgSlug: z.string().optional().nullable()
|
||||
defaultAuthOrgSlug: z.string().optional().nullable()
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
config: SuperAdminSchema.extend({
|
||||
defaultOrgSlug: z.string().nullable()
|
||||
defaultAuthOrgSlug: z.string().nullable()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,17 +10,17 @@ export const superAdminDALFactory = (db: TDbClient) => {
|
||||
const findById = async (id: string) => {
|
||||
const config = await db(TableName.SuperAdmin)
|
||||
.where(`${TableName.SuperAdmin}.id`, id)
|
||||
.leftJoin(TableName.Organization, `${TableName.SuperAdmin}.defaultOrgId`, `${TableName.Organization}.id`)
|
||||
.leftJoin(TableName.Organization, `${TableName.SuperAdmin}.defaultAuthOrgId`, `${TableName.Organization}.id`)
|
||||
.select(
|
||||
db.ref("*").withSchema(TableName.SuperAdmin) as unknown as keyof TSuperAdmin,
|
||||
db.ref("slug").withSchema(TableName.Organization).as("defaultOrgSlug")
|
||||
db.ref("slug").withSchema(TableName.Organization).as("defaultAuthOrgSlug")
|
||||
)
|
||||
.first();
|
||||
|
||||
return {
|
||||
defaultOrgSlug: config?.defaultOrgSlug || null,
|
||||
defaultAuthOrgSlug: config?.defaultAuthOrgSlug || null,
|
||||
...config
|
||||
} as TSuperAdmin & { defaultOrgSlug: string | null };
|
||||
} as TSuperAdmin & { defaultAuthOrgSlug: string | null };
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -28,7 +28,7 @@ type TSuperAdminServiceFactoryDep = {
|
||||
export type TSuperAdminServiceFactory = ReturnType<typeof superAdminServiceFactory>;
|
||||
|
||||
// eslint-disable-next-line
|
||||
export let getServerCfg: () => Promise<TSuperAdmin & { defaultOrgSlug: string | null }>;
|
||||
export let getServerCfg: () => Promise<TSuperAdmin & { defaultAuthOrgSlug: string | null }>;
|
||||
|
||||
const ADMIN_CONFIG_KEY = "infisical-admin-cfg";
|
||||
const ADMIN_CONFIG_KEY_EXP = 60; // 60s
|
||||
@@ -57,7 +57,7 @@ export const superAdminServiceFactory = ({
|
||||
return serverCfg;
|
||||
}
|
||||
|
||||
const keyStoreServerCfg = JSON.parse(config) as TSuperAdmin & { defaultOrgSlug: string | null };
|
||||
const keyStoreServerCfg = JSON.parse(config) as TSuperAdmin & { defaultAuthOrgSlug: string | null };
|
||||
return {
|
||||
...keyStoreServerCfg,
|
||||
// this is to allow admin router to work
|
||||
@@ -78,9 +78,9 @@ export const superAdminServiceFactory = ({
|
||||
|
||||
const updateServerCfg = async (data: TUpdateServerCfgDTO) => {
|
||||
let organization: TOrganizations | undefined;
|
||||
if (data.defaultOrgSlug) {
|
||||
if (data.defaultAuthOrgSlug) {
|
||||
organization = await orgDAL.findOne({
|
||||
slug: data.defaultOrgSlug
|
||||
slug: data.defaultAuthOrgSlug
|
||||
});
|
||||
|
||||
if (!organization) {
|
||||
@@ -92,13 +92,13 @@ export const superAdminServiceFactory = ({
|
||||
}
|
||||
|
||||
const updatedServerCfg = await serverCfgDAL.updateById(ADMIN_CONFIG_DB_UUID, {
|
||||
...omit(data, ["defaultOrgSlug"]),
|
||||
defaultOrgId: organization?.id || null
|
||||
...omit(data, ["defaultAuthOrgSlug"]),
|
||||
defaultAuthOrgId: organization?.id || null
|
||||
});
|
||||
|
||||
const result = {
|
||||
...updatedServerCfg,
|
||||
defaultOrgSlug: organization?.slug || null
|
||||
defaultAuthOrgSlug: organization?.slug || null
|
||||
};
|
||||
|
||||
await keyStore.setItemWithExpiry(ADMIN_CONFIG_KEY, ADMIN_CONFIG_KEY_EXP, JSON.stringify(result));
|
||||
|
||||
@@ -18,6 +18,6 @@ export type TAdminSignUpDTO = {
|
||||
userAgent: string;
|
||||
};
|
||||
|
||||
export type TUpdateServerCfgDTO = Omit<TSuperAdminUpdate, "defaultOrgId"> & {
|
||||
defaultOrgSlug?: string | null;
|
||||
export type TUpdateServerCfgDTO = Omit<TSuperAdminUpdate, "defaultAuthOrgId"> & {
|
||||
defaultAuthOrgSlug?: string | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user