Skip to content

Commit

Permalink
Merge branch 'main' into BC-6059-tldraw-application-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wiaderwek authored Jan 8, 2024
2 parents dcd73f2 + fdfcf51 commit a219c74
Show file tree
Hide file tree
Showing 56 changed files with 935 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ export class ContextExternalToolConfigurationStatusResponse {
})
isOutdatedOnScopeContext: boolean;

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

constructor(props: ContextExternalToolConfigurationStatusResponse) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
this.isDeactivated = props.isDeactivated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ export class ContextExternalToolConfigurationStatus {

isOutdatedOnScopeContext: boolean;

isDeactivated: boolean;

constructor(props: ContextExternalToolConfigurationStatus) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
this.isDeactivated = props.isDeactivated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class ToolStatusResponseMapper {
new ContextExternalToolConfigurationStatusResponse({
isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool,
isOutdatedOnScopeContext: status.isOutdatedOnScopeContext,
isDeactivated: status.isDeactivated,
});

return configurationStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('CommonToolService', () => {
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isDeactivated: false,
})
);
});
Expand Down Expand Up @@ -117,6 +118,7 @@ describe('CommonToolService', () => {
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isDeactivated: false,
})
);
});
Expand Down Expand Up @@ -210,6 +212,7 @@ describe('CommonToolService', () => {
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
isDeactivated: false,
})
);
});
Expand Down Expand Up @@ -241,6 +244,76 @@ describe('CommonToolService', () => {
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
isDeactivated: false,
})
);
});
});

describe('when schoolExternalTool is deactivated', () => {
const setup = () => {
const externalTool: ExternalTool = externalToolFactory.buildWithId({ version: 1 });
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.buildWithId({
toolVersion: 2,
status: { isDeactivated: true },
});
const contextExternalTool: ContextExternalTool = contextExternalToolFactory.buildWithId({ toolVersion: 2 });

return {
externalTool,
schoolExternalTool,
contextExternalTool,
};
};

it('should return a configuration status with deactivated true', () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus(
externalTool,
schoolExternalTool,
contextExternalTool
);

expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
isDeactivated: true,
})
);
});
});

describe('when externalTool is deactivated', () => {
const setup = () => {
const externalTool: ExternalTool = externalToolFactory.buildWithId({ version: 1, isDeactivated: true });
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.buildWithId({
toolVersion: 2,
});
const contextExternalTool: ContextExternalTool = contextExternalToolFactory.buildWithId({ toolVersion: 2 });

return {
externalTool,
schoolExternalTool,
contextExternalTool,
};
};

it('should return a configuration status with deactivated true', () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus(
externalTool,
schoolExternalTool,
contextExternalTool
);

expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
isDeactivated: true,
})
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class CommonToolService {
const configurationStatus: ContextExternalToolConfigurationStatus = new ContextExternalToolConfigurationStatus({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isDeactivated: false,
});

if (
Expand All @@ -34,6 +35,10 @@ export class CommonToolService {
configurationStatus.isOutdatedOnScopeSchool = true;
}

if (externalTool.isDeactivated || schoolExternalTool.status?.isDeactivated) {
configurationStatus.isDeactivated = true;
}

return configurationStatus;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
contextExternalToolFactory,
externalToolFactory,
schoolExternalToolFactory,
schoolToolConfigurationStatusFactory,
toolConfigurationStatusFactory,
} from '@shared/testing';
import { ContextExternalToolConfigurationStatus } from '../../common/domain';
Expand Down Expand Up @@ -319,5 +320,132 @@ describe('ToolVersionService', () => {
expect(contextExternalToolValidationService.validate).toHaveBeenCalledWith(contextExternalTool);
});
});

describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and SchoolExternalTool is deactivated', () => {
const setup = () => {
const externalTool = externalToolFactory.buildWithId();
const schoolExternalTool = schoolExternalToolFactory.buildWithId({
toolId: externalTool.id as string,
});
schoolExternalTool.status = schoolToolConfigurationStatusFactory.build({ isDeactivated: true });
const contextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id as string)
.buildWithId();

toolFeatures.toolStatusWithoutVersions = true;

schoolExternalToolValidationService.validate.mockRejectedValueOnce(Promise.resolve());
contextExternalToolValidationService.validate.mockRejectedValueOnce(Promise.resolve());

return {
externalTool,
schoolExternalTool,
contextExternalTool,
};
};

it('should return status is deactivated', async () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus(
externalTool,
schoolExternalTool,
contextExternalTool
);

expect(status).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isDeactivated: true,
})
);
});
});

describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and externalTool is deactivated', () => {
const setup = () => {
const externalTool = externalToolFactory.buildWithId({
isDeactivated: true,
});
const schoolExternalTool = schoolExternalToolFactory.buildWithId({
toolId: externalTool.id as string,
});
const contextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id as string)
.buildWithId();

toolFeatures.toolStatusWithoutVersions = true;

schoolExternalToolValidationService.validate.mockRejectedValueOnce(Promise.resolve());
contextExternalToolValidationService.validate.mockRejectedValueOnce(Promise.resolve());

return {
externalTool,
schoolExternalTool,
contextExternalTool,
};
};

it('should return deactivated tool status', async () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus(
externalTool,
schoolExternalTool,
contextExternalTool
);

expect(status).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isDeactivated: true,
})
);
});
});

describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true, externalTool and schoolExternalTool are not deactivated', () => {
const setup = () => {
const externalTool = externalToolFactory.buildWithId({});

const schoolExternalTool = schoolExternalToolFactory.buildWithId({
toolId: externalTool.id as string,
});
const contextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id as string)
.buildWithId();

toolFeatures.toolStatusWithoutVersions = true;

schoolExternalToolValidationService.validate.mockRejectedValueOnce(Promise.resolve());
contextExternalToolValidationService.validate.mockRejectedValueOnce(Promise.resolve());

return {
externalTool,
schoolExternalTool,
contextExternalTool,
};
};

it('should return deactivated tool status', async () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus(
externalTool,
schoolExternalTool,
contextExternalTool
);

expect(status).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isDeactivated: false,
})
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class ToolVersionService {
const configurationStatus: ContextExternalToolConfigurationStatus = new ContextExternalToolConfigurationStatus({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
isDeactivated: this.isToolDeactivated(externalTool, schoolExternalTool),
});

try {
Expand All @@ -52,4 +53,12 @@ export class ToolVersionService {

return status;
}

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

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('ToolController (API)', () => {
baseUrl: 'https://link.to-my-tool.com/:key',
},
isHidden: false,
isDeactivated: false,
logoUrl: 'https://link.to-my-logo.com',
url: 'https://link.to-my-tool.com',
openNewTab: true,
Expand Down Expand Up @@ -151,6 +152,7 @@ describe('ToolController (API)', () => {
baseUrl: 'https://link.to-my-tool.com/:key',
},
isHidden: false,
isDeactivated: false,
logoUrl: 'https://link.to-my-logo.com',
url: 'https://link.to-my-tool.com',
openNewTab: true,
Expand Down Expand Up @@ -382,6 +384,7 @@ describe('ToolController (API)', () => {
baseUrl: 'https://link.to-my-tool.com/:key',
},
isHidden: false,
isDeactivated: false,
logoUrl: 'https://link.to-my-logo.com',
url: 'https://link.to-my-tool.com',
openNewTab: true,
Expand Down Expand Up @@ -449,6 +452,7 @@ describe('ToolController (API)', () => {
baseUrl: 'https://link.to-my-tool.com/:key',
},
isHidden: false,
isDeactivated: false,
logoUrl: 'https://link.to-my-logo.com',
url: 'https://link.to-my-tool.com',
openNewTab: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export class ExternalToolCreateParams {
@ApiProperty()
isHidden!: boolean;

@IsBoolean()
@ApiProperty({
type: Boolean,
default: false,
description: 'Tool can be deactivated, related tools can not be added to e.g. school, course or board anymore',
})
isDeactivated!: boolean;

@IsBoolean()
@ApiProperty()
openNewTab!: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export class ExternalToolUpdateParams {
@ApiProperty()
isHidden!: boolean;

@IsBoolean()
@ApiProperty({
type: Boolean,
default: false,
})
isDeactivated!: boolean;

@IsBoolean()
@ApiProperty()
openNewTab!: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class ExternalToolResponse {
@ApiProperty()
isHidden: boolean;

@ApiProperty()
isDeactivated: boolean;

@ApiProperty()
openNewTab: boolean;

Expand All @@ -42,6 +45,7 @@ export class ExternalToolResponse {
this.config = response.config;
this.parameters = response.parameters;
this.isHidden = response.isHidden;
this.isDeactivated = response.isDeactivated;
this.openNewTab = response.openNewTab;
this.version = response.version;
this.restrictToContexts = response.restrictToContexts;
Expand Down
Loading

0 comments on commit a219c74

Please sign in to comment.