Skip to content

Commit

Permalink
N21-2188 show external tool context restriction (#5270)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBergCap authored Oct 2, 2024
1 parent 2eba077 commit a82af02
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const externalToolFactory = ExternalToolFactory.define(ExternalTool, ({ s
isDeactivated: false,
openNewTab: false,
createdAt: new Date(2020, 1, 1),
restrictToContexts: undefined,
isPreferred: false,
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ToolContextType } from '@modules/tool/common/enum';
import { CustomParameterEntryResponse } from './custom-parameter-entry.response';
import { SchoolExternalToolConfigurationStatusResponse } from './school-external-tool-configuration.response';

Expand All @@ -24,6 +25,9 @@ export class SchoolExternalToolResponse {
@ApiProperty({ type: SchoolExternalToolConfigurationStatusResponse })
status: SchoolExternalToolConfigurationStatusResponse;

@ApiPropertyOptional({ enum: ToolContextType, enumName: 'ToolContextType', isArray: true })
restrictToContexts?: ToolContextType[];

constructor(response: SchoolExternalToolResponse) {
this.id = response.id;
this.name = response.name;
Expand All @@ -32,5 +36,6 @@ export class SchoolExternalToolResponse {
this.isDeactivated = response.isDeactivated;
this.parameters = response.parameters;
this.status = response.status;
this.restrictToContexts = response.restrictToContexts;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object';
import { ToolContextType } from '@modules/tool/common/enum';
import { CustomParameterEntry } from '../../common/domain';
import { SchoolExternalToolConfigurationStatus } from './school-external-tool-configuration-status';

Expand All @@ -16,6 +17,8 @@ export interface SchoolExternalToolProps extends AuthorizableObject {
isDeactivated: boolean;

status?: SchoolExternalToolConfigurationStatus;

restrictToContexts?: ToolContextType[];
}

export class SchoolExternalTool extends DomainObject<SchoolExternalToolProps> {
Expand Down Expand Up @@ -50,4 +53,8 @@ export class SchoolExternalTool extends DomainObject<SchoolExternalToolProps> {
set status(value: SchoolExternalToolConfigurationStatus) {
this.props.status = value;
}

get restrictToContexts(): ToolContextType[] | undefined {
return this.props.restrictToContexts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class SchoolExternalToolResponseMapper {
isOutdatedOnScopeSchool: schoolExternalTool.status.isOutdatedOnScopeSchool,
isGloballyDeactivated: schoolExternalTool.status.isGloballyDeactivated,
}),
restrictToContexts: schoolExternalTool.restrictToContexts,
});

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ValidationError } from '@shared/common';
import { SchoolExternalToolRepo } from '@shared/repo';
import { ToolContextType } from '@modules/tool/common/enum';
import { CommonToolDeleteService, CommonToolValidationService } from '../../common/service';
import { ExternalToolService } from '../../external-tool';
import { type ExternalTool } from '../../external-tool/domain';
Expand Down Expand Up @@ -53,7 +54,9 @@ describe(SchoolExternalToolService.name, () => {
describe('findSchoolExternalTools', () => {
describe('when called with query', () => {
const setup = () => {
const externalTool: ExternalTool = externalToolFactory.build();
const externalTool: ExternalTool = externalToolFactory.build({
restrictToContexts: [ToolContextType.COURSE],
});
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.build({
name: undefined,
status: undefined,
Expand Down Expand Up @@ -101,6 +104,7 @@ describe(SchoolExternalToolService.name, () => {
isGloballyDeactivated: externalTool.isDeactivated,
isOutdatedOnScopeSchool: true,
}),
restrictToContexts: externalTool.restrictToContexts,
}),
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class SchoolExternalToolService {
...tool.getProps(),
name: externalTool.name,
status,
restrictToContexts: externalTool.restrictToContexts,
});

return schoolExternalTool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ export const schoolExternalToolFactory = SchoolExternalToolFactory.define(School
toolId: 'toolId',
isDeactivated: false,
status: schoolExternalToolConfigurationStatusFactory.build(),
restrictToContexts: undefined,
};
});

0 comments on commit a82af02

Please sign in to comment.