Skip to content

Commit

Permalink
N21-1337 removes deprecated ctl versioning (#4927)
Browse files Browse the repository at this point in the history
* N21-1337 removes the deprecated feature flags: FEATURE_CTL_CONTEXT_CONFIGURATION_ENABLED and FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED
  • Loading branch information
arnegns authored Apr 15, 2024
1 parent 9dfe1b4 commit b15d641
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 845 deletions.
4 changes: 0 additions & 4 deletions apps/server/src/modules/server/api/dto/config.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export class ConfigResponse {
@ApiProperty()
FEATURE_ENABLE_LDAP_SYNC_DURING_MIGRATION: boolean;

@ApiProperty()
FEATURE_CTL_CONTEXT_CONFIGURATION_ENABLED: boolean;

@ApiProperty()
CTL_TOOLS_RELOAD_TIME_MS: number;

Expand Down Expand Up @@ -251,7 +248,6 @@ export class ConfigResponse {
this.FEATURE_LTI_TOOLS_TAB_ENABLED = config.ltiToolsTabEnabled;
this.FEATURE_SHOW_OUTDATED_USERS = config.FEATURE_SHOW_OUTDATED_USERS;
this.FEATURE_ENABLE_LDAP_SYNC_DURING_MIGRATION = config.FEATURE_ENABLE_LDAP_SYNC_DURING_MIGRATION;
this.FEATURE_CTL_CONTEXT_CONFIGURATION_ENABLED = config.contextConfigurationEnabled;
this.CTL_TOOLS_RELOAD_TIME_MS = config.ctlToolsReloadTimeMs;
this.FEATURE_SHOW_NEW_CLASS_VIEW_ENABLED = config.FEATURE_SHOW_NEW_CLASS_VIEW_ENABLED;
this.FEATURE_CTL_TOOLS_COPY_ENABLED = config.ctlToolsCopyEnabled;
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/modules/server/api/test/server.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('Server Controller (API)', () => {
'FEATURE_CONSENT_NECESSARY',
'FEATURE_COPY_SERVICE_ENABLED',
'FEATURE_COURSE_SHARE',
'FEATURE_CTL_CONTEXT_CONFIGURATION_ENABLED',
'FEATURE_CTL_TOOLS_COPY_ENABLED',
'FEATURE_CTL_TOOLS_TAB_ENABLED',
'FEATURE_ENABLE_LDAP_SYNC_DURING_MIGRATION',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import {
contextExternalToolFactory,
externalToolFactory,
schoolExternalToolFactory,
toolConfigurationStatusFactory,
} from '@shared/testing';
import { CommonToolService } from './common-tool.service';
import { externalToolFactory } from '@shared/testing';
import { ExternalTool } from '../../external-tool/domain';
import { SchoolExternalTool } from '../../school-external-tool/domain';
import { ToolContextType } from '../enum';
import { ContextExternalToolConfigurationStatus } from '../domain';
import { ContextExternalTool } from '../../context-external-tool/domain';
import { CommonToolService } from './common-tool.service';

describe('CommonToolService', () => {
let module: TestingModule;
Expand All @@ -28,298 +20,6 @@ describe('CommonToolService', () => {
await module.close();
});

describe('determineToolConfigurationStatus', () => {
describe('when all versions are equal', () => {
const setup = () => {
const externalTool: ExternalTool = externalToolFactory.buildWithId({ version: 0 });
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.buildWithId({ toolVersion: 0 });
const contextExternalTool: ContextExternalTool = contextExternalToolFactory.buildWithId({ toolVersion: 0 });

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

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

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

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

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

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

it('should return outdated status for school level', () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

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

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

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

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

it('should return outdated status for context level', () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

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

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

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

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

it('should return outdated status for context and school level', () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

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

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

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

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

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

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

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

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

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

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

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

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

describe('when schoolExternalTool version is greater than externalTool version', () => {
const setup = () => {
const externalTool: ExternalTool = externalToolFactory.buildWithId({ version: 1 });
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 latest true', () => {
const { externalTool, schoolExternalTool, contextExternalTool } = setup();

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

expect(result).toEqual(
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,
})
);
});
});
});

describe('isContextRestricted', () => {
describe('when tool is not restricted to context', () => {
const setup = () => {
Expand Down
43 changes: 0 additions & 43 deletions apps/server/src/modules/tool/common/service/common-tool.service.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,9 @@
import { Injectable } from '@nestjs/common';
import { ContextExternalTool } from '../../context-external-tool/domain';
import { ExternalTool } from '../../external-tool/domain';
import { SchoolExternalTool } from '../../school-external-tool/domain';
import { ContextExternalToolConfigurationStatus } from '../domain';
import { ToolContextType } from '../enum';
import { ToolVersion } from '../interface';

// TODO N21-1337 remove class when tool versioning is removed
@Injectable()
export class CommonToolService {
/**
* @deprecated use ToolVersionService
*/
public determineToolConfigurationStatus(
externalTool: ExternalTool,
schoolExternalTool: SchoolExternalTool,
contextExternalTool: ContextExternalTool
): ContextExternalToolConfigurationStatus {
const configurationStatus: ContextExternalToolConfigurationStatus = new ContextExternalToolConfigurationStatus({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
isIncompleteOnScopeContext: false,
isDeactivated: false,
});

if (
this.isLatest(schoolExternalTool, externalTool) &&
this.isLatest(contextExternalTool, schoolExternalTool) &&
this.isLatest(contextExternalTool, externalTool)
) {
configurationStatus.isOutdatedOnScopeContext = false;
configurationStatus.isOutdatedOnScopeSchool = false;
} else {
configurationStatus.isOutdatedOnScopeContext = true;
configurationStatus.isOutdatedOnScopeSchool = true;
}

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

return configurationStatus;
}

private isLatest(tool1: ToolVersion, tool2: ToolVersion): boolean {
return tool1.getVersion() >= tool2.getVersion();
}

public isContextRestricted(externalTool: ExternalTool, context: ToolContextType): boolean {
if (externalTool.restrictToContexts?.length && !externalTool.restrictToContexts.includes(context)) {
return true;
Expand Down
Loading

0 comments on commit b15d641

Please sign in to comment.