Refactor required route role

This commit is contained in:
Tom Moor
2024-04-06 21:43:15 -04:00
parent 79899d051c
commit b458bb3af9
8 changed files with 37 additions and 40 deletions

View File

@@ -1,4 +1,5 @@
import Router from "koa-router";
import { UserRole } from "@shared/types";
import auth from "@server/middlewares/authentication";
import { transaction } from "@server/middlewares/transaction";
import validate from "@server/middlewares/validate";
@@ -16,7 +17,7 @@ const router = new Router();
router.post(
"authenticationProviders.info",
auth({ admin: true }),
auth({ role: UserRole.Admin }),
validate(T.AuthenticationProvidersInfoSchema),
async (ctx: APIContext<T.AuthenticationProvidersInfoReq>) => {
const { id } = ctx.input.body;
@@ -34,7 +35,7 @@ router.post(
router.post(
"authenticationProviders.update",
auth({ admin: true }),
auth({ role: UserRole.Admin }),
validate(T.AuthenticationProvidersUpdateSchema),
transaction(),
async (ctx: APIContext<T.AuthenticationProvidersUpdateReq>) => {
@@ -79,7 +80,7 @@ router.post(
router.post(
"authenticationProviders.list",
auth({ admin: true }),
auth({ role: UserRole.Admin }),
async (ctx: APIContext) => {
const { user } = ctx.state.auth;
authorize(user, "read", user.team);