-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BC-8168 - Implementing video conferences in FE and remaining issues #5420
base: main
Are you sure you want to change the base?
Changes from 5 commits
497048b
3a9c0c1
f9f1cab
e360d90
8b37d4e
96ce039
9cee1eb
577941f
3d5ae27
6275e01
84a46f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,25 +2,42 @@ import { BoardExternalReference, BoardExternalReferenceType, BoardNodeService, C | |
import { CourseService } from '@modules/learnroom'; | ||
import { RoomService } from '@modules/room'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { EntityId } from '@shared/domain/types'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { CourseFeatures } from '@shared/domain/entity'; | ||
import { EntityId, SchoolFeature } from '@shared/domain/types'; | ||
import { BoardFeature } from '../board/domain'; | ||
import { LegacySchoolService } from '../legacy-school'; | ||
import { VideoConferenceConfig } from '../video-conference'; | ||
|
||
@Injectable() | ||
export class BoardContextApiHelperService { | ||
constructor( | ||
private readonly courseService: CourseService, | ||
private readonly roomService: RoomService, | ||
private readonly boardNodeService: BoardNodeService | ||
private readonly boardNodeService: BoardNodeService, | ||
private readonly legacySchoolService: LegacySchoolService, | ||
private readonly configService: ConfigService<VideoConferenceConfig, true> | ||
) {} | ||
|
||
public async getSchoolIdForBoardNode(nodeId: EntityId): Promise<EntityId> { | ||
const boardNode = await this.boardNodeService.findById(nodeId); | ||
const board = await this.boardNodeService.findRoot(boardNode); | ||
const columnBoard = await this.boardNodeService.findByClassAndId(ColumnBoard, board.id); | ||
const schoolId = await this.getSchoolIdForBoard(columnBoard.context); | ||
const boardContext = await this.getBoardContext(nodeId); | ||
const schoolId = await this.getSchoolIdForBoardContext(boardContext); | ||
return schoolId; | ||
} | ||
|
||
private async getSchoolIdForBoard(context: BoardExternalReference): Promise<EntityId> { | ||
public async getFeaturesForBoardNode(nodeId: EntityId): Promise<BoardFeature[]> { | ||
const boardContext = await this.getBoardContext(nodeId); | ||
const features = await this.getFeaturesForBoardContext(boardContext); | ||
return features; | ||
} | ||
|
||
private async getBoardContext(nodeId: EntityId): Promise<BoardExternalReference> { | ||
const boardNode = await this.boardNodeService.findById(nodeId, 0); | ||
const columnBoard = await this.boardNodeService.findByClassAndId(ColumnBoard, boardNode.rootId, 0); | ||
return columnBoard.context; | ||
} | ||
|
||
private async getSchoolIdForBoardContext(context: BoardExternalReference): Promise<EntityId> { | ||
if (context.type === BoardExternalReferenceType.Course) { | ||
const course = await this.courseService.findById(context.id); | ||
|
||
|
@@ -35,4 +52,47 @@ export class BoardContextApiHelperService { | |
/* istanbul ignore next */ | ||
throw new Error(`Unsupported board reference type ${context.type as string}`); | ||
} | ||
|
||
private async getFeaturesForBoardContext(context: BoardExternalReference): Promise<BoardFeature[]> { | ||
const features: BoardFeature[] = []; | ||
|
||
if (context.type === BoardExternalReferenceType.Course) { | ||
const course = await this.courseService.findById(context.id); | ||
|
||
if ( | ||
this.isVideoConferenceEnabledForCourse(course.features) || | ||
(await this.isVideoConferenceEnabledForSchool(course.school.id)) || | ||
this.isVideoConferenceEnabledForConfig() | ||
) { | ||
features.push(BoardFeature.VIDEOCONFERENCE); | ||
} | ||
|
||
return features; | ||
} | ||
|
||
if (context.type === BoardExternalReferenceType.Room) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering what Will that case ever happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const room = await this.roomService.getSingleRoom(context.id); | ||
|
||
if ((await this.isVideoConferenceEnabledForSchool(room.schoolId)) || this.isVideoConferenceEnabledForConfig()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also here we get the feature in both cases, even if its only activated for the instance, but not for the school, that does not sound right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, we should be able to deactivate the feature for the school even if it's enabled on the instance right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, and it should (for the example above) be able to be deactivated on course level, even if its activated on a school (and therefore on the instance) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
features.push(BoardFeature.VIDEOCONFERENCE); | ||
} | ||
|
||
return features; | ||
} | ||
|
||
/* istanbul ignore next */ | ||
throw new Error(`Unsupported board reference type ${context.type as string}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe throwing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
} | ||
|
||
private isVideoConferenceEnabledForCourse(courseFeatures?: CourseFeatures[]): boolean { | ||
return (courseFeatures ?? []).includes(CourseFeatures.VIDEOCONFERENCE); | ||
} | ||
|
||
private isVideoConferenceEnabledForSchool(schoolId: EntityId): Promise<boolean> { | ||
return this.legacySchoolService.hasFeature(schoolId, SchoolFeature.VIDEOCONFERENCE); | ||
} | ||
|
||
private isVideoConferenceEnabledForConfig(): boolean { | ||
return this.configService.get('FEATURE_VIDEOCONFERENCE_ENABLED'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will get the feature pushed into the array, even if only the school has VC activated, but the course has not, did I see that right? That would not be correct, as we could have the case, that VC are activated for the whole school, but not for the specific course. Could you validate my thought?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. See also test.