Skip to content

Commit

Permalink
N21-2149 merlin bibliothek element
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab authored Nov 13, 2024
1 parent 97dbb6b commit 990ad4e
Show file tree
Hide file tree
Showing 25 changed files with 1,049 additions and 624 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,17 @@ data:
"upsert": true
}
);'
mongosh $DATABASE__URL --quiet --eval 'db.getCollection("external-tools").updateOne(
{
"name": "Merlin Bibliothek",
},
{ $set: {
"config_secret": "'$CTL_SEED_SECRET_MERLIN'",
} },
{
"upsert": true
}
);'
echo "Inserted ctl seed data secrets to external-tools."

# ========== End of the CTL seed data configuration section.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export enum LtiMessageType {
BASIC_LTI_LAUNCH_REQUEST = 'basic-lti-launch-request',
CONTENT_ITEM_SELECTION_REQUEST = 'ContentItemSelectionRequest',
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Embedded, Entity, ManyToOne, Property } from '@mikro-orm/core';
import { ObjectId } from '@mikro-orm/mongodb';
import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity';
import { EntityId } from '@shared/domain/types';
import { ObjectId } from '@mikro-orm/mongodb';
import { CustomParameterEntryEntity } from '../../common/entity';
import { SchoolExternalToolEntity } from '../../school-external-tool/entity';
import { ContextExternalToolType } from './context-external-tool-type.enum';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const externalToolDatasheetTemplateDataFactory = ExternalToolDatasheetTem
creatorName: `John Doe ${sequence}`,
instance: 'dBildungscloud',
toolName: `external-tool-${sequence}`,
toolUrl: 'https://www.basic-baseUrl.com/',
toolUrl: 'https://www.basic-baseurl.com/',
toolType: 'Basic',
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeepPartial } from 'fishery';
import { ObjectId } from '@mikro-orm/mongodb';
import { DoBaseFactory } from '@shared/testing/factory/domainobject/do-base.factory';
import { DeepPartial } from 'fishery';
import { CustomParameter } from '../../common/domain';
import {
CustomParameterLocation,
Expand All @@ -24,7 +24,7 @@ import { fileRecordRefFactory } from './file-record-ref.factory';
export const basicToolConfigFactory = DoBaseFactory.define<BasicToolConfig, BasicToolConfig>(BasicToolConfig, () => {
return {
type: ToolConfigType.BASIC,
baseUrl: 'https://www.basic-baseUrl.com/',
baseUrl: 'https://www.basic-baseurl.com/',
};
});

Expand Down Expand Up @@ -86,24 +86,35 @@ export const customParameterFactory = CustomParameterFactory.define(CustomParame
});

