mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
fix: backend check on the service layer
This commit is contained in:
parent
afbb1b6192
commit
dc33f3a7fc
@ -52,6 +52,7 @@ import {
|
||||
SYSTEM_USER_ID,
|
||||
type ProjectCreated,
|
||||
type IProjectOwnersReadModel,
|
||||
ADMIN,
|
||||
} from '../../types';
|
||||
import type {
|
||||
IProjectAccessModel,
|
||||
@ -838,16 +839,21 @@ export default class ProjectService {
|
||||
}
|
||||
|
||||
private async isAllowedToAddAccess(
|
||||
userAddingAccess: number,
|
||||
userAddingAccess: IAuditUser,
|
||||
projectId: string,
|
||||
rolesBeingAdded: number[],
|
||||
): Promise<boolean> {
|
||||
const userPermissions =
|
||||
await this.accessService.getPermissionsForUser(userAddingAccess);
|
||||
if (userPermissions.some(({ permission }) => permission === ADMIN)) {
|
||||
return true;
|
||||
}
|
||||
const userRoles = await this.accessService.getAllProjectRolesForUser(
|
||||
userAddingAccess,
|
||||
userAddingAccess.id,
|
||||
projectId,
|
||||
);
|
||||
if (
|
||||
this.isAdmin(userAddingAccess, userRoles) ||
|
||||
this.isAdmin(userAddingAccess.id, userRoles) ||
|
||||
this.isProjectOwner(userRoles, projectId)
|
||||
) {
|
||||
return true;
|
||||
@ -864,7 +870,7 @@ export default class ProjectService {
|
||||
users: number[],
|
||||
auditUser: IAuditUser,
|
||||
): Promise<void> {
|
||||
if (await this.isAllowedToAddAccess(auditUser.id, projectId, roles)) {
|
||||
if (await this.isAllowedToAddAccess(auditUser, projectId, roles)) {
|
||||
await this.accessService.addAccessToProject(
|
||||
roles,
|
||||
groups,
|
||||
@ -915,7 +921,7 @@ export default class ProjectService {
|
||||
await this.validateAtLeastOneOwner(projectId, ownerRole);
|
||||
}
|
||||
const isAllowedToAssignRoles = await this.isAllowedToAddAccess(
|
||||
auditUser.id,
|
||||
auditUser,
|
||||
projectId,
|
||||
newRoles,
|
||||
);
|
||||
@ -966,7 +972,7 @@ export default class ProjectService {
|
||||
await this.validateAtLeastOneOwner(projectId, ownerRole);
|
||||
}
|
||||
const isAllowedToAssignRoles = await this.isAllowedToAddAccess(
|
||||
auditUser.id,
|
||||
auditUser,
|
||||
projectId,
|
||||
newRoles,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user