Skip to content

Commit

Permalink
Merge branch 'main' into N21-841-use-user-login-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns authored Sep 19, 2023
2 parents 9e2e520 + 8cf1dca commit 36c6d2a
Show file tree
Hide file tree
Showing 116 changed files with 4,078 additions and 1,880 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ jobs:
- name: test image exists
run: |
mkdir -p ~/.docker
echo '{"experimental": "enabled"}' >> ~/.docker/config.json
echo "IMAGE_EXISTS=$(docker manifest inspect ghcr.io/${{ github.repository }}:${{ needs.branch_meta.outputs.sha }} > /dev/null && echo 1 || echo 0)" >> $GITHUB_ENV
- name: Set up Docker Buildx
Expand All @@ -61,7 +59,7 @@ jobs:

- name: Build and push ${{ github.repository }}
if: ${{ env.IMAGE_EXISTS == 0 }}
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
Expand All @@ -83,8 +81,6 @@ jobs:
- name: test image exists (file storage)
run: |
mkdir -p ~/.docker
echo '{"experimental": "enabled"}' >> ~/.docker/config.json
echo "IMAGE_EXISTS=$(docker manifest inspect ghcr.io/${{ github.repository }}:file-storage-${{ needs.branch_meta.outputs.sha }} > /dev/null && echo 1 || echo 0)" >> $GITHUB_ENV
- name: Set up Docker Buildx (file storage)
Expand All @@ -93,7 +89,7 @@ jobs:

