mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-24 05:31:19 +10:00
prevent admin role from managing owner role (backend)
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
|
ForbiddenException,
|
||||||
Injectable,
|
Injectable,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
@ -217,11 +218,21 @@ export class WorkspaceService {
|
|||||||
) {
|
) {
|
||||||
const user = await this.userRepo.findById(userRoleDto.userId, workspaceId);
|
const user = await this.userRepo.findById(userRoleDto.userId, workspaceId);
|
||||||
|
|
||||||
|
const newRole = userRoleDto.role.toLowerCase();
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new BadRequestException('Workspace member not found');
|
throw new BadRequestException('Workspace member not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.role === userRoleDto.role) {
|
// prevent ADMIN from managing OWNER role
|
||||||
|
if (
|
||||||
|
(authUser.role === UserRole.ADMIN && newRole === UserRole.OWNER) ||
|
||||||
|
(authUser.role === UserRole.ADMIN && user.role === UserRole.OWNER)
|
||||||
|
) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.role === newRole) {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +249,7 @@ export class WorkspaceService {
|
|||||||
|
|
||||||
await this.userRepo.updateUser(
|
await this.userRepo.updateUser(
|
||||||
{
|
{
|
||||||
role: userRoleDto.role,
|
role: newRole,
|
||||||
},
|
},
|
||||||
user.id,
|
user.id,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
|
|||||||
Reference in New Issue
Block a user