Skip to content
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

N21-1825 Group UUID auto param for synced course #5155

Merged
merged 17 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c8fbf70
added new type & enum for auto param for moin.schule group uuid
GordonNicholasCap Jul 31, 2024
53d4461
added new auto param strategy
GordonNicholasCap Jul 31, 2024
d94dc06
ensure moinschule_group_uuid auto param is always optional
GordonNicholasCap Aug 1, 2024
f4cc5ef
properly fetch syncedGroup from group service
GordonNicholasCap Aug 1, 2024
1547551
fix fetch external id
GordonNicholasCap Aug 1, 2024
a4de37f
Merge branch 'main' into N21-1825-sync-course-group-uuid-auto-param
GordonNicholasCap Aug 1, 2024
a7db9ef
renamed auto param type to only AUTO_GROUP_UUID
GordonNicholasCap Aug 2, 2024
af8add5
added new tests & adapted existing ones
GordonNicholasCap Aug 2, 2024
6fb0380
Merge remote-tracking branch 'refs/remotes/origin/main' into N21-1825…
GordonNicholasCap Aug 2, 2024
cdf7231
N21-1825 added new tests for create external tool validator
GordonNicholasCap Aug 2, 2024
6bcd135
N21-1825 added special error for when auto param value cannot be filled
GordonNicholasCap Aug 2, 2024
8ef509b
N21-1825 reorder imports, fixed eslint errors
GordonNicholasCap Aug 5, 2024
199b740
N21-1825 re-allow non-optional auto group uuid tool
GordonNicholasCap Aug 5, 2024
b8c0a42
N21-1825 renamed auto_groupuuid -> auto_group_externaluuid
GordonNicholasCap Aug 5, 2024
78f7065
Merge branch 'main' into N21-1825-sync-course-group-uuid-auto-param
GordonNicholasCap Aug 5, 2024
1d82c72
Merge branch 'main' into N21-1825-sync-course-group-uuid-auto-param
GordonNicholasCap Aug 6, 2024
566b93f
N21-1825 return undefined when no external id found
GordonNicholasCap Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum CustomParameterType {
AUTO_SCHOOLID = 'auto_schoolid',
AUTO_SCHOOLNUMBER = 'auto_schoolnumber',
AUTO_MEDIUMID = 'auto_mediumid',
AUTO_GROUP_EXTERNALUUID = 'auto_group_externaluuid',
}

