Skip to content

Commit

Permalink
Merge branch 'main' into BC-7971-room-members
Browse files Browse the repository at this point in the history
  • Loading branch information
EzzatOmar committed Oct 15, 2024
2 parents 66b10bc + 6752c05 commit 91fe96e
Show file tree
Hide file tree
Showing 141 changed files with 9,446 additions and 760 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ data:

# ========== Start of the CTL seed data configuration section.
echo "Inserting ctl seed data secrets to external-tools..."

# Encrypt secrets of external tools that contain an lti11 config.
CTL_SEED_SECRET_ONLINE_DIA_MATHE=$(node scripts/secret.js -s $AES_KEY -e $CTL_SEED_SECRET_ONLINE_DIA_MATHE)
CTL_SEED_SECRET_ONLINE_DIA_DEUTSCH=$(node scripts/secret.js -s $AES_KEY -e $CTL_SEED_SECRET_ONLINE_DIA_DEUTSCH)

mongosh $DATABASE__URL --quiet --eval 'db.getCollection("external-tools").updateOne(
{
"name": "Product Test Onlinediagnose Grundschule - Mathematik",
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/apps/server.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AccountService } from '@modules/account';
import { SystemRule } from '@modules/authorization/domain/rules';

Check warning on line 7 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/authorization/domain/rules' import is restricted from being used by a pattern. Do not deep import from a module

import { ColumnBoardService } from '@modules/board';
import { ContextExternalToolService } from '@src/modules/tool/context-external-tool';
import { CollaborativeStorageUc } from '@modules/collaborative-storage/uc/collaborative-storage.uc';

Check warning on line 11 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/collaborative-storage/uc/collaborative-storage.uc' import is restricted from being used by a pattern. Do not deep import from a module
import { GroupService } from '@modules/group';
import { InternalServerModule } from '@modules/internal-server';
Expand Down Expand Up @@ -94,6 +95,8 @@ async function bootstrap() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-column-board-service'] = nestApp.get(ColumnBoardService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-context-external-tool-service'] = nestApp.get(ContextExternalToolService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-system-rule'] = nestApp.get(SystemRule);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-orm'] = orm;
Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/imports-from-feathers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ export {
addTokenToWhitelist,
createRedisIdentifierFromJwtData,
ensureTokenIsWhitelisted,
getRedisData,
} from '../../../src/services/authentication/logic/whitelist.js';
export * as feathersRedis from '../../../src/utils/redis.js';
export type JwtRedisData = {
IP: string;
Browser: string;
Device: string;
privateDevice: boolean;
expirationInSeconds: number;
};
1 change: 1 addition & 0 deletions apps/server/src/infra/sync/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tsp';
22 changes: 17 additions & 5 deletions apps/server/src/infra/sync/sync.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { ConsoleWriterModule } from '@infra/console';
import { TspClientModule } from '@infra/tsp-client/tsp-client.module';
import { LegacySchoolModule } from '@modules/legacy-school';
import { SchoolModule } from '@modules/school';
import { SystemModule } from '@modules/system';
import { Module } from '@nestjs/common';
import { LoggerModule } from '@src/core/logger';
import { ConsoleWriterModule } from '@infra/console';
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { RabbitMQWrapperModule } from '@infra/rabbitmq';
import { SyncConsole } from './console/sync.console';
import { SyncUc } from './uc/sync.uc';
import { SyncService } from './service/sync.service';
import { TspSyncService } from './tsp/tsp-sync.service';
import { TspSyncStrategy } from './tsp/tsp-sync.strategy';
import { SyncUc } from './uc/sync.uc';

@Module({
imports: [LoggerModule, ConsoleWriterModule],
imports: [
LoggerModule,
ConsoleWriterModule,
...((Configuration.get('FEATURE_TSP_SYNC_ENABLED') as boolean)
? [TspClientModule, SystemModule, SchoolModule, LegacySchoolModule, RabbitMQWrapperModule]
: []),
],
providers: [
SyncConsole,
SyncUc,
SyncService,
...((Configuration.get('FEATURE_TSP_SYNC_ENABLED') as boolean) ? [TspSyncStrategy] : []),
...((Configuration.get('FEATURE_TSP_SYNC_ENABLED') as boolean) ? [TspSyncStrategy, TspSyncService] : []),
],
exports: [SyncConsole],
})
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/infra/sync/tsp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { TspSyncConfig } from './tsp-sync.config';
export { TspSyncStrategy } from './tsp-sync.strategy';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TspSchoolsFetchedLoggable } from './tsp-schools-fetched.loggable';

