mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-16 09:56:36 +00:00
Merge dev into fix/log-analytics-adjustments
This commit is contained in:
@@ -15,9 +15,9 @@ import { FeatureId } from "@server/lib/billing";
|
||||
import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsForOrgs";
|
||||
|
||||
const acceptInviteBodySchema = z.strictObject({
|
||||
token: z.string(),
|
||||
inviteId: z.string()
|
||||
});
|
||||
token: z.string(),
|
||||
inviteId: z.string()
|
||||
});
|
||||
|
||||
export type AcceptInviteResponse = {
|
||||
accepted: boolean;
|
||||
|
||||
@@ -10,10 +10,10 @@ import { eq } from "drizzle-orm";
|
||||
import { fromError } from "zod-validation-error";
|
||||
|
||||
const addUserActionSchema = z.strictObject({
|
||||
userId: z.string(),
|
||||
actionId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
userId: z.string(),
|
||||
actionId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
export async function addUserAction(
|
||||
req: Request,
|
||||
|
||||
@@ -10,9 +10,9 @@ import { eq } from "drizzle-orm";
|
||||
import { fromError } from "zod-validation-error";
|
||||
|
||||
const addUserSiteSchema = z.strictObject({
|
||||
userId: z.string(),
|
||||
siteId: z.string().transform(Number).pipe(z.int().positive())
|
||||
});
|
||||
userId: z.string(),
|
||||
siteId: z.string().transform(Number).pipe(z.int().positive())
|
||||
});
|
||||
|
||||
export async function addUserSite(
|
||||
req: Request,
|
||||
@@ -61,7 +61,6 @@ export async function addUserSite(
|
||||
status: HttpCode.CREATED
|
||||
});
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return next(
|
||||
|
||||
@@ -19,7 +19,9 @@ const adminGeneratePasswordResetCodeSchema = z.strictObject({
|
||||
userId: z.string().min(1)
|
||||
});
|
||||
|
||||
export type AdminGeneratePasswordResetCodeBody = z.infer<typeof adminGeneratePasswordResetCodeSchema>;
|
||||
export type AdminGeneratePasswordResetCodeBody = z.infer<
|
||||
typeof adminGeneratePasswordResetCodeSchema
|
||||
>;
|
||||
|
||||
export type AdminGeneratePasswordResetCodeResponse = {
|
||||
token: string;
|
||||
@@ -32,7 +34,9 @@ export async function adminGeneratePasswordResetCode(
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<any> {
|
||||
const parsedParams = adminGeneratePasswordResetCodeSchema.safeParse(req.params);
|
||||
const parsedParams = adminGeneratePasswordResetCodeSchema.safeParse(
|
||||
req.params
|
||||
);
|
||||
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
@@ -52,12 +56,7 @@ export async function adminGeneratePasswordResetCode(
|
||||
.where(eq(users.userId, userId));
|
||||
|
||||
if (!existingUser || !existingUser.length) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.NOT_FOUND,
|
||||
"User not found"
|
||||
)
|
||||
);
|
||||
return next(createHttpError(HttpCode.NOT_FOUND, "User not found"));
|
||||
}
|
||||
|
||||
if (existingUser[0].type !== UserType.Internal) {
|
||||
@@ -122,4 +121,3 @@ export async function adminGeneratePasswordResetCode(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import logger from "@server/logger";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
|
||||
const adminGetUserSchema = z.strictObject({
|
||||
userId: z.string().min(1)
|
||||
});
|
||||
userId: z.string().min(1)
|
||||
});
|
||||
|
||||
registry.registerPath({
|
||||
method: "get",
|
||||
|
||||
@@ -10,19 +10,19 @@ import { idp, users } from "@server/db";
|
||||
import { fromZodError } from "zod-validation-error";
|
||||
|
||||
const listUsersSchema = z.strictObject({
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
});
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
});
|
||||
|
||||
async function queryUsers(limit: number, offset: number) {
|
||||
return await db
|
||||
|
||||
@@ -11,12 +11,12 @@ import { fromError } from "zod-validation-error";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
|
||||
const updateUser2FAParamsSchema = z.strictObject({
|
||||
userId: z.string()
|
||||
});
|
||||
userId: z.string()
|
||||
});
|
||||
|
||||
const updateUser2FABodySchema = z.strictObject({
|
||||
twoFactorSetupRequested: z.boolean()
|
||||
});
|
||||
twoFactorSetupRequested: z.boolean()
|
||||
});
|
||||
|
||||
export type UpdateUser2FAResponse = {
|
||||
userId: string;
|
||||
@@ -90,13 +90,15 @@ export async function updateUser2FA(
|
||||
);
|
||||
}
|
||||
|
||||
logger.debug(`Updating 2FA for user ${userId} to ${twoFactorSetupRequested}`);
|
||||
logger.debug(
|
||||
`Updating 2FA for user ${userId} to ${twoFactorSetupRequested}`
|
||||
);
|
||||
|
||||
if (twoFactorSetupRequested) {
|
||||
await db
|
||||
.update(users)
|
||||
.set({
|
||||
twoFactorSetupRequested: true,
|
||||
twoFactorSetupRequested: true
|
||||
})
|
||||
.where(eq(users.userId, userId));
|
||||
} else {
|
||||
|
||||
@@ -18,25 +18,26 @@ import { TierId } from "@server/lib/billing/tiers";
|
||||
import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsForOrgs";
|
||||
|
||||
const paramsSchema = z.strictObject({
|
||||
orgId: z.string().nonempty()
|
||||
});
|
||||
orgId: z.string().nonempty()
|
||||
});
|
||||
|
||||
const bodySchema = z.strictObject({
|
||||
email: z.email()
|
||||
.toLowerCase()
|
||||
.optional()
|
||||
.refine((data) => {
|
||||
if (data) {
|
||||
return z.email().safeParse(data).success;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
username: z.string().nonempty().toLowerCase(),
|
||||
name: z.string().optional(),
|
||||
type: z.enum(["internal", "oidc"]).optional(),
|
||||
idpId: z.number().optional(),
|
||||
roleId: z.number()
|
||||
});
|
||||
email: z
|
||||
.email()
|
||||
.toLowerCase()
|
||||
.optional()
|
||||
.refine((data) => {
|
||||
if (data) {
|
||||
return z.email().safeParse(data).success;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
username: z.string().nonempty().toLowerCase(),
|
||||
name: z.string().optional(),
|
||||
type: z.enum(["internal", "oidc"]).optional(),
|
||||
idpId: z.number().optional(),
|
||||
roleId: z.number()
|
||||
});
|
||||
|
||||
export type CreateOrgUserResponse = {};
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ export type GetOrgUserResponse = NonNullable<
|
||||
>;
|
||||
|
||||
const getOrgUserParamsSchema = z.strictObject({
|
||||
userId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
userId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
registry.registerPath({
|
||||
method: "get",
|
||||
|
||||
@@ -22,16 +22,16 @@ import { build } from "@server/build";
|
||||
import cache from "@server/lib/cache";
|
||||
|
||||
const inviteUserParamsSchema = z.strictObject({
|
||||
orgId: z.string()
|
||||
});
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
const inviteUserBodySchema = z.strictObject({
|
||||
email: z.email().toLowerCase(),
|
||||
roleId: z.number(),
|
||||
validHours: z.number().gt(0).lte(168),
|
||||
sendEmail: z.boolean().optional(),
|
||||
regenerate: z.boolean().optional()
|
||||
});
|
||||
email: z.email().toLowerCase(),
|
||||
roleId: z.number(),
|
||||
validHours: z.number().gt(0).lte(168),
|
||||
sendEmail: z.boolean().optional(),
|
||||
regenerate: z.boolean().optional()
|
||||
});
|
||||
|
||||
export type InviteUserBody = z.infer<typeof inviteUserBodySchema>;
|
||||
|
||||
@@ -109,12 +109,7 @@ export async function inviteUser(
|
||||
const [role] = await db
|
||||
.select()
|
||||
.from(roles)
|
||||
.where(
|
||||
and(
|
||||
eq(roles.roleId, roleId),
|
||||
eq(roles.orgId, orgId)
|
||||
)
|
||||
)
|
||||
.where(and(eq(roles.roleId, roleId), eq(roles.orgId, orgId)))
|
||||
.limit(1);
|
||||
|
||||
if (!role) {
|
||||
|
||||
@@ -11,23 +11,23 @@ import { fromZodError } from "zod-validation-error";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
|
||||
const listInvitationsParamsSchema = z.strictObject({
|
||||
orgId: z.string()
|
||||
});
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
const listInvitationsQuerySchema = z.strictObject({
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
});
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
});
|
||||
|
||||
async function queryInvitations(orgId: string, limit: number, offset: number) {
|
||||
return await db
|
||||
|
||||
@@ -12,23 +12,23 @@ import { OpenAPITags, registry } from "@server/openApi";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
const listUsersParamsSchema = z.strictObject({
|
||||
orgId: z.string()
|
||||
});
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
const listUsersSchema = z.strictObject({
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
});
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
});
|
||||
|
||||
async function queryUsers(orgId: string, limit: number, offset: number) {
|
||||
return await db
|
||||
@@ -48,7 +48,7 @@ async function queryUsers(orgId: string, limit: number, offset: number) {
|
||||
idpId: users.idpId,
|
||||
idpType: idp.type,
|
||||
idpVariant: idpOidcConfig.variant,
|
||||
twoFactorEnabled: users.twoFactorEnabled,
|
||||
twoFactorEnabled: users.twoFactorEnabled
|
||||
})
|
||||
.from(users)
|
||||
.leftJoin(userOrgs, eq(users.userId, userOrgs.userId))
|
||||
|
||||
@@ -10,9 +10,9 @@ import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
|
||||
const removeInvitationParamsSchema = z.strictObject({
|
||||
orgId: z.string(),
|
||||
inviteId: z.string()
|
||||
});
|
||||
orgId: z.string(),
|
||||
inviteId: z.string()
|
||||
});
|
||||
|
||||
export async function removeInvitation(
|
||||
req: Request,
|
||||
|
||||
@@ -10,13 +10,13 @@ import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
|
||||
const removeUserActionParamsSchema = z.strictObject({
|
||||
userId: z.string()
|
||||
});
|
||||
userId: z.string()
|
||||
});
|
||||
|
||||
const removeUserActionSchema = z.strictObject({
|
||||
actionId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
actionId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
export async function removeUserAction(
|
||||
req: Request,
|
||||
|
||||
@@ -16,9 +16,9 @@ import { UserType } from "@server/types/UserTypes";
|
||||
import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsForOrgs";
|
||||
|
||||
const removeUserSchema = z.strictObject({
|
||||
userId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
userId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
registry.registerPath({
|
||||
method: "delete",
|
||||
|
||||
@@ -10,12 +10,9 @@ import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
|
||||
const removeUserResourceSchema = z.strictObject({
|
||||
userId: z.string(),
|
||||
resourceId: z
|
||||
.string()
|
||||
.transform(Number)
|
||||
.pipe(z.int().positive())
|
||||
});
|
||||
userId: z.string(),
|
||||
resourceId: z.string().transform(Number).pipe(z.int().positive())
|
||||
});
|
||||
|
||||
export async function removeUserResource(
|
||||
req: Request,
|
||||
|
||||
@@ -10,12 +10,12 @@ import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
|
||||
const removeUserSiteParamsSchema = z.strictObject({
|
||||
userId: z.string()
|
||||
});
|
||||
userId: z.string()
|
||||
});
|
||||
|
||||
const removeUserSiteSchema = z.strictObject({
|
||||
siteId: z.int().positive()
|
||||
});
|
||||
siteId: z.int().positive()
|
||||
});
|
||||
|
||||
export async function removeUserSite(
|
||||
req: Request,
|
||||
|
||||
@@ -10,11 +10,12 @@ import { fromError } from "zod-validation-error";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
|
||||
const paramsSchema = z.strictObject({
|
||||
userId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
userId: z.string(),
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
const bodySchema = z.strictObject({
|
||||
const bodySchema = z
|
||||
.strictObject({
|
||||
autoProvisioned: z.boolean().optional()
|
||||
})
|
||||
.refine((data) => Object.keys(data).length > 0, {
|
||||
|
||||
Reference in New Issue
Block a user