export const autoParameters: CustomParameterType[] = [
Expand All @@ -15,4 +16,5 @@ export const autoParameters: CustomParameterType[] = [
CustomParameterType.AUTO_SCHOOLID,
CustomParameterType.AUTO_SCHOOLNUMBER,
CustomParameterType.AUTO_MEDIUMID,
CustomParameterType.AUTO_GROUP_EXTERNALUUID,
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum CustomParameterTypeParams {
AUTO_SCHOOLID = 'auto_schoolid',
AUTO_SCHOOLNUMBER = 'auto_schoolnumber',
AUTO_MEDIUMID = 'auto_mediumid',
AUTO_GROUP_EXTERNALUUID = 'auto_group_externaluuid',
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,16 @@ describe(ToolParameterTypeValidationUtil.name, () => {
expect(result).toEqual(false);
});
});

describe('when the type is AUTO_GROUPUUID', () => {
it('should return false', () => {
const result: boolean = ToolParameterTypeValidationUtil.isValueValidForType(
CustomParameterType.AUTO_GROUP_EXTERNALUUID,
'any value'
);

expect(result).toEqual(false);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class ToolParameterTypeValidationUtil {
[CustomParameterType.AUTO_SCHOOLID]: () => false,
[CustomParameterType.AUTO_SCHOOLNUMBER]: () => false,
[CustomParameterType.AUTO_MEDIUMID]: () => false,
[CustomParameterType.AUTO_GROUP_EXTERNALUUID]: () => false,
};

public static isValueValidForType(type: CustomParameterType, val: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const typeMapping: Record<CustomParameterTypeParams, CustomParameterType> = {
[CustomParameterTypeParams.AUTO_SCHOOLID]: CustomParameterType.AUTO_SCHOOLID,
[CustomParameterTypeParams.AUTO_SCHOOLNUMBER]: CustomParameterType.AUTO_SCHOOLNUMBER,
[CustomParameterTypeParams.AUTO_MEDIUMID]: CustomParameterType.AUTO_MEDIUMID,
[CustomParameterTypeParams.AUTO_GROUP_EXTERNALUUID]: CustomParameterType.AUTO_GROUP_EXTERNALUUID,
};

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const typeMapping: Record<CustomParameterType, CustomParameterTypeParams> = {
[CustomParameterType.AUTO_SCHOOLID]: CustomParameterTypeParams.AUTO_SCHOOLID,
[CustomParameterType.AUTO_SCHOOLNUMBER]: CustomParameterTypeParams.AUTO_SCHOOLNUMBER,
[CustomParameterType.AUTO_MEDIUMID]: CustomParameterTypeParams.AUTO_MEDIUMID,
[CustomParameterType.AUTO_GROUP_EXTERNALUUID]: CustomParameterTypeParams.AUTO_GROUP_EXTERNALUUID,
};

@Injectable()
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/tool/tool-launch/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './missing-tool-parameter-value.loggable-exception';
export * from './parameter-type-not-implemented.loggable-exception';
export { MissingMediaLicenseLoggableException } from './missing-licence.loggable-exception';
export { LaunchContextUnavailableLoggableException } from './launch-context-unavailable.loggable-exception';
export { MissingAutoParameterValueLoggableException } from './missing-auto-parameter-value.loggable-exception';
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { contextExternalToolFactory } from '../../context-external-tool/testing';
import { ContextExternalTool } from '../../context-external-tool/domain';
import { CustomParameterType } from '../../common/enum';
import { MissingAutoParameterValueLoggableException } from './missing-auto-parameter-value.loggable-exception';

describe(MissingAutoParameterValueLoggableException.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const contextExternalTool: ContextExternalTool = contextExternalToolFactory.build();

const parameterType: CustomParameterType = CustomParameterType.AUTO_GROUP_EXTERNALUUID;

const exception = new MissingAutoParameterValueLoggableException(contextExternalTool, parameterType);

return {
contextExternalTool,
parameterType,
exception,
};
};

it('should give the correct log message', () => {
const { contextExternalTool, parameterType, exception } = setup();

const result = exception.getLogMessage();

expect(result).toEqual({
type: 'MISSING_AUTO_PARAMETER_VALUE',
message:
'The external tool was attempted to launch, but the value to fill an auto parameter was not found ' +
'or could not be retrieved successfully',
stack: expect.any(String),
data: {
contextExternalToolId: contextExternalTool.id,
parameterType,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { HttpStatus } from '@nestjs/common';
import { BusinessError } from '@shared/common';
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { ContextExternalToolLaunchable } from '../../context-external-tool/domain';
import { CustomParameterType } from '../../common/enum';

export class MissingAutoParameterValueLoggableException extends BusinessError implements Loggable {
constructor(
private readonly contextExternalTool: ContextExternalToolLaunchable,
private readonly parameterType: CustomParameterType
) {
super(
{
type: 'MISSING_AUTO_PARAMETER_VALUE',
title: 'Missing auto parameter value',
defaultMessage:
'The external tool was attempted to launch, but the value to fill an auto parameter was not found ' +
'or could not be retrieved successfully',
},
HttpStatus.UNPROCESSABLE_ENTITY,
{
parameterType,
}
);
}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
type: this.type,
message: this.message,
stack: this.stack,
data: {
contextExternalToolId: this.contextExternalTool.id,
parameterType: this.parameterType,
},
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Injectable } from '@nestjs/common';
import { CourseService } from '@modules/learnroom';
import { Group, GroupService } from '@modules/group';
import { Course } from '@shared/domain/entity';
import { CustomParameterType, ToolContextType } from '../../../common/enum';
import { ContextExternalToolLaunchable } from '../../../context-external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { MissingAutoParameterValueLoggableException } from '../../error';
import { AutoParameterStrategy } from './auto-parameter.strategy';

@Injectable()
export class AutoGroupExternalUuidStrategy implements AutoParameterStrategy {
constructor(private readonly courseService: CourseService, private readonly groupService: GroupService) {}

async getValue(
_schoolExternalTool: SchoolExternalTool,
contextExternalTool: ContextExternalToolLaunchable
): Promise<string | undefined> {
if (contextExternalTool.contextRef.type !== ToolContextType.COURSE) {
return undefined;
}

const courseId = contextExternalTool.contextRef.id;
const course: Course = await this.courseService.findById(courseId);

const syncedGroup: Group | undefined = await this.getSyncedGroup(course);
if (!syncedGroup) {
return undefined;
}

const groupUuid = syncedGroup.externalSource?.externalId;
if (!groupUuid) {
throw new MissingAutoParameterValueLoggableException(
GordonNicholasCap marked this conversation as resolved.
Show resolved Hide resolved
contextExternalTool,
CustomParameterType.AUTO_GROUP_EXTERNALUUID
);
}

return groupUuid;
}

private async getSyncedGroup(course: Course): Promise<Group | undefined> {
const syncedGroupId = course.syncedWithGroup?.id;
if (!syncedGroupId) {
return undefined;
}

const syncedGroup = await this.groupService.findById(syncedGroupId);
return syncedGroup;
}
}
Loading
Loading