diff --git a/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/auto-moin-schule-group-uuid.strategy.ts b/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/auto-moin-schule-group-uuid.strategy.ts new file mode 100644 index 00000000000..f9fe98e81d9 --- /dev/null +++ b/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/auto-moin-schule-group-uuid.strategy.ts @@ -0,0 +1,38 @@ +import { Injectable } from '@nestjs/common'; +import { CourseService } from '@modules/learnroom'; +import { ToolContextType } from '../../../common/enum'; +import { MissingToolParameterValueLoggableException } from '../../error'; +import { ContextExternalToolLaunchable } from '../../../context-external-tool/domain'; +import { SchoolExternalTool } from '../../../school-external-tool/domain'; +import { AutoParameterStrategy } from './auto-parameter.strategy'; + +@Injectable() +export class AutoMoinSchuleGroupUuidStrategy implements AutoParameterStrategy { + constructor(private readonly courseService: CourseService) {} + + async getValue( + _schoolExternalTool: SchoolExternalTool, + contextExternalTool: ContextExternalToolLaunchable + ): Promise { + if (contextExternalTool.contextRef.type !== ToolContextType.COURSE) { + return undefined; + } + + const courseId = contextExternalTool.contextRef.id; + const courseEntity = await this.courseService.findById(courseId); + const syncedGroup = courseEntity.syncedWithGroup; + + if (!syncedGroup) { + return undefined; + } + + const uuid = syncedGroup.externalSource?.externalId; + + if (!uuid) { + // TODO: think if a new special error is needed for this case + throw new MissingToolParameterValueLoggableException(contextExternalTool, []); + } + + return uuid; + } +} diff --git a/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/index.ts b/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/index.ts index 30f058547a1..780f72eab94 100644 --- a/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/index.ts +++ b/apps/server/src/modules/tool/tool-launch/service/auto-parameter-strategy/index.ts @@ -3,4 +3,5 @@ export * from './auto-school-id.strategy'; export * from './auto-context-id.strategy'; export * from './auto-context-name.strategy'; export * from './auto-school-number.strategy'; +export * from './auto-moin-schule-group-uuid.strategy'; export { AutoMediumIdStrategy } from './auto-medium-id.strategy'; diff --git a/apps/server/src/modules/tool/tool-launch/service/launch-strategy/abstract-launch.strategy.ts b/apps/server/src/modules/tool/tool-launch/service/launch-strategy/abstract-launch.strategy.ts index 9abfb4cf78c..42c4ea95249 100644 --- a/apps/server/src/modules/tool/tool-launch/service/launch-strategy/abstract-launch.strategy.ts +++ b/apps/server/src/modules/tool/tool-launch/service/launch-strategy/abstract-launch.strategy.ts @@ -16,6 +16,7 @@ import { AutoParameterStrategy, AutoSchoolIdStrategy, AutoSchoolNumberStrategy, + AutoMoinSchuleGroupUuidStrategy, } from '../auto-parameter-strategy'; import { ToolLaunchParams } from './tool-launch-params.interface'; import { ToolLaunchStrategy } from './tool-launch-strategy.interface'; @@ -29,7 +30,8 @@ export abstract class AbstractLaunchStrategy implements ToolLaunchStrategy { autoSchoolNumberStrategy: AutoSchoolNumberStrategy, autoContextIdStrategy: AutoContextIdStrategy, autoContextNameStrategy: AutoContextNameStrategy, - autoMediumIdStrategy: AutoMediumIdStrategy + autoMediumIdStrategy: AutoMediumIdStrategy, + autoMoinSchuleGroupUuidStrategy: AutoMoinSchuleGroupUuidStrategy ) { this.autoParameterStrategyMap = new Map([ [CustomParameterType.AUTO_SCHOOLID, autoSchoolIdStrategy], @@ -37,6 +39,7 @@ export abstract class AbstractLaunchStrategy implements ToolLaunchStrategy { [CustomParameterType.AUTO_CONTEXTID, autoContextIdStrategy], [CustomParameterType.AUTO_CONTEXTNAME, autoContextNameStrategy], [CustomParameterType.AUTO_MEDIUMID, autoMediumIdStrategy], + [CustomParameterType.AUTO_MOINSCHULE_GROUPUUID, autoMoinSchuleGroupUuidStrategy], ]); } diff --git a/apps/server/src/modules/tool/tool-launch/service/launch-strategy/lti11-tool-launch.strategy.ts b/apps/server/src/modules/tool/tool-launch/service/launch-strategy/lti11-tool-launch.strategy.ts index 30a601f6025..b054e00a600 100644 --- a/apps/server/src/modules/tool/tool-launch/service/launch-strategy/lti11-tool-launch.strategy.ts +++ b/apps/server/src/modules/tool/tool-launch/service/launch-strategy/lti11-tool-launch.strategy.ts @@ -16,6 +16,7 @@ import { AutoMediumIdStrategy, AutoSchoolIdStrategy, AutoSchoolNumberStrategy, + AutoMoinSchuleGroupUuidStrategy, } from '../auto-parameter-strategy'; import { Lti11EncryptionService } from '../lti11-encryption.service'; import { AbstractLaunchStrategy } from './abstract-launch.strategy'; @@ -31,14 +32,16 @@ export class Lti11ToolLaunchStrategy extends AbstractLaunchStrategy { autoSchoolNumberStrategy: AutoSchoolNumberStrategy, autoContextIdStrategy: AutoContextIdStrategy, autoContextNameStrategy: AutoContextNameStrategy, - autoMediumIdStrategy: AutoMediumIdStrategy + autoMediumIdStrategy: AutoMediumIdStrategy, + autoMoinSchuleGroupUuidStrategy: AutoMoinSchuleGroupUuidStrategy ) { super( autoSchoolIdStrategy, autoSchoolNumberStrategy, autoContextIdStrategy, autoContextNameStrategy, - autoMediumIdStrategy + autoMediumIdStrategy, + autoMoinSchuleGroupUuidStrategy ); } diff --git a/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts b/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts index 9c1504321a9..c029e50457e 100644 --- a/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts +++ b/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts @@ -15,6 +15,7 @@ import { AutoMediumIdStrategy, AutoSchoolIdStrategy, AutoSchoolNumberStrategy, + AutoMoinSchuleGroupUuidStrategy, } from './service/auto-parameter-strategy'; import { BasicToolLaunchStrategy, Lti11ToolLaunchStrategy, OAuth2ToolLaunchStrategy } from './service/launch-strategy'; @@ -41,6 +42,7 @@ import { BasicToolLaunchStrategy, Lti11ToolLaunchStrategy, OAuth2ToolLaunchStrat AutoSchoolIdStrategy, AutoSchoolNumberStrategy, AutoMediumIdStrategy, + AutoMoinSchuleGroupUuidStrategy, ], exports: [ToolLaunchService], })