fix: permission failed
This commit is contained in:
parent
859b733245
commit
94cb990b9c
1 changed files with 22 additions and 19 deletions
|
|
@ -470,7 +470,7 @@ export class UserController extends Controller {
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
}),
|
}),
|
||||||
prisma.branch.findMany({
|
prisma.branch.findMany({
|
||||||
include: { user: { where: { id: req.user.sub } } },
|
include: { user: { where: { userId: req.user.sub } } },
|
||||||
where: {
|
where: {
|
||||||
id: {
|
id: {
|
||||||
in: Array.isArray(body.branchId) ? body.branchId : body.branchId ? [body.branchId] : [],
|
in: Array.isArray(body.branchId) ? body.branchId : body.branchId ? [body.branchId] : [],
|
||||||
|
|
@ -515,10 +515,11 @@ export class UserController extends Controller {
|
||||||
const THROW_PERM_MSG = "You do not have permission to perform this action.";
|
const THROW_PERM_MSG = "You do not have permission to perform this action.";
|
||||||
const THROW_PERM_CODE = "noPermission";
|
const THROW_PERM_CODE = "noPermission";
|
||||||
|
|
||||||
if (setRoleIndex < userRoleIndex) {
|
if (setRoleIndex !== -1 && setRoleIndex < userRoleIndex) {
|
||||||
throw new HttpError(HttpStatus.FORBIDDEN, THROW_PERM_MSG, THROW_PERM_CODE);
|
throw new HttpError(HttpStatus.FORBIDDEN, THROW_PERM_MSG, THROW_PERM_CODE);
|
||||||
}
|
}
|
||||||
if (!globalAllow(req.user)) {
|
|
||||||
|
if (!globalAllow(req.user) && body.branchId) {
|
||||||
if (branch.some((v) => !v.user.find((v) => v.userId === req.user.sub))) {
|
if (branch.some((v) => !v.user.find((v) => v.userId === req.user.sub))) {
|
||||||
throw new HttpError(HttpStatus.FORBIDDEN, THROW_PERM_MSG, THROW_PERM_CODE);
|
throw new HttpError(HttpStatus.FORBIDDEN, THROW_PERM_MSG, THROW_PERM_CODE);
|
||||||
}
|
}
|
||||||
|
|
@ -542,7 +543,8 @@ export class UserController extends Controller {
|
||||||
|
|
||||||
const role = list.find((v) => v.name === body.userRole);
|
const role = list.find((v) => v.name === body.userRole);
|
||||||
|
|
||||||
const resultAddRole = role && (await addUserRoles(userId, [role]));
|
if (role) {
|
||||||
|
const resultAddRole = await addUserRoles(userId, [role]);
|
||||||
|
|
||||||
if (!resultAddRole) {
|
if (!resultAddRole) {
|
||||||
throw new Error("Failed. Cannot set user's role.");
|
throw new Error("Failed. Cannot set user's role.");
|
||||||
|
|
@ -561,6 +563,7 @@ export class UserController extends Controller {
|
||||||
|
|
||||||
userRole = role.name;
|
userRole = role.name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (body.username) {
|
if (body.username) {
|
||||||
await editUser(userId, { username: body.username, enabled: body.status !== "INACTIVE" });
|
await editUser(userId, { username: body.username, enabled: body.status !== "INACTIVE" });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue