mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-15 01:16:38 +00:00
🚧 WIP
This commit is contained in:
107
server/private/routers/authPage/getOrgAuthPage.ts
Normal file
107
server/private/routers/authPage/getOrgAuthPage.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
/*
|
||||
* This file is part of a proprietary work.
|
||||
*
|
||||
* Copyright (c) 2025 Fossorial, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is licensed under the Fossorial Commercial License.
|
||||
* You may not use this file except in compliance with the License.
|
||||
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||
*
|
||||
* This file is not licensed under the AGPLv3.
|
||||
*/
|
||||
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { z } from "zod";
|
||||
import { db, orgAuthPages } from "@server/db";
|
||||
import { orgs } from "@server/db";
|
||||
import response from "@server/lib/response";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
import createResponseBodySchema from "@server/lib/createResponseBodySchema";
|
||||
|
||||
const getOrgAuthPageParamsSchema = z
|
||||
.object({
|
||||
orgId: z.string()
|
||||
})
|
||||
.strict();
|
||||
|
||||
const reponseSchema = createResponseBodySchema(
|
||||
z
|
||||
.object({
|
||||
logoUrl: z.string().url(),
|
||||
logoWidth: z.number().min(1),
|
||||
logoHeight: z.number().min(1),
|
||||
title: z.string(),
|
||||
subtitle: z.string().optional(),
|
||||
resourceTitle: z.string(),
|
||||
resourceSubtitle: z.string().optional()
|
||||
})
|
||||
.strict()
|
||||
);
|
||||
|
||||
export type GetOrgAuthPageResponse = z.infer<typeof reponseSchema>;
|
||||
|
||||
registry.registerPath({
|
||||
method: "get",
|
||||
path: "/org/{orgId}/auth-page",
|
||||
description: "Get an organization auth page",
|
||||
tags: [OpenAPITags.Org],
|
||||
request: {
|
||||
params: getOrgAuthPageParamsSchema
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
description: "",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: reponseSchema
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export async function getOrgAuthPage(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<any> {
|
||||
try {
|
||||
const parsedParams = getOrgAuthPageParamsSchema.safeParse(req.params);
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
fromError(parsedParams.error).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const { orgId } = parsedParams.data;
|
||||
|
||||
const [orgAuthPage] = await db
|
||||
.select()
|
||||
.from(orgAuthPages)
|
||||
.leftJoin(orgs, eq(orgs.orgId, orgAuthPages.orgId))
|
||||
.where(eq(orgs.orgId, orgId))
|
||||
.limit(1);
|
||||
|
||||
return response(res, {
|
||||
data: orgAuthPage?.orgAuthPages ?? null,
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Organization auth page retrieved successfully",
|
||||
status: HttpCode.OK
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return next(
|
||||
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||
);
|
||||
}
|
||||
}
|
||||
15
server/private/routers/authPage/index.ts
Normal file
15
server/private/routers/authPage/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This file is part of a proprietary work.
|
||||
*
|
||||
* Copyright (c) 2025 Fossorial, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is licensed under the Fossorial Commercial License.
|
||||
* You may not use this file except in compliance with the License.
|
||||
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||
*
|
||||
* This file is not licensed under the AGPLv3.
|
||||
*/
|
||||
|
||||
export * from "./updateOrgAuthPage";
|
||||
export * from "./getOrgAuthPage";
|
||||
141
server/private/routers/authPage/updateOrgAuthPage.ts
Normal file
141
server/private/routers/authPage/updateOrgAuthPage.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* This file is part of a proprietary work.
|
||||
*
|
||||
* Copyright (c) 2025 Fossorial, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is licensed under the Fossorial Commercial License.
|
||||
* You may not use this file except in compliance with the License.
|
||||
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||
*
|
||||
* This file is not licensed under the AGPLv3.
|
||||
*/
|
||||
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { z } from "zod";
|
||||
import { db, orgAuthPages } from "@server/db";
|
||||
import response from "@server/lib/response";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
import createResponseBodySchema from "@server/lib/createResponseBodySchema";
|
||||
|
||||
const updateOrgAuthPageParamsSchema = z
|
||||
.object({
|
||||
orgId: z.string()
|
||||
})
|
||||
.strict();
|
||||
|
||||
const updateOrgAuthPageBodySchema = z
|
||||
.object({
|
||||
logoUrl: z.string().url(),
|
||||
logoWidth: z.number().min(1),
|
||||
logoHeight: z.number().min(1),
|
||||
title: z.string(),
|
||||
subtitle: z.string().optional(),
|
||||
resourceTitle: z.string(),
|
||||
resourceSubtitle: z.string().optional()
|
||||
})
|
||||
.strict();
|
||||
|
||||
const reponseSchema = createResponseBodySchema(updateOrgAuthPageBodySchema);
|
||||
|
||||
export type UpdateOrgAuthPageResponse = z.infer<typeof reponseSchema>;
|
||||
|
||||
registry.registerPath({
|
||||
method: "put",
|
||||
path: "/org/{orgId}/auth-page",
|
||||
description: "Update an organization auth page",
|
||||
tags: [OpenAPITags.Org],
|
||||
request: {
|
||||
params: updateOrgAuthPageParamsSchema,
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: updateOrgAuthPageBodySchema
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
description: "",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: reponseSchema
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export async function updateOrgAuthPage(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<any> {
|
||||
try {
|
||||
const parsedParams = updateOrgAuthPageParamsSchema.safeParse(
|
||||
req.params
|
||||
);
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
fromError(parsedParams.error).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const parsedBody = updateOrgAuthPageBodySchema.safeParse(req.body);
|
||||
if (!parsedBody.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
fromError(parsedBody.error).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const { orgId } = parsedParams.data;
|
||||
const body = parsedBody.data;
|
||||
|
||||
const updatedOrgAuthPages = await db
|
||||
.insert(orgAuthPages)
|
||||
.values({
|
||||
...body,
|
||||
orgId
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: orgAuthPages.orgId,
|
||||
set: {
|
||||
...body
|
||||
}
|
||||
})
|
||||
.returning();
|
||||
|
||||
if (updatedOrgAuthPages.length === 0) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.NOT_FOUND,
|
||||
`Organization with ID ${orgId} not found`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return response(res, {
|
||||
data: updatedOrgAuthPages[0],
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Organization auth page updated successfully",
|
||||
status: HttpCode.OK
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return next(
|
||||
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import * as billing from "#private/routers/billing";
|
||||
import * as remoteExitNode from "#private/routers/remoteExitNode";
|
||||
import * as loginPage from "#private/routers/loginPage";
|
||||
import * as orgIdp from "#private/routers/orgIdp";
|
||||
import * as authPage from "#private/routers/authPage";
|
||||
import * as domain from "#private/routers/domain";
|
||||
import * as auth from "#private/routers/auth";
|
||||
import * as license from "#private/routers/license";
|
||||
@@ -403,3 +404,23 @@ authenticated.get(
|
||||
logActionAudit(ActionsEnum.exportLogs),
|
||||
logs.exportAccessAuditLogs
|
||||
);
|
||||
|
||||
authenticated.put(
|
||||
"/org/:orgId/auth-page",
|
||||
verifyValidLicense,
|
||||
verifyValidSubscription,
|
||||
verifyOrgAccess,
|
||||
verifyUserHasAction(ActionsEnum.updateOrgAuthPage),
|
||||
logActionAudit(ActionsEnum.updateOrgAuthPage),
|
||||
authPage.updateOrgAuthPage
|
||||
);
|
||||
|
||||
authenticated.get(
|
||||
"/org/:orgId/auth-page",
|
||||
verifyValidLicense,
|
||||
verifyValidSubscription,
|
||||
verifyOrgAccess,
|
||||
verifyUserHasAction(ActionsEnum.getOrgAuthPage),
|
||||
logActionAudit(ActionsEnum.getOrgAuthPage),
|
||||
authPage.getOrgAuthPage
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user