From d839ac3fe7a95d9ec115a2367bb795c3e95756da Mon Sep 17 00:00:00 2001 From: hbukvic Date: Thu, 14 Sep 2023 17:25:02 +0200 Subject: [PATCH 1/3] adds role validation --- .../video-conference/service/video-conference.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/server/src/modules/video-conference/service/video-conference.service.ts b/apps/server/src/modules/video-conference/service/video-conference.service.ts index eec64d1bd4a..51182e30439 100644 --- a/apps/server/src/modules/video-conference/service/video-conference.service.ts +++ b/apps/server/src/modules/video-conference/service/video-conference.service.ts @@ -64,6 +64,9 @@ export class VideoConferenceService { case VideoConferenceScope.COURSE: { const user: UserDO = await this.userService.findById(userId); isExpert = this.existsExpertRole(user.roles); + if (isExpert && user.roles.length > 1) { + isExpert = false; + } return isExpert; } case VideoConferenceScope.EVENT: { From ed459a1471e7dbe4959448948728214c97dbd8b2 Mon Sep 17 00:00:00 2001 From: hbukvic Date: Fri, 15 Sep 2023 13:43:15 +0200 Subject: [PATCH 2/3] adds test --- .../service/video-conference.service.spec.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts b/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts index 9136724d3d7..1fcc547a225 100644 --- a/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts +++ b/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts @@ -203,6 +203,35 @@ describe('VideoConferenceService', () => { }); }); + describe('when user has the EXPERT role and an additional role for a course conference', () => { + const setup = () => { + const user: UserDO = userDoFactory + .withRoles([ + { id: new ObjectId().toHexString(), name: RoleName.STUDENT }, + { id: new ObjectId().toHexString(), name: RoleName.EXPERT }, + ]) + .buildWithId(); + const userId = user.id as EntityId; + const scopeId = new ObjectId().toHexString(); + + userService.findById.mockResolvedValue(user); + + return { + userId, + scopeId, + }; + }; + + it('should return false', async () => { + const { userId, scopeId } = setup(); + + const result = await service.hasExpertRole(userId, VideoConferenceScope.COURSE, scopeId); + + expect(result).toBe(false); + expect(userService.findById).toHaveBeenCalledWith(userId); + }); + }); + describe('when conference scope is unknown', () => { const setup = () => { const user: UserDO = userDoFactory From e8fa41e439fcc40790d21fe318a05bbd3abab73d Mon Sep 17 00:00:00 2001 From: Arne Gnisa Date: Mon, 18 Sep 2023 15:12:17 +0200 Subject: [PATCH 3/3] N21-1268 some changes --- .../service/video-conference.service.spec.ts | 11 +++++++++-- .../service/video-conference.service.ts | 16 +++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts b/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts index 1fcc547a225..57c2cc988ec 100644 --- a/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts +++ b/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts @@ -29,7 +29,7 @@ import { NotFoundException } from '@nestjs/common/exceptions/not-found.exception import { teamUserFactory } from '@shared/testing/factory/teamuser.factory'; import { CourseService } from '@src/modules/learnroom/service/course.service'; import { VideoConferenceService } from './video-conference.service'; -import { ErrorStatus } from '../error/error-status.enum'; +import { ErrorStatus } from '../error'; import { BBBRole } from '../bbb'; import { IScopeInfo, ScopeRef, VideoConferenceState } from '../uc/dto'; import { IVideoConferenceSettings, VideoConferenceOptions, VideoConferenceSettings } from '../interface'; @@ -193,13 +193,20 @@ describe('VideoConferenceService', () => { }; }; + it('should call the user service to find the user by id', async () => { + const { userId, scopeId } = setup(); + + await service.hasExpertRole(userId, VideoConferenceScope.COURSE, scopeId); + + expect(userService.findById).toHaveBeenCalledWith(userId); + }); + it('should return false', async () => { const { userId, scopeId } = setup(); const result = await service.hasExpertRole(userId, VideoConferenceScope.COURSE, scopeId); expect(result).toBe(false); - expect(userService.findById).toHaveBeenCalledWith(userId); }); }); diff --git a/apps/server/src/modules/video-conference/service/video-conference.service.ts b/apps/server/src/modules/video-conference/service/video-conference.service.ts index 51182e30439..c82823a106c 100644 --- a/apps/server/src/modules/video-conference/service/video-conference.service.ts +++ b/apps/server/src/modules/video-conference/service/video-conference.service.ts @@ -25,7 +25,7 @@ import { CourseService } from '@src/modules/learnroom/service/course.service'; import { SchoolService } from '@src/modules/school'; import { UserService } from '@src/modules/user'; import { BBBRole } from '../bbb'; -import { ErrorStatus } from '../error/error-status.enum'; +import { ErrorStatus } from '../error'; import { IVideoConferenceSettings, VideoConferenceOptions, VideoConferenceSettings } from '../interface'; import { PermissionScopeMapping } from '../mapper/video-conference.mapper'; import { IScopeInfo, VideoConferenceState } from '../uc/dto'; @@ -63,10 +63,8 @@ export class VideoConferenceService { switch (conferenceScope) { case VideoConferenceScope.COURSE: { const user: UserDO = await this.userService.findById(userId); - isExpert = this.existsExpertRole(user.roles); - if (isExpert && user.roles.length > 1) { - isExpert = false; - } + isExpert = this.existsOnlyExpertRole(user.roles); + return isExpert; } case VideoConferenceScope.EVENT: { @@ -87,10 +85,14 @@ export class VideoConferenceService { } } - private existsExpertRole(roles: RoleReference[]): boolean { + private existsOnlyExpertRole(roles: RoleReference[]): boolean { const roleNames: RoleName[] = roles.map((role: RoleReference) => role.name); - const isExpert: boolean = roleNames.includes(RoleName.EXPERT); + let isExpert: boolean = roleNames.includes(RoleName.EXPERT); + + if (isExpert && roles.length > 1) { + isExpert = false; + } return isExpert; }