Merge branch 'dev/front-methapon' into dev/front

This commit is contained in:
Methapon2001 2023-11-29 17:18:42 +07:00
commit da29ceecf1
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
6 changed files with 22 additions and 6 deletions

View file

@ -31,7 +31,15 @@ const router = createRouter({
beforeEnter: async (_to, _from, next) => {
const token = await getToken()
if (token) return next()
if (token) {
const roles = getRole()
if (token && roles.includes('admin')) {
return next()
}
return next('/')
}
await login(async () => {
const token = await getToken()

View file

@ -138,7 +138,8 @@ export class CabinetController extends Controller {
await esClient.update({
index: DEFAULT_INDEX!,
id: data._id,
doc: { pathname: destination },
doc: { pathname: destination, path },
refresh: "wait_for",
});
await minioClient.removeObject(DEFAULT_BUCKET!, current.name);

View file

@ -157,7 +157,8 @@ export class DrawerController extends Controller {
await esClient.update({
index: DEFAULT_INDEX!,
id: data._id,
doc: { pathname: destination },
doc: { pathname: destination, path },
refresh: "wait_for",
});
await minioClient.removeObject(DEFAULT_BUCKET!, current.name);

View file

@ -164,7 +164,8 @@ export class FolderController extends Controller {
await esClient.update({
index: DEFAULT_INDEX!,
id: data._id,
doc: { pathname: destination },
doc: { pathname: destination, path },
refresh: "wait_for",
});
await minioClient.removeObject(DEFAULT_BUCKET!, current.name);

View file

@ -165,7 +165,8 @@ export class SubFolderController extends Controller {
await esClient.update({
index: DEFAULT_INDEX!,
id: data._id,
doc: { pathname: destination },
doc: { pathname: destination, path },
refresh: "wait_for",
});
await minioClient.removeObject(DEFAULT_BUCKET!, current.name);

View file

@ -35,7 +35,11 @@ export async function expressAuthentication(
throw new HttpError(HttpStatusCode.UNAUTHORIZED, "Invalid token provided.");
}
if (scopes && !scopes.some((v) => payload.resource_access[payload.azp].roles.includes(v))) {
if (
scopes &&
scopes.length > 0 &&
scopes.some((v) => !payload.resource_access[payload.azp].roles.includes(v))
) {
throw new HttpError(HttpStatusCode.FORBIDDEN, "You are not allowed to perform this action.");
}