mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 10:05:53 +02:00
Add actions check to all endpoints
This commit is contained in:
parent
20db6d450c
commit
81017139c5
25 changed files with 232 additions and 34 deletions
|
@ -6,6 +6,7 @@ import { eq } from 'drizzle-orm';
|
|||
import response from "@server/utils/response";
|
||||
import HttpCode from '@server/types/HttpCode';
|
||||
import createHttpError from 'http-errors';
|
||||
import { ActionsEnum, checkUserActionPermission } from '@server/auth/actions';
|
||||
|
||||
const getOrgSchema = z.object({
|
||||
orgId: z.string().transform(Number).pipe(z.number().int().positive())
|
||||
|
@ -25,6 +26,12 @@ export async function getOrg(req: Request, res: Response, next: NextFunction): P
|
|||
|
||||
const { orgId } = parsedParams.data;
|
||||
|
||||
// Check if the user has permission to list sites
|
||||
const hasPermission = await checkUserActionPermission(ActionsEnum.getOrg, req);
|
||||
if (!hasPermission) {
|
||||
return next(createHttpError(HttpCode.FORBIDDEN, 'User does not have permission to list sites'));
|
||||
}
|
||||
|
||||
const org = await db.select()
|
||||
.from(orgs)
|
||||
.where(eq(orgs.orgId, orgId))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue