Skip to content

Commit

Permalink
refatorings
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Apr 18, 2024
1 parent 05f055d commit e4b6287
Show file tree
Hide file tree
Showing 41 changed files with 305 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,39 +247,40 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
}

async visitExternalToolElementAsync(original: ExternalToolElement): Promise<void> {
let status: CopyStatusEnum = CopyStatusEnum.SUCCESS;

const copy = new ExternalToolElement({
const boardElementCopy: ExternalToolElement = new ExternalToolElement({
id: new ObjectId().toHexString(),
contextExternalToolId: undefined,
children: [],
createdAt: new Date(),
updatedAt: new Date(),
});

let status: CopyStatusEnum;
if (this.toolFeatures.ctlToolsCopyEnabled && original.contextExternalToolId) {
const tool: ContextExternalTool | null = await this.contextExternalToolService.findById(
const linkedTool: ContextExternalTool | null = await this.contextExternalToolService.findById(
original.contextExternalToolId
);

if (tool) {
const copiedTool: ContextExternalTool = await this.contextExternalToolService.copyContextExternalTool(
tool,
copy.id
);
if (linkedTool) {
const contextExternalToolCopy: ContextExternalTool =
await this.contextExternalToolService.copyContextExternalTool(linkedTool, boardElementCopy.id);

boardElementCopy.contextExternalToolId = contextExternalToolCopy.id;

copy.contextExternalToolId = copiedTool.id;
status = CopyStatusEnum.SUCCESS;
} else {
status = CopyStatusEnum.FAIL;
}
} else {
status = CopyStatusEnum.SUCCESS;
}

this.resultMap.set(original.id, {
copyEntity: copy,
copyEntity: boardElementCopy,
type: CopyElementType.EXTERNAL_TOOL_ELEMENT,
status,
});
this.copyMap.set(original.id, copy);
this.copyMap.set(original.id, boardElementCopy);

return Promise.resolve();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,8 @@ describe(MediaAvailableLineService.name, () => {

service.createMediaAvailableLine(availableExternalTools);

expect(externalToolLogoService.buildLogoUrl).toHaveBeenCalledWith(
'/v3/tools/external-tools/{id}/logo',
externalTool1
);
expect(externalToolLogoService.buildLogoUrl).toHaveBeenCalledWith(
'/v3/tools/external-tools/{id}/logo',
externalTool2
);
expect(externalToolLogoService.buildLogoUrl).toHaveBeenCalledWith(externalTool1);
expect(externalToolLogoService.buildLogoUrl).toHaveBeenCalledWith(externalTool2);
});

it('should create a media available line with correct elements', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ export class MediaAvailableLineService {
externalTool: ExternalTool,
schoolExternalTool: SchoolExternalTool
): MediaAvailableLineElement {
const logoUrl: string | undefined = this.externalToolLogoService.buildLogoUrl(
'/v3/tools/external-tools/{id}/logo',
externalTool
);
const logoUrl: string | undefined = this.externalToolLogoService.buildLogoUrl(externalTool);

const element: MediaAvailableLineElement = new MediaAvailableLineElement({
schoolExternalToolId: schoolExternalTool.id ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface GroupUserEntityProps {
}

@Embeddable()
export class GroupUserEntity {
export class GroupUserEmbeddable {
@ManyToOne(() => User)
user: User;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface GroupValidPeriodEntityProps {
}

@Embeddable()
export class GroupValidPeriodEntity {
export class GroupValidPeriodEmbeddable {
@Property()
from: Date;

Expand Down
24 changes: 12 additions & 12 deletions apps/server/src/modules/group/entity/group.entity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Collection, Embedded, Entity, Enum, ManyToOne, OneToMany, Property } from '@mikro-orm/core';
import { Course as CourseEntity } from '@shared/domain/entity';
import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity';
import { ExternalSourceEntity } from '@shared/domain/entity/external-source.entity';
import { ExternalSourceEmbeddable } from '@shared/domain/entity/external-source.embeddable';
import { SchoolEntity } from '@shared/domain/entity/school.entity';
import { EntityId } from '@shared/domain/types';
import { GroupUserEntity } from './group-user.entity';
import { GroupValidPeriodEntity } from './group-valid-period.entity';
import { GroupUserEmbeddable } from './group-user.embeddable';
import { GroupValidPeriodEmbeddable } from './group-valid-period.embeddable';

export enum GroupEntityTypes {
CLASS = 'class',
Expand All @@ -20,11 +20,11 @@ export interface GroupEntityProps {

type: GroupEntityTypes;

externalSource?: ExternalSourceEntity;
externalSource?: ExternalSourceEmbeddable;

validPeriod?: GroupValidPeriodEntity;
validPeriod?: GroupValidPeriodEmbeddable;

users: GroupUserEntity[];
users: GroupUserEmbeddable[];

organization?: SchoolEntity;
}
Expand All @@ -37,14 +37,14 @@ export class GroupEntity extends BaseEntityWithTimestamps {
@Enum()
type: GroupEntityTypes;

@Embedded(() => ExternalSourceEntity, { nullable: true })
externalSource?: ExternalSourceEntity;
@Embedded(() => ExternalSourceEmbeddable, { nullable: true })
externalSource?: ExternalSourceEmbeddable;

@Embedded(() => GroupValidPeriodEntity, { nullable: true })
validPeriod?: GroupValidPeriodEntity;
@Embedded(() => GroupValidPeriodEmbeddable, { nullable: true })
validPeriod?: GroupValidPeriodEmbeddable;

@Embedded(() => GroupUserEntity, { array: true })
users: GroupUserEntity[];
@Embedded(() => GroupUserEmbeddable, { array: true })
users: GroupUserEmbeddable[];

@ManyToOne(() => SchoolEntity, { nullable: true })
organization?: SchoolEntity;
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/group/entity/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './group.entity';
export * from './group-user.entity';
export * from './group-valid-period.entity';
export * from './group-user.embeddable';
export * from './group-valid-period.embeddable';
22 changes: 11 additions & 11 deletions apps/server/src/modules/group/repo/group-domain.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EntityData } from '@mikro-orm/core';
import { EntityManager } from '@mikro-orm/mongodb';
import { ExternalSource } from '@shared/domain/domainobject';
import { ExternalSourceEntity, Role, SchoolEntity, SystemEntity, User } from '@shared/domain/entity';
import { ExternalSourceEmbeddable, Role, SchoolEntity, SystemEntity, User } from '@shared/domain/entity';
import { Group, GroupProps, GroupTypes, GroupUser } from '../domain';
import { GroupEntity, GroupEntityTypes, GroupUserEntity, GroupValidPeriodEntity } from '../entity';
import { GroupEntity, GroupEntityTypes, GroupUserEmbeddable, GroupValidPeriodEmbeddable } from '../entity';

const GroupEntityTypesToGroupTypesMapping: Record<GroupEntityTypes, GroupTypes> = {
[GroupEntityTypes.CLASS]: GroupTypes.CLASS,
Expand All @@ -21,9 +21,9 @@ export class GroupDomainMapper {
static mapDoToEntityData(group: Group, em: EntityManager): EntityData<GroupEntity> {
const props: GroupProps = group.getProps();

let validPeriod: GroupValidPeriodEntity | undefined;
let validPeriod: GroupValidPeriodEmbeddable | undefined;
if (props.validFrom && props.validUntil) {
validPeriod = new GroupValidPeriodEntity({
validPeriod = new GroupValidPeriodEmbeddable({
from: props.validFrom,
until: props.validUntil,
});
Expand All @@ -36,7 +36,7 @@ export class GroupDomainMapper {
? this.mapExternalSourceToExternalSourceEntity(props.externalSource, em)
: undefined,
users: props.users.map(
(groupUser): GroupUserEntity => GroupDomainMapper.mapGroupUserToGroupUserEntity(groupUser, em)
(groupUser): GroupUserEmbeddable => GroupDomainMapper.mapGroupUserToGroupUserEntity(groupUser, em)
),
validPeriod,
organization: props.organizationId ? em.getReference(SchoolEntity, props.organizationId) : undefined,
Expand Down Expand Up @@ -65,16 +65,16 @@ export class GroupDomainMapper {
static mapExternalSourceToExternalSourceEntity(
externalSource: ExternalSource,
em: EntityManager
): ExternalSourceEntity {
const externalSourceEntity: ExternalSourceEntity = new ExternalSourceEntity({
): ExternalSourceEmbeddable {
const externalSourceEntity: ExternalSourceEmbeddable = new ExternalSourceEmbeddable({
externalId: externalSource.externalId,
system: em.getReference(SystemEntity, externalSource.systemId),
});

return externalSourceEntity;
}

static mapExternalSourceEntityToExternalSource(entity: ExternalSourceEntity): ExternalSource {
static mapExternalSourceEntityToExternalSource(entity: ExternalSourceEmbeddable): ExternalSource {
const externalSource: ExternalSource = new ExternalSource({
externalId: entity.externalId,
systemId: entity.system.id,
Expand All @@ -83,16 +83,16 @@ export class GroupDomainMapper {
return externalSource;
}

static mapGroupUserToGroupUserEntity(groupUser: GroupUser, em: EntityManager): GroupUserEntity {
const groupUserEntity: GroupUserEntity = new GroupUserEntity({
static mapGroupUserToGroupUserEntity(groupUser: GroupUser, em: EntityManager): GroupUserEmbeddable {
const groupUserEntity: GroupUserEmbeddable = new GroupUserEmbeddable({
user: em.getReference(User, groupUser.userId),
role: em.getReference(Role, groupUser.roleId),
});

return groupUserEntity;
}

static mapGroupUserEntityToGroupUser(entity: GroupUserEntity): GroupUser {
static mapGroupUserEntityToGroupUser(entity: GroupUserEmbeddable): GroupUser {
const groupUser: GroupUser = new GroupUser({
userId: entity.user.id,
roleId: entity.role.id,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/group/repo/group.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
userFactory,
} from '@shared/testing';
import { Group, GroupProps, GroupTypes, GroupUser } from '../domain';
import { GroupEntity, GroupEntityTypes, GroupUserEntity } from '../entity';
import { GroupEntity, GroupEntityTypes, GroupUserEmbeddable } from '../entity';
import { GroupRepo } from './group.repo';

describe('GroupRepo', () => {
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('GroupRepo', () => {
const setup = async () => {
const userEntity: User = userFactory.buildWithId();
const user: UserDO = userDoFactory.build({ id: userEntity.id });
const groupUserEntity: GroupUserEntity = new GroupUserEntity({
const groupUserEntity: GroupUserEmbeddable = new GroupUserEmbeddable({
user: userEntity,
role: roleFactory.buildWithId(),
});
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/modules/server/api/dto/config.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ export class ConfigResponse {
@ApiProperty()
FEATURE_MEDIA_SHELF_ENABLED: boolean;

@ApiProperty()
FEATURE_MIGRATION_WIZARD_WITH_USER_LOGIN_MIGRATION: boolean;

constructor(config: ServerConfig) {
this.ACCESSIBILITY_REPORT_EMAIL = config.ACCESSIBILITY_REPORT_EMAIL;
this.ADMIN_TABLES_DISPLAY_CONSENT_COLUMN = config.ADMIN_TABLES_DISPLAY_CONSENT_COLUMN;
Expand Down Expand Up @@ -260,5 +263,6 @@ export class ConfigResponse {
this.FEATURE_VIDEOCONFERENCE_ENABLED = config.enabled;
this.FEATURE_SCHULCONNEX_COURSE_SYNC_ENABLED = config.FEATURE_SCHULCONNEX_COURSE_SYNC_ENABLED;
this.FEATURE_MEDIA_SHELF_ENABLED = config.FEATURE_MEDIA_SHELF_ENABLED;
this.FEATURE_MIGRATION_WIZARD_WITH_USER_LOGIN_MIGRATION = config.useWithUserLoginMigration;
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/server/api/test/server.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('Server Controller (API)', () => {
'TLDRAW__ASSETS_MAX_SIZE',
'FEATURE_SCHULCONNEX_COURSE_SYNC_ENABLED',
'FEATURE_MEDIA_SHELF_ENABLED',
'FEATURE_MIGRATION_WIZARD_WITH_USER_LOGIN_MIGRATION',
];

expect(response.status).toEqual(HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { RestrictedContextMismatchLoggableException } from './restricted-context-mismatch-loggabble';
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ToolContextType } from '../../common/enum';
import { RestrictedContextMismatchLoggable } from './restricted-context-mismatch-loggabble';
import { ToolContextType } from '../../../common/enum';
import { RestrictedContextMismatchLoggableException } from './restricted-context-mismatch-loggabble';

describe('RestrictedContextMismatchLoggable', () => {
describe('getLogMessage', () => {
const setup = () => {
const externalToolName = 'name';
const context: ToolContextType = ToolContextType.COURSE;
const loggable = new RestrictedContextMismatchLoggable(externalToolName, context);
const loggable = new RestrictedContextMismatchLoggableException(externalToolName, context);

return { loggable, externalToolName, context };
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { UnprocessableEntityException } from '@nestjs/common';
import { Loggable } from '@src/core/logger/interfaces';
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { ToolContextType } from '../../common/enum';
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { ToolContextType } from '../../../common/enum';

export class RestrictedContextMismatchLoggable extends UnprocessableEntityException implements Loggable {
export class RestrictedContextMismatchLoggableException extends UnprocessableEntityException implements Loggable {
constructor(private readonly externalToolName: string, private readonly context: ToolContextType) {
super();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './context-external-tool.do';
export * from './context-ref';
export * from './tool-reference';
export { RestrictedContextMismatchLoggableException } from './error';
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { AuthorizationContext, AuthorizationContextBuilder, AuthorizationService } from '@modules/authorization';
import { NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { Permission } from '@shared/domain/interface';
import { ContextExternalToolRepo } from '@shared/repo';
import {
contextExternalToolFactory,
Expand All @@ -9,19 +12,15 @@ import {
legacySchoolDoFactory,
schoolExternalToolFactory,
} from '@shared/testing/factory/domainobject';
import { AuthorizationContext, AuthorizationContextBuilder, AuthorizationService } from '@modules/authorization';
import { ObjectId } from '@mikro-orm/mongodb';
import { Permission } from '@shared/domain/interface';
import { CustomParameter } from '../../common/domain';
import { ToolContextType } from '../../common/enum';
import { SchoolExternalTool, SchoolExternalToolWithId } from '../../school-external-tool/domain';
import { ContextExternalTool, ContextRef } from '../domain';
import { ContextExternalToolService } from './context-external-tool.service';
import { ExternalTool } from '../../external-tool/domain';
import { CommonToolService } from '../../common/service';
import { ExternalToolService } from '../../external-tool';
import { ExternalTool } from '../../external-tool/domain';
import { SchoolExternalToolService } from '../../school-external-tool';
import { RestrictedContextMismatchLoggable } from './restricted-context-mismatch-loggabble';
import { CommonToolService } from '../../common/service';
import { CustomParameter } from '../../common/domain';
import { SchoolExternalTool, SchoolExternalToolWithId } from '../../school-external-tool/domain';
import { ContextExternalTool, ContextRef, RestrictedContextMismatchLoggableException } from '../domain';
import { ContextExternalToolService } from './context-external-tool.service';

describe('ContextExternalToolService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -397,7 +396,7 @@ describe('ContextExternalToolService', () => {
const { contextExternalTool, externalTool } = setup();

await expect(service.checkContextRestrictions(contextExternalTool)).rejects.toThrow(
new RestrictedContextMismatchLoggable(externalTool.name, contextExternalTool.contextRef.type)
new RestrictedContextMismatchLoggableException(externalTool.name, contextExternalTool.contextRef.type)
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { ExternalTool } from '../../external-tool/domain';
import { ExternalToolService } from '../../external-tool/service';
import { SchoolExternalTool } from '../../school-external-tool/domain';
import { SchoolExternalToolService } from '../../school-external-tool/service';
import { ContextExternalTool, ContextExternalToolWithId, ContextRef } from '../domain';
import {
ContextExternalTool,
ContextExternalToolWithId,
ContextRef,
RestrictedContextMismatchLoggableException,
} from '../domain';
import { ContextExternalToolQuery } from '../uc/dto/context-external-tool.types';
import { RestrictedContextMismatchLoggable } from './restricted-context-mismatch-loggabble';

@Injectable()
export class ContextExternalToolService {
Expand Down Expand Up @@ -75,7 +79,7 @@ export class ContextExternalToolService {
const externalTool: ExternalTool = await this.externalToolService.findById(schoolExternalTool.toolId);

if (this.commonToolService.isContextRestricted(externalTool, contextExternalTool.contextRef.type)) {
throw new RestrictedContextMismatchLoggable(externalTool.name, contextExternalTool.contextRef.type);
throw new RestrictedContextMismatchLoggableException(externalTool.name, contextExternalTool.contextRef.type);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './context-external-tool.service';
export * from './context-external-tool-authorizable.service';
export * from './tool-reference.service';
export { ToolConfigurationStatusService } from './tool-configuration-status.service';
Loading

0 comments on commit e4b6287

Please sign in to comment.