Skip to content

Commit

Permalink
fix school external tools
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Jun 28, 2024
1 parent 4a10de7 commit 61050ac
Show file tree
Hide file tree
Showing 39 changed files with 346 additions and 613 deletions.
38 changes: 38 additions & 0 deletions apps/server/src/migrations/mikro-orm/Migration20240627134214.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240627134214 extends Migration {
async up(): Promise<void> {
await this.driver.aggregate('school-external-tools', [
{ $set: { isDeactivated: { $ifNull: ['$status.isDeactivated', false] } } },
{ $unset: 'status' },
{ $out: 'school-external-tools' },
]);

console.info(`'status.isDeactivated' has moved to 'isDeactivated' for all school-external-tools`);
}

async down(): Promise<void> {
await this.driver.nativeUpdate(
'school-external-tools',
{ isDeactivated: true },
{
$set: {
status: {
isOutdatedOnScopeSchool: false,
isDeactivated: true,
},
},
}
);

await this.driver.nativeUpdate(
'school-external-tools',
{},
{
$unset: { isDeactivated: '' },
}
);

console.info(`All school-external-tools were reverted to using 'status'`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class SchulconnexToolProvisioningService {
id: new ObjectId().toHexString(),
toolId: externalTool.id,
schoolId,
isDeactivated: false,
parameters: [],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ describe(ToolConfigurationStatusService.name, () => {
const externalTool = externalToolFactory.buildWithId();
const schoolExternalTool = schoolExternalToolFactory.buildWithId({
toolId: externalTool.id,
status: { isDeactivated: true },
isDeactivated: true,
});
const contextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ToolConfigurationStatusService {
}

private isToolDeactivated(externalTool: ExternalTool, schoolExternalTool: SchoolExternalTool): boolean {
return !!(externalTool.isDeactivated || (schoolExternalTool.status && schoolExternalTool.status.isDeactivated));
return externalTool.isDeactivated || schoolExternalTool.isDeactivated;
}

private async isToolLicensed(externalTool: ExternalTool, userId: EntityId): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ExternalToolDatasheetMapper {
return 'Das Tool ist instanzweit deaktiviert';
}

if (schoolExternalTool?.status?.isDeactivated) {
if (schoolExternalTool?.isDeactivated) {
return 'Das Tool ist deaktiviert';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ExternalToolConfigurationService {
const availableTools: ContextExternalToolTemplateInfo[] = unusedTools
.filter((toolRef): toolRef is ContextExternalToolTemplateInfo => !toolRef.externalTool.isHidden)
.filter((toolRef) => !toolRef.externalTool.isDeactivated)
.filter((toolRef) => !toolRef.schoolExternalTool.status?.isDeactivated);
.filter((toolRef) => !toolRef.schoolExternalTool.isDeactivated);

return availableTools;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ describe('ToolSchoolController (API)', () => {
const response = await loggedInClient.post().send(postParams);

expect(response.statusCode).toEqual(HttpStatus.CREATED);
expect(response.body).toEqual({
expect(response.body).toEqual<SchoolExternalToolResponse>({
id: expect.any(String),
isDeactivated: postParams.isDeactivated,
name: externalToolEntity.name,
schoolId: postParams.schoolId,
toolId: postParams.toolId,
Expand Down Expand Up @@ -231,6 +232,7 @@ describe('ToolSchoolController (API)', () => {

const externalToolEntity: ExternalToolEntity = externalToolEntityFactory.buildWithId({
parameters: [],
isDeactivated: true,
});

const schoolExternalToolEntity: SchoolExternalToolEntity = schoolExternalToolEntityFactory.buildWithId({
Expand Down Expand Up @@ -284,16 +286,18 @@ describe('ToolSchoolController (API)', () => {

expect(response.statusCode).toEqual(HttpStatus.OK);
expect(response.body).toEqual(
expect.objectContaining(<SchoolExternalToolSearchListResponse>{
expect.objectContaining<SchoolExternalToolSearchListResponse>({
data: [
{
id: schoolExternalToolEntity.id,
name: externalToolEntity.name,
schoolId: school.id,
toolId: externalToolEntity.id,
status: schoolExternalToolConfigurationStatusFactory.build({
isDeactivated: false,
status: {
isOutdatedOnScopeSchool: true,
}),
isGloballyDeactivated: true,
},
parameters: [
{
name: schoolExternalToolEntity.schoolParameters[0].name,
Expand Down Expand Up @@ -322,6 +326,7 @@ describe('ToolSchoolController (API)', () => {

const externalToolEntity: ExternalToolEntity = externalToolEntityFactory.buildWithId({
parameters: [],
isDeactivated: true,
});

const schoolExternalToolEntity: SchoolExternalToolEntity = schoolExternalToolEntityFactory.buildWithId({
Expand All @@ -331,12 +336,14 @@ describe('ToolSchoolController (API)', () => {

const schoolExternalToolResponse: SchoolExternalToolResponse = new SchoolExternalToolResponse({
id: schoolExternalToolEntity.id,
name: '',
name: externalToolEntity.name,
schoolId: school.id,
toolId: externalToolEntity.id,
status: schoolExternalToolConfigurationStatusFactory.build({
isOutdatedOnScopeSchool: false,
}),
isDeactivated: false,
status: {
isOutdatedOnScopeSchool: true,
isGloballyDeactivated: true,
},
parameters: [
{
name: schoolExternalToolEntity.schoolParameters[0].name,
Expand Down Expand Up @@ -459,9 +466,11 @@ describe('ToolSchoolController (API)', () => {
name: externalToolEntity.name,
schoolId: postParamsUpdate.schoolId,
toolId: postParamsUpdate.toolId,
status: schoolExternalToolConfigurationStatusFactory.build({
isDeactivated: false,
status: {
isOutdatedOnScopeSchool: false,
}),
isGloballyDeactivated: false,
},
parameters: [
{
name: updatedParamEntry.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export * from './school-external-tool-post.params';
export * from './school-external-tool-search.params';
export * from './school-external-tool-search-list.response';
export * from './school-external-tool-metadata.response';
export * from '../domain/school-external-tool-configuration-status';
export { SchoolExternalToolConfigurationStatusResponse } from './school-external-tool-configuration.response';
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export class SchoolExternalToolConfigurationStatusResponse {

@ApiProperty({
type: Boolean,
description: 'Is the tool deactivated, because of school administrator?',
description: 'Is the tool deactivated, because of instance administrator?',
})
isDeactivated: boolean;
isGloballyDeactivated: boolean;

constructor(props: SchoolExternalToolConfigurationStatusResponse) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isDeactivated = props.isDeactivated;
this.isGloballyDeactivated = props.isGloballyDeactivated;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiProperty } from '@nestjs/swagger';
import { CustomParameterEntryResponse } from './custom-parameter-entry.response';
import { SchoolExternalToolConfigurationStatusResponse } from './school-external-tool-configuration.response';

Expand All @@ -15,22 +15,22 @@ export class SchoolExternalToolResponse {
@ApiProperty()
schoolId: string;

@ApiProperty()
isDeactivated: boolean;

@ApiProperty({ type: [CustomParameterEntryResponse] })
parameters: CustomParameterEntryResponse[];

@ApiProperty({ type: SchoolExternalToolConfigurationStatusResponse })
status: SchoolExternalToolConfigurationStatusResponse;

@ApiPropertyOptional()
logoUrl?: string;

constructor(response: SchoolExternalToolResponse) {
this.id = response.id;
this.name = response.name;
this.toolId = response.toolId;
this.schoolId = response.schoolId;
this.isDeactivated = response.isDeactivated;
this.parameters = response.parameters;
this.status = response.status;
this.logoUrl = response.logoUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import {
import { ValidationError } from '@shared/common';
import { LegacyLogger } from '@src/core/logger';
import { ExternalToolSearchListResponse } from '../../external-tool/controller/dto';
import { SchoolExternalTool, SchoolExternalToolMetadata } from '../domain';
import { SchoolExternalTool, SchoolExternalToolMetadata, SchoolExternalToolProps } from '../domain';
import {
SchoolExternalToolMetadataMapper,
SchoolExternalToolRequestMapper,
SchoolExternalToolResponseMapper,
} from '../mapper';
import { SchoolExternalToolUc } from '../uc';
import { SchoolExternalToolDto } from '../uc/dto/school-external-tool.types';
import {
SchoolExternalToolIdParams,
SchoolExternalToolMetadataResponse,
Expand All @@ -36,12 +35,7 @@ import {
@Authenticate('jwt')
@Controller('tools/school-external-tools')
export class ToolSchoolController {
constructor(
private readonly schoolExternalToolUc: SchoolExternalToolUc,
private readonly responseMapper: SchoolExternalToolResponseMapper,
private readonly requestMapper: SchoolExternalToolRequestMapper,
private readonly logger: LegacyLogger
) {}
constructor(private readonly schoolExternalToolUc: SchoolExternalToolUc, private readonly logger: LegacyLogger) {}

@Get()
@ApiFoundResponse({ description: 'SchoolExternalTools has been found.', type: ExternalToolSearchListResponse })
Expand All @@ -55,7 +49,8 @@ export class ToolSchoolController {
const found: SchoolExternalTool[] = await this.schoolExternalToolUc.findSchoolExternalTools(currentUser.userId, {
schoolId: schoolExternalToolParams.schoolId,
});
const response: SchoolExternalToolSearchListResponse = this.responseMapper.mapToSearchListResponse(found);
const response: SchoolExternalToolSearchListResponse =
SchoolExternalToolResponseMapper.mapToSearchListResponse(found);
return response;
}

Expand All @@ -71,7 +66,8 @@ export class ToolSchoolController {
currentUser.userId,
params.schoolExternalToolId
);
const mapped: SchoolExternalToolResponse = this.responseMapper.mapToSchoolExternalToolResponse(schoolExternalTool);
const mapped: SchoolExternalToolResponse =
SchoolExternalToolResponseMapper.mapToSchoolExternalToolResponse(schoolExternalTool);
return mapped;
}

Expand All @@ -86,14 +82,16 @@ export class ToolSchoolController {
@Param() params: SchoolExternalToolIdParams,
@Body() body: SchoolExternalToolPostParams
): Promise<SchoolExternalToolResponse> {
const schoolExternalToolDto: SchoolExternalToolDto = this.requestMapper.mapSchoolExternalToolRequest(body);
const schoolExternalToolDto: SchoolExternalToolProps =
SchoolExternalToolRequestMapper.mapSchoolExternalToolRequest(body);
const updated: SchoolExternalTool = await this.schoolExternalToolUc.updateSchoolExternalTool(
currentUser.userId,
params.schoolExternalToolId,
schoolExternalToolDto
);

const mapped: SchoolExternalToolResponse = this.responseMapper.mapToSchoolExternalToolResponse(updated);
const mapped: SchoolExternalToolResponse =
SchoolExternalToolResponseMapper.mapToSchoolExternalToolResponse(updated);
this.logger.debug(`SchoolExternalTool with id ${mapped.id} was updated by user with id ${currentUser.userId}`);
return mapped;
}
Expand Down Expand Up @@ -127,15 +125,16 @@ export class ToolSchoolController {
@CurrentUser() currentUser: ICurrentUser,
@Body() body: SchoolExternalToolPostParams
): Promise<SchoolExternalToolResponse> {
const schoolExternalToolDto: SchoolExternalToolDto = this.requestMapper.mapSchoolExternalToolRequest(body);
const schoolExternalToolDto: SchoolExternalToolProps =
SchoolExternalToolRequestMapper.mapSchoolExternalToolRequest(body);

const createdSchoolExternalToolDO: SchoolExternalTool = await this.schoolExternalToolUc.createSchoolExternalTool(
currentUser.userId,
schoolExternalToolDto
);

const response: SchoolExternalToolResponse =
this.responseMapper.mapToSchoolExternalToolResponse(createdSchoolExternalToolDO);
SchoolExternalToolResponseMapper.mapToSchoolExternalToolResponse(createdSchoolExternalToolDO);

this.logger.debug(`SchoolExternalTool with id ${response.id} was created by user with id ${currentUser.userId}`);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './school-external-tool.do';
export * from './school-external-tool.ref';
export * from './school-external-tool-metadata';
export { SchoolExternalToolConfigurationStatus } from './school-external-tool-configuration-status';
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export class SchoolExternalToolConfigurationStatus {
isOutdatedOnScopeSchool: boolean;

isDeactivated: boolean;
isGloballyDeactivated: boolean;

constructor(props: SchoolExternalToolConfigurationStatus) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isDeactivated = props.isDeactivated;
this.isGloballyDeactivated = props.isGloballyDeactivated;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object';
import { CustomParameterEntry } from '../../common/domain';
import { SchoolExternalToolConfigurationStatus } from '../controller/dto';
import { SchoolExternalToolConfigurationStatus } from './school-external-tool-configuration-status';

export interface SchoolExternalToolProps extends AuthorizableObject {
id: string;
Expand All @@ -13,6 +13,8 @@ export interface SchoolExternalToolProps extends AuthorizableObject {

parameters: CustomParameterEntry[];

isDeactivated: boolean;

status?: SchoolExternalToolConfigurationStatus;
}

Expand All @@ -37,11 +39,15 @@ export class SchoolExternalTool extends DomainObject<SchoolExternalToolProps> {
return this.props.parameters;
}

get status(): SchoolExternalToolConfigurationStatus | undefined {
return this.props.status;
get isDeactivated(): boolean {
return this.props.isDeactivated;
}

get status(): SchoolExternalToolConfigurationStatus {
return this.props.status ?? { isOutdatedOnScopeSchool: false, isGloballyDeactivated: false };
}

set status(value: SchoolExternalToolConfigurationStatus | undefined) {
set status(value: SchoolExternalToolConfigurationStatus) {
this.props.status = value;
}
}
Loading

0 comments on commit 61050ac

Please sign in to comment.