describe(TspSchoolsFetchedLoggable.name, () => {
let loggable: TspSchoolsFetchedLoggable;

beforeAll(() => {
loggable = new TspSchoolsFetchedLoggable(10, 5);
});

describe('when loggable is initialized', () => {
it('should be defined', () => {
expect(loggable).toBeDefined();
});
});

describe('getLogMessage', () => {
it('should return a log message', () => {
expect(loggable.getLogMessage()).toEqual({
message: `Fetched 10 schools for the last 5 days from TSP`,
data: {
tspSchoolCount: 10,
daysFetched: 5,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Loggable, LogMessage } from '@src/core/logger';

export class TspSchoolsFetchedLoggable implements Loggable {
constructor(private readonly tspSchoolCount: number, private readonly daysFetched: number) {}

getLogMessage(): LogMessage {
const message: LogMessage = {
message: `Fetched ${this.tspSchoolCount} schools for the last ${this.daysFetched} days from TSP`,
data: {
tspSchoolCount: this.tspSchoolCount,
daysFetched: this.daysFetched,
},
};

return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TspSchoolsSyncedLoggable } from './tsp-schools-synced.loggable';

describe(TspSchoolsSyncedLoggable.name, () => {
let loggable: TspSchoolsSyncedLoggable;

beforeAll(() => {
loggable = new TspSchoolsSyncedLoggable(10, 10, 5, 5);
});

describe('when loggable is initialized', () => {
it('should be defined', () => {
expect(loggable).toBeDefined();
});
});

describe('getLogMessage', () => {
it('should return a log message', () => {
expect(loggable.getLogMessage()).toEqual({
message: `Synced schools: Of 10 schools 10 were processed. 5 were created and 5 were updated`,
data: {
tspSchoolCount: 10,
processedSchools: 10,
createdSchools: 5,
updatedSchools: 5,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Loggable, LogMessage } from '@src/core/logger';

export class TspSchoolsSyncedLoggable implements Loggable {
constructor(
private readonly tspSchoolCount: number,
private readonly processedSchools: number,
private readonly createdSchools: number,
private readonly updatedSchools: number
) {}

getLogMessage(): LogMessage {
const message: LogMessage = {
message: `Synced schools: Of ${this.tspSchoolCount} schools ${this.processedSchools} were processed. ${this.createdSchools} were created and ${this.updatedSchools} were updated`,
data: {
tspSchoolCount: this.tspSchoolCount,
processedSchools: this.processedSchools,
createdSchools: this.createdSchools,
updatedSchools: this.updatedSchools,
},
};

return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { TspSchulnummerMissingLoggable } from './tsp-schulnummer-missing.loggable';

describe(TspSchulnummerMissingLoggable.name, () => {
let loggable: TspSchulnummerMissingLoggable;

beforeAll(() => {
loggable = new TspSchulnummerMissingLoggable('Schule');
});

describe('when loggable is initialized', () => {
it('should be defined', () => {
expect(loggable).toBeDefined();
});
});

describe('getLogMessage', () => {
it('should return a log message', () => {
expect(loggable.getLogMessage()).toEqual({
message: `The TSP school 'Schule' is missing a Schulnummer. This school is skipped.`,
data: {
schulName: 'Schule',
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Loggable, LogMessage } from '@src/core/logger';

export class TspSchulnummerMissingLoggable implements Loggable {
constructor(private readonly schulName?: string) {}

getLogMessage(): LogMessage {
const message: LogMessage = {
message: `The TSP school '${this.schulName ?? ''}' is missing a Schulnummer. This school is skipped.`,
data: {
schulName: this.schulName,
},
};

return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { TspSystemNotFoundLoggableException } from './tsp-system-not-found.loggable-exception';

describe(TspSystemNotFoundLoggableException.name, () => {
let loggable: TspSystemNotFoundLoggableException;

beforeAll(() => {
loggable = new TspSystemNotFoundLoggableException();
});

describe('when loggable is initialized', () => {
it('should be defined', () => {
expect(loggable).toBeDefined();
});
});

describe('getLogMessage', () => {
it('should return a log message', () => {
expect(loggable.getLogMessage()).toEqual({
message: 'The TSP system could not be found during the sync',
type: 'TSP_SYSTEM_NOT_FOUND',
stack: expect.any(String),
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { HttpStatus } from '@nestjs/common';
import { BusinessError, ErrorLogMessage } from '@shared/common';
import { Loggable, LogMessage } from '@src/core/logger';

export class TspSystemNotFoundLoggableException extends BusinessError implements Loggable {
constructor() {
super(
{
type: 'TSP_SYSTEM_NOT_FOUND',
title: 'The TSP system could not be found',
defaultMessage: 'The TSP system could not be found during the sync',
},
HttpStatus.BAD_REQUEST
);
}

getLogMessage(): LogMessage | ErrorLogMessage {
const message: LogMessage | ErrorLogMessage = {
message: this.message,
type: this.type,
stack: this.stack,
};

return message;
}
}
4 changes: 4 additions & 0 deletions apps/server/src/infra/sync/tsp/tsp-sync.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface TspSyncConfig {
TSP_SYNC_SCHOOL_LIMIT: number;
TSP_SYNC_SCHOOL_DAYS_TO_FETCH: number;
}
Loading

0 comments on commit 91fe96e

Please sign in to comment.