class ExternalToolFactory extends DoBaseFactory<ExternalTool, ExternalToolProps> {
withBasicConfig(customParam?: DeepPartial<BasicToolConfig>): this {
const params: DeepPartial<ExternalTool> = {
config: basicToolConfigFactory.build(customParam),
};

return this.params(params);
}

withOauth2Config(customParam?: DeepPartial<Oauth2ToolConfig>): this {
const params: DeepPartial<ExternalTool> = {
config: oauth2ToolConfigFactory.build(customParam),
};

return this.params(params);
}

withLti11Config(customParam?: DeepPartial<Lti11ToolConfig>): this {
const params: DeepPartial<ExternalTool> = {
config: lti11ToolConfigFactory.build(customParam),
};

return this.params(params);
}

withCustomParameters(number: number, customParam?: DeepPartial<CustomParameter>): this {
const params: DeepPartial<ExternalTool> = {
parameters: customParameterFactory.buildList(number, customParam),
};

return this.params(params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ describe(ExternalToolUc.name, () => {

const lti11ToolConfig: Lti11ToolConfigUpdate = {
type: ToolConfigType.LTI11,
baseUrl: 'https://www.basic-baseUrl.com/',
baseUrl: 'https://www.basic-baseurl.com/',
key: 'key',
privacy_permission: LtiPrivacyPermission.PSEUDONYMOUS,
lti_message_type: LtiMessageType.BASIC_LTI_LAUNCH_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('ToolLaunchController (API)', () => {
method: LaunchRequestMethod.GET,
url: 'https://mockurl.de/',
openNewTab: true,
isDeepLink: false,
});
});
});
Expand Down Expand Up @@ -413,6 +414,7 @@ describe('ToolLaunchController (API)', () => {
method: LaunchRequestMethod.GET,
url: 'https://mockurl.de/',
openNewTab: true,
isDeepLink: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ export class ToolLaunchRequestResponse {
})
openNewTab?: boolean;

@ApiProperty({
description: 'Specifies whether the request is an LTI Deep linking content item selection request',
})
isDeepLink: boolean;

constructor(props: ToolLaunchRequestResponse) {
this.url = props.url;
this.method = props.method;
this.payload = props.payload;
this.openNewTab = props.openNewTab;
this.isDeepLink = props.isDeepLink;
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import { contextExternalToolFactory } from '../../context-external-tool/testing';
import { toolConfigurationStatusFactory } from '../../external-tool/testing';
import { ToolStatusNotLaunchableLoggableException } from './tool-status-not-launchable.loggable-exception';

describe('ToolStatusNotLaunchableLoggableException', () => {
describe(ToolStatusNotLaunchableLoggableException.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const toolId = 'toolId';
const userId = 'userId';
const contextExternalTool = contextExternalToolFactory.build();
const toolConfigStatus = toolConfigurationStatusFactory.build();

const exception = new ToolStatusNotLaunchableLoggableException(
userId,
toolId,
toolConfigStatus.isOutdatedOnScopeSchool,
toolConfigStatus.isOutdatedOnScopeContext,
toolConfigStatus.isIncompleteOnScopeContext,
toolConfigStatus.isIncompleteOperationalOnScopeContext,
toolConfigStatus.isDeactivated,
toolConfigStatus.isNotLicensed
);
const exception = new ToolStatusNotLaunchableLoggableException(userId, contextExternalTool, toolConfigStatus);

return {
exception,
toolConfigStatus,
contextExternalTool,
};
};

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

const result = exception.getLogMessage();

Expand All @@ -35,13 +29,9 @@ describe('ToolStatusNotLaunchableLoggableException', () => {
stack: expect.any(String),
data: {
userId: 'userId',
toolId: 'toolId',
isOutdatedOnScopeSchool: false,
isOutdatedOnScopeContext: false,
isIncompleteOnScopeContext: false,
isIncompleteOperationalOnScopeContext: false,
isDeactivated: false,
isNotLicensed: false,
contextExternalToolId: contextExternalTool.id,
schoolExternalToolId: contextExternalTool.schoolToolRef.schoolToolId,
status: toolConfigStatus,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { UnprocessableEntityException } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { ContextExternalToolConfigurationStatus } from '../../common/domain';
import { ContextExternalToolLaunchable } from '../../context-external-tool/domain';

export class ToolStatusNotLaunchableLoggableException extends UnprocessableEntityException implements Loggable {
constructor(
private readonly userId: EntityId,
private readonly toolId: EntityId,
private readonly isOutdatedOnScopeSchool: boolean,
private readonly isOutdatedOnScopeContext: boolean,
private readonly isIncompleteOnScopeContext: boolean,
private readonly isIncompleteOperationalOnScopeContext: boolean,
private readonly isDeactivated: boolean,
private readonly isNotLicensed: boolean
private readonly contextExternalTool: ContextExternalToolLaunchable,
private readonly configStatus: ContextExternalToolConfigurationStatus
) {
super();
}
Expand All @@ -23,13 +20,9 @@ export class ToolStatusNotLaunchableLoggableException extends UnprocessableEntit
stack: this.stack,
data: {
userId: this.userId,
toolId: this.toolId,
isOutdatedOnScopeSchool: this.isOutdatedOnScopeSchool,
isOutdatedOnScopeContext: this.isOutdatedOnScopeContext,
isIncompleteOnScopeContext: this.isIncompleteOnScopeContext,
isIncompleteOperationalOnScopeContext: this.isIncompleteOperationalOnScopeContext,
isDeactivated: this.isDeactivated,
isNotLicensed: this.isNotLicensed,
contextExternalToolId: this.contextExternalTool.id,
schoolExternalToolId: this.contextExternalTool.schoolToolRef.schoolToolId,
status: { ...this.configStatus },
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CustomParameterLocation, ToolConfigType } from '../../common/enum';
import { ToolLaunchRequestResponse } from '../controller/dto';
import { LaunchRequestMethod, PropertyLocation, ToolLaunchDataType, ToolLaunchRequest } from '../types';
import { ToolLaunchMapper } from './tool-launch.mapper';
import { CustomParameterLocation, ToolConfigType } from '../../common/enum';

describe('ToolLaunchMapper', () => {
describe('mapToParameterLocation', () => {
Expand Down Expand Up @@ -33,15 +33,17 @@ describe('ToolLaunchMapper', () => {
url: 'url',
openNewTab: true,
payload: 'payload',
isDeepLink: false,
});

const result: ToolLaunchRequestResponse = ToolLaunchMapper.mapToToolLaunchRequestResponse(toolLaunchRequest);

expect(result).toEqual({
expect(result).toEqual<ToolLaunchRequestResponse>({
method: toolLaunchRequest.method,
url: toolLaunchRequest.url,
payload: toolLaunchRequest.payload,
openNewTab: toolLaunchRequest.openNewTab,
isDeepLink: toolLaunchRequest.isDeepLink,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PropertyLocation, ToolLaunchDataType, ToolLaunchRequest } from '../types';
import { ToolLaunchRequestResponse } from '../controller/dto';
import { CustomParameterLocation, ToolConfigType } from '../../common/enum';
import { ToolLaunchRequestResponse } from '../controller/dto';
import { PropertyLocation, ToolLaunchDataType, ToolLaunchRequest } from '../types';

const customToParameterLocationMapping: Record<CustomParameterLocation, PropertyLocation> = {
[CustomParameterLocation.PATH]: PropertyLocation.PATH,
Expand All @@ -14,37 +14,22 @@ const toolConfigTypeToToolLaunchDataTypeMapping: Record<ToolConfigType, ToolLaun
[ToolConfigType.OAUTH2]: ToolLaunchDataType.OAUTH2,
};

const toolLaunchDataTypeToToolConfigTypeMapping: Record<ToolLaunchDataType, ToolConfigType> = {
[ToolLaunchDataType.BASIC]: ToolConfigType.BASIC,
[ToolLaunchDataType.LTI11]: ToolConfigType.LTI11,
[ToolLaunchDataType.OAUTH2]: ToolConfigType.OAUTH2,
};

export class ToolLaunchMapper {
static mapToParameterLocation(location: CustomParameterLocation): PropertyLocation {
const mappedLocation = customToParameterLocationMapping[location];

return mappedLocation;
}

static mapToToolLaunchDataType(configType: ToolConfigType): ToolLaunchDataType {
const mappedType = toolConfigTypeToToolLaunchDataTypeMapping[configType];
return mappedType;
}

static mapToToolConfigType(launchDataType: ToolLaunchDataType): ToolConfigType {
const mappedType = toolLaunchDataTypeToToolConfigTypeMapping[launchDataType];
return mappedType;
}

static mapToToolLaunchRequestResponse(toolLaunchRequest: ToolLaunchRequest): ToolLaunchRequestResponse {
const { method, url, payload, openNewTab } = toolLaunchRequest;

const response = new ToolLaunchRequestResponse({
method,
url,
payload,
openNewTab,
});
const response = new ToolLaunchRequestResponse(toolLaunchRequest);

return response;
}
}
Loading

0 comments on commit 990ad4e

Please sign in to comment.