- name: Build and push ${{ github.repository }} (file storage)
if: ${{ env.IMAGE_EXISTS == 0 }}
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v4
with:
build-args: |
BASE_IMAGE=ghcr.io/${{ github.repository }}:${{ needs.branch_meta.outputs.sha }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
password: ${{ secrets.QUAY_TOKEN }}

- name: Build and push ${{ github.repository }}
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
Expand All @@ -59,7 +59,7 @@ jobs:
labels: |
org.opencontainers.image.title=schulcloud-file-storage
- name: Build and push ${{ github.repository }} (file-storage)
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v4
with:
build-args: |
BASE_IMAGE=quay.io/schulcloudverbund/schulcloud-server:${{ github.ref_name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,49 @@ data:

# ========== End of the Dev IServ configuration section.

# ========== Start of the Test BRB Univention LDAP system (also used on the REF BRB) configuration section.

# This is currently performed for any 'brb-*' namespace ('brb-main' for example).

if [[ "$NS" =~ ^brb-[^\s]+$ ]]; then
UNIVENTION_LDAP_SYSTEM_ID=621beef78ec63ea12a3adae6
UNIVENTION_LDAP_FEDERAL_STATE_ID=0000b186816abba584714c53

# Encrypt LDAP server's search user password.
UNIVENTION_LDAP_SEARCH_USER_PASSWORD=$(node scripts/secret.js -s $AES_KEY -e $UNIVENTION_LDAP_SEARCH_USER_PASSWORD)

# Add (or replace) document with the test BRB Univention LDAP system configuration.
mongosh $DATABASE__URL --eval 'db.systems.replaceOne(
{
"_id": ObjectId("'$UNIVENTION_LDAP_SYSTEM_ID'"),
},
{
"_id": ObjectId("'$UNIVENTION_LDAP_SYSTEM_ID'"),
"alias": "TEST BRB UNIVENTION LDAP",
"ldapConfig": {
"active": true,
"federalState": ObjectId("'$UNIVENTION_LDAP_FEDERAL_STATE_ID'"),
"url": "'$UNIVENTION_LDAP_URL'",
"rootPath": "'$UNIVENTION_LDAP_ROOT_PATH'",
"searchUser": "'$UNIVENTION_LDAP_SEARCH_USER'",
"searchUserPassword": "'$UNIVENTION_LDAP_SEARCH_USER_PASSWORD'",
"provider": "univention",
"providerOptions": {
"userAttributeNameMapping": {},
"roleAttributeNameMapping": {},
"classAttributeNameMapping": {}
}
},
"type": "ldap"
},
{
"upsert": true
}
);'
fi

# ========== End of the Test BRB Univention LDAP system (also used on the REF BRB) configuration section.

# ========== Start of the Bettermarks tool configuration section.

# This is currently performed only for the following 4 namespaces:
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 @@ -8,6 +8,7 @@ import { enableOpenApiDocs } from '@shared/controller/swagger';
import { Mail, MailService } from '@shared/infra/mail';
import { LegacyLogger, Logger } from '@src/core/logger';
import { AccountService } from '@src/modules/account/services/account.service';
import { TeamService } from '@src/modules/teams/service/team.service';
import { AccountValidationService } from '@src/modules/account/services/account.validation.service';
import { AccountUc } from '@src/modules/account/uc/account.uc';
import { CollaborativeStorageUc } from '@src/modules/collaborative-storage/uc/collaborative-storage.uc';
Expand Down Expand Up @@ -76,6 +77,8 @@ async function bootstrap() {
feathersExpress.services['nest-account-uc'] = nestApp.get(AccountUc);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-collaborative-storage-uc'] = nestApp.get(CollaborativeStorageUc);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-team-service'] = nestApp.get(TeamService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-orm'] = orm;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,79 @@
import { INestApplicationContext } from '@nestjs/common';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { ConsoleWriterService } from '@shared/infra/console';
import { ServerConsoleModule } from '@src/console/console.module';
import { CommanderError } from 'commander';
import { execute, TestBootstrapConsole } from './test-bootstrap.console';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { TestBootstrapConsole, execute } from './test-bootstrap.console';

describe('DatabaseManagementConsole (API)', () => {
let app: INestApplicationContext;
let console: BootstrapConsole;
let bootstrap: BootstrapConsole;
let consoleService: ConsoleService;
beforeAll(async () => {
console = new TestBootstrapConsole({
let consoleWriter: ConsoleWriterService;

beforeEach(async () => {
bootstrap = new TestBootstrapConsole({
module: ServerConsoleModule,
useDecorators: true,
});
app = await console.init();
app = await bootstrap.init();
await app.init();
consoleService = app.get(ConsoleService);
consoleWriter = app.get(ConsoleWriterService);
});

afterAll(async () => {
afterEach(async () => {
consoleService.resetCli();
await app.close();
});

describe('Command "database"', () => {
beforeEach(() => {
const setup = () => {
const cli = consoleService.getCli('database');
const exitFn = (err: CommanderError) => {
if (err.exitCode !== 0) throw err;
};
cli?.exitOverride(exitFn);
const rootCli = consoleService.getRootCli();
rootCli.exitOverride(exitFn);
});
const spyConsoleWriterInfo = jest.spyOn(consoleWriter, 'info');
return { spyConsoleWriterInfo };
};
describe('when command not exists', () => {
it('should fail for unknown command', async () => {
setup();
await expect(execute(bootstrap, ['database', 'not_existing_command'])).rejects.toThrow(
`error: unknown command 'not_existing_command'`
);

afterEach(() => {
consoleService.resetCli();
consoleService.resetCli();
});
});

it('should fail for unknown command', async () => {
await expect(execute(console, ['database', 'not_existing_command'])).rejects.toThrow(
`error: unknown command 'not_existing_command'`
);
});
it('should provide command "seed"', async () => {
await execute(console, ['database', 'seed']);
});
it('should provide command "export"', async () => {
await execute(console, ['database', 'export']);
describe('when command exists', () => {
it('should provide command "seed"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'seed']);

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should provide command "export"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'export']);

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should provide command "sync-indexes"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'sync-indexes']);

expect(spyConsoleWriterInfo).toBeCalled();
});
});
});
});
10 changes: 9 additions & 1 deletion apps/server/src/console/api-test/test-bootstrap.console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ConsoleWriterService } from '@shared/infra/console';
import { DatabaseManagementUc } from '@src/modules/management/uc/database-management.uc';
import { AbstractBootstrapConsole, BootstrapConsole } from 'nestjs-console';

export class TestBootstrapConsole extends AbstractBootstrapConsole<TestingModule> {
create(): Promise<TestingModule> {
return Test.createTestingModule({
imports: [this.options.module],
}).compile();
})
.overrideProvider(DatabaseManagementUc)
.useValue(createMock<DatabaseManagementUc>())
.overrideProvider(ConsoleWriterService)
.useValue(createMock<ConsoleWriterService>())
.compile();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { CACHE_MANAGER } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Test, TestingModule } from '@nestjs/testing';
import { CacheService } from '@shared/infra/cache';
import { CacheStoreType } from '@shared/infra/cache/interface/cache-store-type.enum';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Inject, Injectable } from '@nestjs/common';
import { CacheService } from '@shared/infra/cache';
import { CacheStoreType } from '@shared/infra/cache/interface/cache-store-type.enum';
import {
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/modules/class/class.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ClassService } from './service';
import { ClassesRepo } from './repo';

@Module({
providers: [ClassService, ClassesRepo],
exports: [ClassService],
})
export class ClassModule {}
15 changes: 15 additions & 0 deletions apps/server/src/modules/class/domain/class-source-options.do.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface ClassSourceOptionsProps {
tspUid?: string;
}

export class ClassSourceOptions {
protected props: ClassSourceOptionsProps;

constructor(props: ClassSourceOptionsProps) {
this.props = props;
}

get tspUid(): string | undefined {
return this.props.tspUid;
}
}
77 changes: 77 additions & 0 deletions apps/server/src/modules/class/domain/class.do.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { EntityId } from '@shared/domain/types';
import { AuthorizableObject, DomainObject } from '../../../shared/domain/domain-object';
import { ClassSourceOptions } from './class-source-options.do';

export interface ClassProps extends AuthorizableObject {
name: string;
schoolId: EntityId;
userIds?: EntityId[];
teacherIds: EntityId[];
invitationLink?: string;
year?: EntityId;
gradeLevel?: number;
ldapDN?: string;
successor?: EntityId;
source?: string;
sourceOptions?: ClassSourceOptions;
createdAt: Date;
updatedAt: Date;
}

export class Class extends DomainObject<ClassProps> {
get name(): string {
return this.props.name;
}

get schoolId(): EntityId {
return this.props.schoolId;
}

get userIds(): EntityId[] | undefined {
return this.props.userIds;
}

get teacherIds(): EntityId[] {
return this.props.teacherIds;
}

get invitationLink(): string | undefined {
return this.props.invitationLink;
}

get year(): EntityId | undefined {
return this.props.year;
}

get gradeLevel(): number | undefined {
return this.props.gradeLevel;
}

get ldapDN(): string | undefined {
return this.props.ldapDN;
}

get successor(): EntityId | undefined {
return this.props.successor;
}

get source(): string | undefined {
return this.props.source;
}

get sourceOptions(): ClassSourceOptions | undefined {
return this.props.sourceOptions;
}

get createdAt(): Date {
return this.props.createdAt;
}

get updatedAt(): Date {
return this.props.updatedAt;
}

public removeUser(userId: string) {
this.props.userIds = this.props.userIds?.filter((userId1) => userId1 !== userId);
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/class/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './class.do';
Loading

0 comments on commit 36c6d2a

Please sign in to comment.