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;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
Tabs
|
||||
} from "@app/components/v2";
|
||||
import { useOrganization, useServerConfig, useUser } from "@app/context";
|
||||
import { useUpdateServerConfig } from "@app/hooks/api";
|
||||
import { useGetOrganizations, useUpdateServerConfig } from "@app/hooks/api";
|
||||
|
||||
import { RateLimitPanel } from "./RateLimitPanel";
|
||||
|
||||
@@ -41,7 +41,7 @@ const formSchema = z.object({
|
||||
trustSamlEmails: z.boolean(),
|
||||
trustLdapEmails: z.boolean(),
|
||||
trustOidcEmails: z.boolean(),
|
||||
defaultAuthOrgSlug: z.string().optional().nullable()
|
||||
defaultAuthOrgId: z.string()
|
||||
});
|
||||
|
||||
type TDashboardForm = z.infer<typeof formSchema>;
|
||||
@@ -64,7 +64,7 @@ export const AdminDashboardPage = () => {
|
||||
trustSamlEmails: config.trustSamlEmails,
|
||||
trustLdapEmails: config.trustLdapEmails,
|
||||
trustOidcEmails: config.trustOidcEmails,
|
||||
defaultAuthOrgSlug: config.defaultAuthOrgSlug
|
||||
defaultAuthOrgId: config.defaultAuthOrgId ?? ""
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,6 +74,8 @@ export const AdminDashboardPage = () => {
|
||||
const { orgs } = useOrganization();
|
||||
const { mutateAsync: updateServerConfig } = useUpdateServerConfig();
|
||||
|
||||
const organizations = useGetOrganizations();
|
||||
|
||||
const isNotAllowed = !user?.superAdmin;
|
||||
|
||||
// TODO(akhilmhdh): on nextjs 14 roadmap this will be properly addressed with context split
|
||||
@@ -94,11 +96,11 @@ export const AdminDashboardPage = () => {
|
||||
trustSamlEmails,
|
||||
trustLdapEmails,
|
||||
trustOidcEmails,
|
||||
defaultAuthOrgSlug
|
||||
defaultAuthOrgId
|
||||
} = formData;
|
||||
|
||||
await updateServerConfig({
|
||||
defaultAuthOrgSlug,
|
||||
defaultAuthOrgId: defaultAuthOrgId || null,
|
||||
allowSignUp: signUpMode !== SignUpModes.Disabled,
|
||||
allowedSignUpDomain: signUpMode === SignUpModes.Anyone ? allowedSignUpDomain : null,
|
||||
trustSamlEmails,
|
||||
@@ -155,13 +157,13 @@ export const AdminDashboardPage = () => {
|
||||
name="signUpMode"
|
||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
className="max-w-72 w-72"
|
||||
className="max-w-sm"
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error)}
|
||||
>
|
||||
<Select
|
||||
className="w-72 bg-mineshaft-700"
|
||||
dropdownContainerClassName="bg-mineshaft-700"
|
||||
className="w-full bg-mineshaft-700"
|
||||
dropdownContainerClassName="bg-mineshaft-800"
|
||||
defaultValue={field.value}
|
||||
onValueChange={(e) => onChange(e)}
|
||||
{...field}
|
||||
@@ -203,7 +205,7 @@ export const AdminDashboardPage = () => {
|
||||
|
||||
<div className="flex flex-col justify-start">
|
||||
<div className="mb-2 text-xl font-semibold text-mineshaft-100">
|
||||
Default organization slug
|
||||
Default organization
|
||||
</div>
|
||||
<div className="mb-4 max-w-sm text-sm text-mineshaft-400">
|
||||
Select the slug of the organization you want to set as default for SAML/LDAP
|
||||
@@ -212,16 +214,33 @@ export const AdminDashboardPage = () => {
|
||||
</div>
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="defaultAuthOrgSlug"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
name="defaultAuthOrgId"
|
||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Default organization slug"
|
||||
className="w-72"
|
||||
isError={Boolean(error)}
|
||||
className="max-w-sm"
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error)}
|
||||
>
|
||||
<Input {...field} value={field.value || ""} placeholder="acme-corp" />
|
||||
<Select
|
||||
className="w-full bg-mineshaft-700"
|
||||
dropdownContainerClassName="bg-mineshaft-800"
|
||||
defaultValue={field.value ?? " "}
|
||||
onValueChange={(e) => {
|
||||
if (e === " ") {
|
||||
onChange(null);
|
||||
} else {
|
||||
onChange(e);
|
||||
}
|
||||
}}
|
||||
{...field}
|
||||
>
|
||||
<SelectItem value=" ">Select organization...</SelectItem>
|
||||
{organizations.data?.map((org) => (
|
||||
<SelectItem key={org.id} value={org.id}>
|
||||
{org.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user