feat: user permission on delete
This commit is contained in:
parent
2cd92b2234
commit
05a959ee55
1 changed files with 35 additions and 3 deletions
|
|
@ -681,15 +681,47 @@ export class UserController extends Controller {
|
||||||
createdBy: true,
|
createdBy: true,
|
||||||
updatedBy: true,
|
updatedBy: true,
|
||||||
branch: {
|
branch: {
|
||||||
|
include: {
|
||||||
|
branch: {
|
||||||
|
include: {
|
||||||
|
branch: {
|
||||||
|
include: {
|
||||||
|
headOffice: {
|
||||||
|
include: {
|
||||||
|
user: {
|
||||||
where: {
|
where: {
|
||||||
userId: req.user.sub,
|
userId: req.user.sub,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
where: {
|
||||||
|
userId: req.user.sub,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!globalAllow(req.user) && !record?.branch.some((v) => v.userId === req.user.sub)) {
|
if (
|
||||||
|
!isSystem(req.user) &&
|
||||||
|
record?.branch.some((v) => {
|
||||||
|
const allow = v.branch.user.some((u) => u.userId === req.user.sub);
|
||||||
|
if (!globalAllow(req.user) && !allow) {
|
||||||
|
return v.branch.branch.some((b) =>
|
||||||
|
b.headOffice?.user.some((u) => u.userId === req.user.sub),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatus.FORBIDDEN,
|
HttpStatus.FORBIDDEN,
|
||||||
"You do not have permission to perform this action.",
|
"You do not have permission to perform this action.",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue