refactor: separate function
This commit is contained in:
parent
05a959ee55
commit
42cce880cd
3 changed files with 7 additions and 7 deletions
|
|
@ -19,6 +19,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import minio, { presignedGetObjectIfExist } from "../services/minio";
|
import minio, { presignedGetObjectIfExist } from "../services/minio";
|
||||||
|
import { isSystem } from "../utils/keycloak";
|
||||||
|
|
||||||
if (!process.env.MINIO_BUCKET) {
|
if (!process.env.MINIO_BUCKET) {
|
||||||
throw Error("Require MinIO bucket.");
|
throw Error("Require MinIO bucket.");
|
||||||
|
|
@ -27,10 +28,6 @@ if (!process.env.MINIO_BUCKET) {
|
||||||
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin"];
|
const MANAGE_ROLES = ["system", "head_of_admin"];
|
||||||
|
|
||||||
function isSystem(user: RequestWithUser["user"]) {
|
|
||||||
return user.roles.includes("system");
|
|
||||||
}
|
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
return MANAGE_ROLES.some((v) => user.roles?.includes(v));
|
return MANAGE_ROLES.some((v) => user.roles?.includes(v));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import {
|
||||||
getUserRoles,
|
getUserRoles,
|
||||||
removeUserRoles,
|
removeUserRoles,
|
||||||
} from "../services/keycloak";
|
} from "../services/keycloak";
|
||||||
|
import { isSystem } from "../utils/keycloak";
|
||||||
|
|
||||||
if (!process.env.MINIO_BUCKET) {
|
if (!process.env.MINIO_BUCKET) {
|
||||||
throw Error("Require MinIO bucket.");
|
throw Error("Require MinIO bucket.");
|
||||||
|
|
@ -36,9 +37,6 @@ if (!process.env.MINIO_BUCKET) {
|
||||||
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "branch_manager"];
|
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "branch_manager"];
|
||||||
|
|
||||||
function isSystem(user: RequestWithUser["user"]) {
|
|
||||||
return user.roles.includes("system");
|
|
||||||
}
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const listAllowed = ["system", "head_of_admin"];
|
const listAllowed = ["system", "head_of_admin"];
|
||||||
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
|
|
|
||||||
5
src/utils/keycloak.ts
Normal file
5
src/utils/keycloak.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
|
|
||||||
|
export function isSystem(user: RequestWithUser["user"]) {
|
||||||
|
return user.roles.includes("system");
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue