From 8b9feea3ee6f3ea966759ece215b4985946ae62f Mon Sep 17 00:00:00 2001 From: Uwe Ilgenstein Date: Wed, 27 Nov 2024 21:27:26 +0100 Subject: [PATCH] rename room-member to room-membership --- .../mikro-orm/Migration202411271951208.ts | 15 +++ .../src/modules/board/board-api.module.ts | 4 +- .../src/modules/board/board-ws-api.module.ts | 11 ++- apps/server/src/modules/board/board.module.ts | 4 +- .../board-context-in-rooms.api.spec.ts | 4 +- .../api-test/board-create-in-room.api.spec.ts | 8 +- .../api-test/board-delete-in-room.api.spec.ts | 4 +- .../api-test/board-lookup-in-room.api.spec.ts | 4 +- .../board-update-title-in-room.api.spec.ts | 4 +- .../board-visibility-in-room.api.spec.ts | 4 +- .../internal/board-context.service.spec.ts | 26 ++--- .../service/internal/board-context.service.ts | 9 +- .../src/modules/board/uc/board.uc.spec.ts | 6 +- apps/server/src/modules/board/uc/board.uc.ts | 8 +- apps/server/src/modules/room-member/index.ts | 9 -- .../modules/room-member/repo/entity/index.ts | 1 - .../repo/room-member-domain.mapper.spec.ts | 93 ------------------ .../repo/room-member-domain.mapper.ts | 37 ------- .../room-member/repo/room-member.repo.ts | 64 ------------- .../modules/room-member/room-member.module.ts | 15 --- .../src/modules/room-member/testing/index.ts | 2 - .../room-membership.rule.spec.ts} | 46 ++++----- .../authorization/room-membership.rule.ts} | 10 +- .../do/room-membership-authorizable.do.ts} | 4 +- .../do/room-membership.do.spec.ts} | 20 ++-- .../do/room-membership.do.ts} | 8 +- .../src/modules/room-membership/index.ts | 9 ++ .../room-membership/repo/entity/index.ts | 1 + .../repo/entity/room-membership.entity.ts} | 10 +- .../room-membership-domain.mapper.spec.ts | 93 ++++++++++++++++++ .../repo/room-membership-domain.mapper.ts | 37 +++++++ .../repo/room-membership.repo.spec.ts} | 54 +++++------ .../repo/room-membership.repo.ts | 64 +++++++++++++ .../room-membership/room-membership.module.ts | 15 +++ .../service/room-membership.service.spec.ts} | 96 +++++++++---------- .../service/room-membership.service.ts} | 44 +++++---- .../modules/room-membership/testing/index.ts | 2 + .../room-membership-entity.factory.ts} | 6 +- .../testing/room-membership.factory.ts} | 6 +- .../dto/request/create-room.body.params.ts | 4 +- .../dto/request/update-room.body.params.ts | 4 +- .../dto/response/room-board-item.response.ts | 2 +- .../api/dto/response/room-details.response.ts | 2 +- .../modules/room/api/mapper/room.mapper.ts | 2 +- .../src/modules/room/api/room.uc.spec.ts | 18 ++-- apps/server/src/modules/room/api/room.uc.ts | 42 ++++---- .../api/test/room-add-members.api.spec.ts | 8 +- .../room/api/test/room-create.api.spec.ts | 8 +- .../room/api/test/room-delete.api.spec.ts | 8 +- .../room/api/test/room-get-boards.api.spec.ts | 12 +-- .../room/api/test/room-get.api.spec.ts | 8 +- .../room/api/test/room-index.api.spec.ts | 8 +- .../room/api/test/room-members.api.spec.ts | 8 +- .../api/test/room-remove-members.api.spec.ts | 8 +- .../room/api/test/room-update.api.spec.ts | 6 +- .../src/modules/room/room-api.module.ts | 4 +- .../src/modules/sharing/sharing-api.module.ts | 18 ++-- .../modules/sharing/uc/share-token.uc.spec.ts | 12 +-- .../src/modules/sharing/uc/share-token.uc.ts | 16 ++-- .../src/shared/domain/entity/all-entities.ts | 4 +- backup/setup/migrations.json | 9 ++ 61 files changed, 551 insertions(+), 517 deletions(-) create mode 100644 apps/server/src/migrations/mikro-orm/Migration202411271951208.ts delete mode 100644 apps/server/src/modules/room-member/index.ts delete mode 100644 apps/server/src/modules/room-member/repo/entity/index.ts delete mode 100644 apps/server/src/modules/room-member/repo/room-member-domain.mapper.spec.ts delete mode 100644 apps/server/src/modules/room-member/repo/room-member-domain.mapper.ts delete mode 100644 apps/server/src/modules/room-member/repo/room-member.repo.ts delete mode 100644 apps/server/src/modules/room-member/room-member.module.ts delete mode 100644 apps/server/src/modules/room-member/testing/index.ts rename apps/server/src/modules/{room-member/authorization/room-member.rule.spec.ts => room-membership/authorization/room-membership.rule.spec.ts} (60%) rename apps/server/src/modules/{room-member/authorization/room-member.rule.ts => room-membership/authorization/room-membership.rule.ts} (69%) rename apps/server/src/modules/{room-member/do/room-member-authorizable.do.ts => room-membership/do/room-membership-authorizable.do.ts} (79%) rename apps/server/src/modules/{room-member/do/room-member.do.spec.ts => room-membership/do/room-membership.do.spec.ts} (60%) rename apps/server/src/modules/{room-member/do/room-member.do.ts => room-membership/do/room-membership.do.ts} (75%) create mode 100644 apps/server/src/modules/room-membership/index.ts create mode 100644 apps/server/src/modules/room-membership/repo/entity/index.ts rename apps/server/src/modules/{room-member/repo/entity/room-member.entity.ts => room-membership/repo/entity/room-membership.entity.ts} (67%) create mode 100644 apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.spec.ts create mode 100644 apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.ts rename apps/server/src/modules/{room-member/repo/room-member.repo.spec.ts => room-membership/repo/room-membership.repo.spec.ts} (63%) create mode 100644 apps/server/src/modules/room-membership/repo/room-membership.repo.ts create mode 100644 apps/server/src/modules/room-membership/room-membership.module.ts rename apps/server/src/modules/{room-member/service/room-member.service.spec.ts => room-membership/service/room-membership.service.spec.ts} (68%) rename apps/server/src/modules/{room-member/service/room-member.service.ts => room-membership/service/room-membership.service.ts} (73%) create mode 100644 apps/server/src/modules/room-membership/testing/index.ts rename apps/server/src/modules/{room-member/testing/room-member-entity.factory.ts => room-membership/testing/room-membership-entity.factory.ts} (57%) rename apps/server/src/modules/{room-member/testing/room-member.factory.ts => room-membership/testing/room-membership.factory.ts} (55%) diff --git a/apps/server/src/migrations/mikro-orm/Migration202411271951208.ts b/apps/server/src/migrations/mikro-orm/Migration202411271951208.ts new file mode 100644 index 00000000000..0b74ac61e63 --- /dev/null +++ b/apps/server/src/migrations/mikro-orm/Migration202411271951208.ts @@ -0,0 +1,15 @@ +import { Migration } from '@mikro-orm/migrations-mongodb'; + +export class Migration20241127195120 extends Migration { + async up(): Promise { + const db = this.driver.getConnection().getDb(); + await db.renameCollection('room-members', 'room-memberships'); + console.info('Collection renamed from room-members to room-memberships'); + } + + async down(): Promise { + const db = this.driver.getConnection().getDb(); + await db.renameCollection('room-memberships', 'room-members'); + console.info('Collection renamed from room-memberships to room-members'); + } +} diff --git a/apps/server/src/modules/board/board-api.module.ts b/apps/server/src/modules/board/board-api.module.ts index 83d5c1ebb73..e4fa5ac9cb0 100644 --- a/apps/server/src/modules/board/board-api.module.ts +++ b/apps/server/src/modules/board/board-api.module.ts @@ -2,7 +2,7 @@ import { AuthorizationModule } from '@modules/authorization'; import { forwardRef, Module } from '@nestjs/common'; import { CourseRepo } from '@shared/repo/course'; import { LoggerModule } from '@src/core/logger'; -import { RoomMemberModule } from '@modules/room-member'; +import { RoomMembershipModule } from '@src/modules/room-membership'; import { BoardModule } from './board.module'; import { BoardController, @@ -16,7 +16,7 @@ import { BoardUc, CardUc, ColumnUc, ElementUc, SubmissionItemUc } from './uc'; import { RoomModule } from '../room'; @Module({ - imports: [BoardModule, LoggerModule, RoomMemberModule, RoomModule, forwardRef(() => AuthorizationModule)], + imports: [BoardModule, LoggerModule, RoomMembershipModule, RoomModule, forwardRef(() => AuthorizationModule)], controllers: [BoardController, ColumnController, CardController, ElementController, BoardSubmissionController], providers: [BoardUc, BoardNodePermissionService, ColumnUc, CardUc, ElementUc, SubmissionItemUc, CourseRepo], }) diff --git a/apps/server/src/modules/board/board-ws-api.module.ts b/apps/server/src/modules/board/board-ws-api.module.ts index 8c2e07203f7..663b1417b5d 100644 --- a/apps/server/src/modules/board/board-ws-api.module.ts +++ b/apps/server/src/modules/board/board-ws-api.module.ts @@ -3,7 +3,7 @@ import { UserModule } from '@modules/user'; import { forwardRef, Module } from '@nestjs/common'; import { CourseRepo } from '@shared/repo/course'; import { LoggerModule } from '@src/core/logger'; -import { RoomMemberModule } from '../room-member'; +import { RoomMembershipModule } from '../room-membership'; import { BoardModule } from './board.module'; import { BoardCollaborationGateway } from './gateway/board-collaboration.gateway'; import { MetricsService } from './metrics/metrics.service'; @@ -12,7 +12,14 @@ import { BoardUc, CardUc, ColumnUc, ElementUc } from './uc'; import { RoomModule } from '../room'; @Module({ - imports: [BoardModule, forwardRef(() => AuthorizationModule), LoggerModule, UserModule, RoomMemberModule, RoomModule], + imports: [ + BoardModule, + forwardRef(() => AuthorizationModule), + LoggerModule, + UserModule, + RoomMembershipModule, + RoomModule, + ], providers: [ BoardCollaborationGateway, BoardNodePermissionService, diff --git a/apps/server/src/modules/board/board.module.ts b/apps/server/src/modules/board/board.module.ts index 7a2142e1204..e8d703431bd 100644 --- a/apps/server/src/modules/board/board.module.ts +++ b/apps/server/src/modules/board/board.module.ts @@ -10,7 +10,7 @@ import { CqrsModule } from '@nestjs/cqrs'; import { CourseRepo } from '@shared/repo/course'; import { LoggerModule } from '@src/core/logger'; import { AuthorizationModule } from '../authorization'; -import { RoomMemberModule } from '../room-member'; +import { RoomMembershipModule } from '../room-membership'; import { BoardNodeRule } from './authorisation/board-node.rule'; import { BoardNodeFactory } from './domain'; import { BoardNodeRepo } from './repo'; @@ -46,7 +46,7 @@ import { CqrsModule, CollaborativeTextEditorModule, AuthorizationModule, - RoomMemberModule, + RoomMembershipModule, ], providers: [ // TODO: move BoardDoAuthorizableService, BoardDoRepo, BoardDoService, BoardNodeRepo in separate module and move mediaboard related services in mediaboard module diff --git a/apps/server/src/modules/board/controller/api-test/board-context-in-rooms.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-context-in-rooms.api.spec.ts index 1461f141013..9fe85f82b51 100644 --- a/apps/server/src/modules/board/controller/api-test/board-context-in-rooms.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-context-in-rooms.api.spec.ts @@ -6,7 +6,7 @@ import { TestApiClient, cleanupCollections, groupEntityFactory, roleFactory, use import { Permission, RoleName } from '@shared/domain/interface'; import { accountFactory } from '@src/modules/account/testing'; import { GroupEntityTypes } from '@src/modules/group/entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; import { roomEntityFactory } from '@src/modules/room/testing'; import { columnBoardEntityFactory } from '../../testing'; import { BoardExternalReferenceType } from '../../domain'; @@ -66,7 +66,7 @@ describe('board get context in room (api)', () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([ accountWithEditRole, diff --git a/apps/server/src/modules/board/controller/api-test/board-create-in-room.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-create-in-room.api.spec.ts index 3da8c8240da..a79c2559c43 100644 --- a/apps/server/src/modules/board/controller/api-test/board-create-in-room.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-create-in-room.api.spec.ts @@ -7,7 +7,7 @@ import { RoleName } from '@shared/domain/interface/rolename.enum'; import { cleanupCollections, groupEntityFactory, roleFactory, TestApiClient, userFactory } from '@shared/testing'; import { accountFactory } from '@src/modules/account/testing'; import { GroupEntityTypes } from '@src/modules/group/entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; import { roomEntityFactory } from '@src/modules/room/testing'; import { BoardExternalReferenceType, BoardLayout } from '../../domain'; import { BoardNodeEntity } from '../../repo'; @@ -54,7 +54,7 @@ describe(`create board in room (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([account, user, role, userGroup, room, roomMember]); em.clear(); @@ -170,7 +170,7 @@ describe(`create board in room (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([account, user, role, userGroup, room, roomMember]); em.clear(); @@ -238,7 +238,7 @@ describe(`create board in room (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([account, user, role, userGroup, room, roomMember]); em.clear(); diff --git a/apps/server/src/modules/board/controller/api-test/board-delete-in-room.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-delete-in-room.api.spec.ts index 30f05f7953f..dbb50f06c32 100644 --- a/apps/server/src/modules/board/controller/api-test/board-delete-in-room.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-delete-in-room.api.spec.ts @@ -7,7 +7,7 @@ import { accountFactory } from '@src/modules/account/testing'; import { Permission, RoleName } from '@shared/domain/interface'; import { GroupEntityTypes } from '@src/modules/group/entity'; import { roomEntityFactory } from '@src/modules/room/testing'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; import { columnBoardEntityFactory, columnEntityFactory } from '../../testing'; import { BoardNodeEntity } from '../../repo'; import { BoardExternalReferenceType } from '../../domain'; @@ -61,7 +61,7 @@ describe(`board delete in room (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([ accountWithEditRole, diff --git a/apps/server/src/modules/board/controller/api-test/board-lookup-in-room.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-lookup-in-room.api.spec.ts index 952140cc19e..76d617c9525 100644 --- a/apps/server/src/modules/board/controller/api-test/board-lookup-in-room.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-lookup-in-room.api.spec.ts @@ -7,7 +7,7 @@ import { cleanupCollections, groupEntityFactory, roleFactory, TestApiClient, use import { Permission, RoleName } from '@shared/domain/interface'; import { accountFactory } from '@src/modules/account/testing'; import { GroupEntityTypes } from '@src/modules/group/entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; import { roomEntityFactory } from '@src/modules/room/testing'; import { BoardExternalReferenceType, BoardLayout } from '../../domain'; import { BoardResponse } from '../dto'; @@ -62,7 +62,7 @@ describe(`board lookup in room (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([ accountWithEditRole, diff --git a/apps/server/src/modules/board/controller/api-test/board-update-title-in-room.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-update-title-in-room.api.spec.ts index 8cf0930de8a..d074df6a0eb 100644 --- a/apps/server/src/modules/board/controller/api-test/board-update-title-in-room.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-update-title-in-room.api.spec.ts @@ -7,7 +7,7 @@ import { TestApiClient, cleanupCollections, groupEntityFactory, roleFactory, use import { Permission, RoleName } from '@shared/domain/interface'; import { accountFactory } from '@src/modules/account/testing'; import { GroupEntityTypes } from '@src/modules/group/entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; import { roomEntityFactory } from '@src/modules/room/testing'; import { BoardNodeEntity } from '../../repo'; import { columnBoardEntityFactory } from '../../testing'; @@ -68,7 +68,7 @@ describe(`board update title with room relation (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([ accountWithEditRole, diff --git a/apps/server/src/modules/board/controller/api-test/board-visibility-in-room.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-visibility-in-room.api.spec.ts index 56a0e52e71e..58a1669774e 100644 --- a/apps/server/src/modules/board/controller/api-test/board-visibility-in-room.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-visibility-in-room.api.spec.ts @@ -6,7 +6,7 @@ import { TestApiClient, cleanupCollections, groupEntityFactory, roleFactory, use import { Permission, RoleName } from '@shared/domain/interface'; import { accountFactory } from '@src/modules/account/testing'; import { GroupEntityTypes } from '@src/modules/group/entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; import { roomEntityFactory } from '@src/modules/room/testing'; import { BoardExternalReferenceType } from '../../domain'; import { columnBoardEntityFactory } from '../../testing'; @@ -67,7 +67,7 @@ describe(`board update visibility with room relation (api)`, () => { const room = roomEntityFactory.buildWithId(); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([ accountWithEditRole, diff --git a/apps/server/src/modules/board/service/internal/board-context.service.spec.ts b/apps/server/src/modules/board/service/internal/board-context.service.spec.ts index 82859128268..ecf3656b2d3 100644 --- a/apps/server/src/modules/board/service/internal/board-context.service.spec.ts +++ b/apps/server/src/modules/board/service/internal/board-context.service.spec.ts @@ -5,26 +5,26 @@ import { Permission, RoleName } from '@shared/domain/interface'; import { CourseRepo } from '@shared/repo/course'; import { courseFactory, groupFactory, roleFactory, setupEntities, userFactory } from '@shared/testing'; import { GroupTypes } from '@src/modules/group'; -import { RoomMemberService } from '@src/modules/room-member'; -import { roomMemberFactory } from '@src/modules/room-member/testing'; +import { RoomMembershipService } from '@src/modules/room-membership'; +import { roomMembershipFactory } from '@src/modules/room-membership/testing'; import { roomFactory } from '@src/modules/room/testing'; import { BoardExternalReferenceType, BoardRoles, UserWithBoardRoles } from '../../domain'; import { columnBoardFactory, columnFactory } from '../../testing'; import { BoardContextService } from './board-context.service'; -describe(`${BoardContextService.name}`, () => { +describe(BoardContextService.name, () => { let module: TestingModule; let service: BoardContextService; let courseRepo: DeepMocked; - let roomMemberService: DeepMocked; + let roomMembershipService: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ providers: [ BoardContextService, { - provide: RoomMemberService, - useValue: createMock(), + provide: RoomMembershipService, + useValue: createMock(), }, { provide: CourseRepo, @@ -34,7 +34,7 @@ describe(`${BoardContextService.name}`, () => { }).compile(); service = module.get(BoardContextService); - roomMemberService = module.get(RoomMemberService); + roomMembershipService = module.get(RoomMembershipService); courseRepo = module.get(CourseRepo); await setupEntities(); @@ -221,7 +221,7 @@ describe(`${BoardContextService.name}`, () => { const role = roleFactory.build({ name: RoleName.ROOMEDITOR, permissions: [Permission.ROOM_EDIT] }); const group = groupFactory.build({ type: GroupTypes.ROOM, users: [{ userId: user.id, roleId: role.id }] }); const room = roomFactory.build(); - roomMemberFactory.build({ roomId: room.id, userGroupId: group.id }); + roomMembershipFactory.build({ roomId: room.id, userGroupId: group.id }); const columnBoard = columnBoardFactory.build({ context: { id: room.id, type: BoardExternalReferenceType.Room }, }); @@ -232,7 +232,7 @@ describe(`${BoardContextService.name}`, () => { it('should return their information + editor role', async () => { const { columnBoard, role, user } = setup(); - roomMemberService.getRoomMemberAuthorizable.mockResolvedValue({ + roomMembershipService.getRoomMembershipAuthorizable.mockResolvedValue({ id: 'foo', roomId: columnBoard.context.id, members: [{ userId: user.id, roles: [role] }], @@ -256,7 +256,7 @@ describe(`${BoardContextService.name}`, () => { const role = roleFactory.build({ name: RoleName.ROOMVIEWER, permissions: [Permission.ROOM_VIEW] }); const group = groupFactory.build({ type: GroupTypes.ROOM, users: [{ userId: user.id, roleId: role.id }] }); const room = roomFactory.build(); - roomMemberFactory.build({ roomId: room.id, userGroupId: group.id }); + roomMembershipFactory.build({ roomId: room.id, userGroupId: group.id }); const columnBoard = columnBoardFactory.build({ context: { id: room.id, type: BoardExternalReferenceType.Room }, }); @@ -267,7 +267,7 @@ describe(`${BoardContextService.name}`, () => { it('should return their information + reader role', async () => { const { columnBoard, role, user } = setup(); - roomMemberService.getRoomMemberAuthorizable.mockResolvedValue({ + roomMembershipService.getRoomMembershipAuthorizable.mockResolvedValue({ id: 'foo', roomId: columnBoard.context.id, members: [{ userId: user.id, roles: [role] }], @@ -291,7 +291,7 @@ describe(`${BoardContextService.name}`, () => { const role = roleFactory.build(); const group = groupFactory.build({ type: GroupTypes.ROOM, users: [{ userId: user.id, roleId: role.id }] }); const room = roomFactory.build(); - roomMemberFactory.build({ roomId: room.id, userGroupId: group.id }); + roomMembershipFactory.build({ roomId: room.id, userGroupId: group.id }); const columnBoard = columnBoardFactory.build({ context: { id: room.id, type: BoardExternalReferenceType.Room }, }); @@ -302,7 +302,7 @@ describe(`${BoardContextService.name}`, () => { it('should return their information + no role', async () => { const { columnBoard, role, user } = setup(); - roomMemberService.getRoomMemberAuthorizable.mockResolvedValue({ + roomMembershipService.getRoomMembershipAuthorizable.mockResolvedValue({ id: 'foo', roomId: columnBoard.context.id, members: [{ userId: user.id, roles: [role] }], diff --git a/apps/server/src/modules/board/service/internal/board-context.service.ts b/apps/server/src/modules/board/service/internal/board-context.service.ts index 66c78a1ac1f..32b6ef1df2d 100644 --- a/apps/server/src/modules/board/service/internal/board-context.service.ts +++ b/apps/server/src/modules/board/service/internal/board-context.service.ts @@ -2,13 +2,12 @@ import { Injectable } from '@nestjs/common'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; import { CourseRepo } from '@shared/repo/course'; -import { RoomMemberService } from '@src/modules/room-member'; -import { UserWithRoomRoles } from '@src/modules/room-member/do/room-member-authorizable.do'; +import { RoomMembershipService, UserWithRoomRoles } from '@src/modules/room-membership'; import { AnyBoardNode, BoardExternalReferenceType, BoardRoles, UserWithBoardRoles } from '../../domain'; @Injectable() export class BoardContextService { - constructor(private readonly courseRepo: CourseRepo, private readonly roomMemberService: RoomMemberService) {} + constructor(private readonly courseRepo: CourseRepo, private readonly roomMembershipService: RoomMembershipService) {} async getUsersWithBoardRoles(rootNode: AnyBoardNode): Promise { if (!('context' in rootNode)) { @@ -31,8 +30,8 @@ export class BoardContextService { } private async getFromRoom(roomId: EntityId): Promise { - const roomMemberAuthorizable = await this.roomMemberService.getRoomMemberAuthorizable(roomId); - const usersWithRoles: UserWithBoardRoles[] = roomMemberAuthorizable.members.map((member) => { + const roomMembershipAuthorizable = await this.roomMembershipService.getRoomMembershipAuthorizable(roomId); + const usersWithRoles: UserWithBoardRoles[] = roomMembershipAuthorizable.members.map((member) => { const roles = this.getBoardRolesFromRoomMember(member); return { userId: member.userId, diff --git a/apps/server/src/modules/board/uc/board.uc.spec.ts b/apps/server/src/modules/board/uc/board.uc.spec.ts index 2706ff151ba..ff22353895b 100644 --- a/apps/server/src/modules/board/uc/board.uc.spec.ts +++ b/apps/server/src/modules/board/uc/board.uc.spec.ts @@ -8,7 +8,7 @@ import { setupEntities, userFactory } from '@shared/testing'; import { courseFactory } from '@shared/testing/factory'; import { LegacyLogger } from '@src/core/logger'; import { RoomService } from '@src/modules/room'; -import { RoomMemberService } from '@src/modules/room-member'; +import { RoomMembershipService } from '@src/modules/room-membership'; import { CopyElementType, CopyStatus, CopyStatusEnum } from '../../copy-helper'; import { BoardExternalReferenceType, BoardLayout, BoardNodeFactory, Column, ColumnBoard } from '../domain'; import { BoardNodePermissionService, BoardNodeService, ColumnBoardService } from '../service'; @@ -58,8 +58,8 @@ describe(BoardUc.name, () => { useValue: createMock(), }, { - provide: RoomMemberService, - useValue: createMock(), + provide: RoomMembershipService, + useValue: createMock(), }, { provide: LegacyLogger, diff --git a/apps/server/src/modules/board/uc/board.uc.ts b/apps/server/src/modules/board/uc/board.uc.ts index 31abada02d5..c18a722304a 100644 --- a/apps/server/src/modules/board/uc/board.uc.ts +++ b/apps/server/src/modules/board/uc/board.uc.ts @@ -7,7 +7,7 @@ import { CourseRepo } from '@shared/repo/course'; import { LegacyLogger } from '@src/core/logger'; import { StorageLocation } from '@src/modules/files-storage/interface'; import { RoomService } from '@src/modules/room'; -import { RoomMemberService } from '@src/modules/room-member'; +import { RoomMembershipService } from '@src/modules/room-membership'; import { CreateBoardBodyParams } from '../controller/dto'; import { BoardExternalReference, BoardExternalReferenceType, BoardNodeFactory, Column, ColumnBoard } from '../domain'; import { BoardNodePermissionService, BoardNodeService, ColumnBoardService } from '../service'; @@ -19,7 +19,7 @@ export class BoardUc { @Inject(forwardRef(() => AuthorizationService)) // TODO is this needed? private readonly authorizationService: AuthorizationService, private readonly boardPermissionService: BoardNodePermissionService, - private readonly roomMemberService: RoomMemberService, + private readonly roomMembershipService: RoomMembershipService, private readonly boardNodeService: BoardNodeService, private readonly columnBoardService: ColumnBoardService, private readonly logger: LegacyLogger, @@ -158,9 +158,9 @@ export class BoardUc { requiredPermissions: [Permission.COURSE_EDIT], }); } else if (context.type === BoardExternalReferenceType.Room) { - const roomMemberAuthorizable = await this.roomMemberService.getRoomMemberAuthorizable(context.id); + const roomMembershipAuthorizable = await this.roomMembershipService.getRoomMembershipAuthorizable(context.id); - this.authorizationService.checkPermission(user, roomMemberAuthorizable, { + this.authorizationService.checkPermission(user, roomMembershipAuthorizable, { action: Action.write, requiredPermissions: [], }); diff --git a/apps/server/src/modules/room-member/index.ts b/apps/server/src/modules/room-member/index.ts deleted file mode 100644 index 772b42aa05a..00000000000 --- a/apps/server/src/modules/room-member/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { RoomMemberEntity } from './repo/entity'; -import { RoomMemberRepo } from './repo/room-member.repo'; -import { RoomMemberService } from './service/room-member.service'; - -export * from './do/room-member.do'; -export * from './room-member.module'; -export { RoomMemberEntity, RoomMemberRepo, RoomMemberService }; - -export { UserWithRoomRoles, RoomMemberAuthorizable } from './do/room-member-authorizable.do'; diff --git a/apps/server/src/modules/room-member/repo/entity/index.ts b/apps/server/src/modules/room-member/repo/entity/index.ts deleted file mode 100644 index 845b87253da..00000000000 --- a/apps/server/src/modules/room-member/repo/entity/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './room-member.entity'; diff --git a/apps/server/src/modules/room-member/repo/room-member-domain.mapper.spec.ts b/apps/server/src/modules/room-member/repo/room-member-domain.mapper.spec.ts deleted file mode 100644 index d2629ebef65..00000000000 --- a/apps/server/src/modules/room-member/repo/room-member-domain.mapper.spec.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { RoomMember, RoomMemberProps } from '../do/room-member.do'; -import { roomMemberEntityFactory } from '../testing'; -import { RoomMemberEntity } from './entity'; -import { RoomMemberDomainMapper } from './room-member-domain.mapper'; - -describe('RoomMemberDomainMapper', () => { - describe('mapEntityToDo', () => { - it('should correctly map roomMemberEntity to RoomMember domain object', () => { - const roomMemberEntity = { - id: '1', - } as RoomMemberEntity; - - const result = RoomMemberDomainMapper.mapEntityToDo(roomMemberEntity); - - expect(result).toBeInstanceOf(RoomMember); - expect(result.getProps()).toEqual({ - id: '1', - }); - }); - - it('should return existing domainObject if present, regardless of entity properties', () => { - const existingRoomMember = new RoomMember({ - id: '1', - roomId: 'r1', - userGroupId: 'ug1', - createdAt: new Date('2023-01-01'), - updatedAt: new Date('2023-01-01'), - }); - - const roomMemberEntity = { - id: '1', - domainObject: existingRoomMember, - } as RoomMemberEntity; - - const result = RoomMemberDomainMapper.mapEntityToDo(roomMemberEntity); - - expect(result).toBe(existingRoomMember); - expect(result).toBeInstanceOf(RoomMember); - expect(result.getProps()).toEqual({ - id: '1', - roomId: 'r1', - userGroupId: 'ug1', - createdAt: new Date('2023-01-01'), - updatedAt: new Date('2023-01-01'), - }); - expect(result.getProps().id).toBe('1'); - expect(result.getProps().id).toBe(roomMemberEntity.id); - }); - - it('should wrap the actual entity reference in the domain object', () => { - const roomMemberEntity = { - id: '1', - } as RoomMemberEntity; - - const result = RoomMemberDomainMapper.mapEntityToDo(roomMemberEntity); - // @ts-expect-error check necessary - const { props } = result; - - expect(props === roomMemberEntity).toBe(true); - }); - }); - - describe('mapDoToEntity', () => { - describe('when domain object props are instanceof roomMemberEntity', () => { - it('should return the entity', () => { - const roomMemberEntity = roomMemberEntityFactory.build(); - const roomMember = new RoomMember(roomMemberEntity); - - const result = RoomMemberDomainMapper.mapDoToEntity(roomMember); - - expect(result).toBe(roomMemberEntity); - }); - }); - - describe('when domain object props are not instanceof roomMemberEntity', () => { - it('should convert them to an entity and return it', () => { - const roomMemberEntity: RoomMemberProps = { - id: '66d581c3ef74c548a4efea1d', - roomId: '66d581c3ef74c548a4efea1a', - userGroupId: '66d581c3ef74c548a4efea1b', - createdAt: new Date('2024-10-1'), - updatedAt: new Date('2024-10-1'), - }; - const room = new RoomMember(roomMemberEntity); - - const result = RoomMemberDomainMapper.mapDoToEntity(room); - - expect(result).toBeInstanceOf(RoomMemberEntity); - expect(result).toMatchObject(roomMemberEntity); - }); - }); - }); -}); diff --git a/apps/server/src/modules/room-member/repo/room-member-domain.mapper.ts b/apps/server/src/modules/room-member/repo/room-member-domain.mapper.ts deleted file mode 100644 index 73163a07769..00000000000 --- a/apps/server/src/modules/room-member/repo/room-member-domain.mapper.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { RoomMember } from '../do/room-member.do'; -import { RoomMemberEntity } from './entity'; - -export class RoomMemberDomainMapper { - static mapEntityToDo(roomMemberEntity: RoomMemberEntity): RoomMember { - // check identity map reference - if (roomMemberEntity.domainObject) { - return roomMemberEntity.domainObject; - } - - const roomMember = new RoomMember(roomMemberEntity); - - // attach to identity map - roomMemberEntity.domainObject = roomMember; - - return roomMember; - } - - static mapDoToEntity(roomMember: RoomMember): RoomMemberEntity { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const { props } = roomMember; - - if (!(props instanceof RoomMemberEntity)) { - const entity = new RoomMemberEntity(); - Object.assign(entity, props); - - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - roomMember.props = entity; - - return entity; - } - - return props; - } -} diff --git a/apps/server/src/modules/room-member/repo/room-member.repo.ts b/apps/server/src/modules/room-member/repo/room-member.repo.ts deleted file mode 100644 index 022383fffaf..00000000000 --- a/apps/server/src/modules/room-member/repo/room-member.repo.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Utils } from '@mikro-orm/core'; -import { EntityManager } from '@mikro-orm/mongodb'; -import { Injectable } from '@nestjs/common'; -import { EntityId } from '@shared/domain/types'; -import { RoomMember } from '../do/room-member.do'; -import { RoomMemberEntity } from './entity'; -import { RoomMemberDomainMapper } from './room-member-domain.mapper'; - -@Injectable() -export class RoomMemberRepo { - constructor(private readonly em: EntityManager) {} - - async findByRoomId(roomId: EntityId): Promise { - const roomMemberEntities = await this.em.findOne(RoomMemberEntity, { roomId }); - if (!roomMemberEntities) return null; - - const roomMembers = RoomMemberDomainMapper.mapEntityToDo(roomMemberEntities); - - return roomMembers; - } - - async findByRoomIds(roomIds: EntityId[]): Promise { - const entities = await this.em.find(RoomMemberEntity, { roomId: { $in: roomIds } }); - const roomMembers = entities.map((entity) => RoomMemberDomainMapper.mapEntityToDo(entity)); - - return roomMembers; - } - - async findByGroupId(groupId: EntityId): Promise { - const entities = await this.em.find(RoomMemberEntity, { userGroupId: groupId }); - const roomMembers = entities.map((entity) => RoomMemberDomainMapper.mapEntityToDo(entity)); - - return roomMembers; - } - - async findByGroupIds(groupIds: EntityId[]): Promise { - const entities = await this.em.find(RoomMemberEntity, { userGroupId: { $in: groupIds } }); - const roomMembers = entities.map((entity) => RoomMemberDomainMapper.mapEntityToDo(entity)); - - return roomMembers; - } - - async save(roomMember: RoomMember | RoomMember[]): Promise { - const roomMembers = Utils.asArray(roomMember); - - roomMembers.forEach((member) => { - const entity = RoomMemberDomainMapper.mapDoToEntity(member); - this.em.persist(entity); - }); - - await this.em.flush(); - } - - async delete(roomMember: RoomMember | RoomMember[]): Promise { - const roomMembers = Utils.asArray(roomMember); - - roomMembers.forEach((member) => { - const entity = RoomMemberDomainMapper.mapDoToEntity(member); - this.em.remove(entity); - }); - - await this.em.flush(); - } -} diff --git a/apps/server/src/modules/room-member/room-member.module.ts b/apps/server/src/modules/room-member/room-member.module.ts deleted file mode 100644 index b07ace89160..00000000000 --- a/apps/server/src/modules/room-member/room-member.module.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { GroupModule } from '@modules/group'; -import { Module } from '@nestjs/common'; -import { CqrsModule } from '@nestjs/cqrs'; -import { AuthorizationModule } from '../authorization'; -import { RoleModule } from '../role'; -import { RoomMemberRule } from './authorization/room-member.rule'; -import { RoomMemberRepo } from './repo/room-member.repo'; -import { RoomMemberService } from './service/room-member.service'; - -@Module({ - imports: [AuthorizationModule, CqrsModule, GroupModule, RoleModule], - providers: [RoomMemberService, RoomMemberRepo, RoomMemberRule], - exports: [RoomMemberService], -}) -export class RoomMemberModule {} diff --git a/apps/server/src/modules/room-member/testing/index.ts b/apps/server/src/modules/room-member/testing/index.ts deleted file mode 100644 index 7f1a2950ff5..00000000000 --- a/apps/server/src/modules/room-member/testing/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './room-member-entity.factory'; -export * from './room-member.factory'; diff --git a/apps/server/src/modules/room-member/authorization/room-member.rule.spec.ts b/apps/server/src/modules/room-membership/authorization/room-membership.rule.spec.ts similarity index 60% rename from apps/server/src/modules/room-member/authorization/room-member.rule.spec.ts rename to apps/server/src/modules/room-membership/authorization/room-membership.rule.spec.ts index 1ca26adb941..6946c83aa8d 100644 --- a/apps/server/src/modules/room-member/authorization/room-member.rule.spec.ts +++ b/apps/server/src/modules/room-membership/authorization/room-membership.rule.spec.ts @@ -1,22 +1,22 @@ import { Test, TestingModule } from '@nestjs/testing'; import { Permission } from '@shared/domain/interface'; import { roleDtoFactory, setupEntities, userFactory } from '@shared/testing'; -import { Action, AuthorizationHelper, AuthorizationInjectionService } from '@src/modules/authorization'; -import { RoomMemberAuthorizable } from '../do/room-member-authorizable.do'; -import { RoomMemberRule } from './room-member.rule'; +import { Action, AuthorizationHelper, AuthorizationInjectionService } from '@modules/authorization'; +import { RoomMembershipAuthorizable } from '../do/room-membership-authorizable.do'; +import { RoomMembershipRule } from './room-membership.rule'; -describe(RoomMemberRule.name, () => { - let service: RoomMemberRule; +describe(RoomMembershipRule.name, () => { + let service: RoomMembershipRule; let injectionService: AuthorizationInjectionService; beforeAll(async () => { await setupEntities(); const module: TestingModule = await Test.createTestingModule({ - providers: [RoomMemberRule, AuthorizationHelper, AuthorizationInjectionService], + providers: [RoomMembershipRule, AuthorizationHelper, AuthorizationInjectionService], }).compile(); - service = await module.get(RoomMemberRule); + service = await module.get(RoomMembershipRule); injectionService = await module.get(AuthorizationInjectionService); }); @@ -30,14 +30,14 @@ describe(RoomMemberRule.name, () => { describe('when entity is applicable', () => { const setup = () => { const user = userFactory.buildWithId(); - const roomMemberAuthorizable = new RoomMemberAuthorizable('', []); + const roomMembershipAuthorizable = new RoomMembershipAuthorizable('', []); - return { user, roomMemberAuthorizable }; + return { user, roomMembershipAuthorizable }; }; it('should return true', () => { - const { user, roomMemberAuthorizable } = setup(); - const result = service.isApplicable(user, roomMemberAuthorizable); + const { user, roomMembershipAuthorizable } = setup(); + const result = service.isApplicable(user, roomMembershipAuthorizable); expect(result).toStrictEqual(true); }); @@ -64,15 +64,15 @@ describe(RoomMemberRule.name, () => { const setup = () => { const user = userFactory.buildWithId(); const roleDto = roleDtoFactory.build({ permissions: [Permission.ROOM_VIEW] }); - const roomMemberAuthorizable = new RoomMemberAuthorizable('', [{ roles: [roleDto], userId: user.id }]); + const roomMembershipAuthorizable = new RoomMembershipAuthorizable('', [{ roles: [roleDto], userId: user.id }]); - return { user, roomMemberAuthorizable }; + return { user, roomMembershipAuthorizable }; }; it('should return "true" for read action', () => { - const { user, roomMemberAuthorizable } = setup(); + const { user, roomMembershipAuthorizable } = setup(); - const res = service.hasPermission(user, roomMemberAuthorizable, { + const res = service.hasPermission(user, roomMembershipAuthorizable, { action: Action.read, requiredPermissions: [], }); @@ -81,9 +81,9 @@ describe(RoomMemberRule.name, () => { }); it('should return "false" for write action', () => { - const { user, roomMemberAuthorizable } = setup(); + const { user, roomMembershipAuthorizable } = setup(); - const res = service.hasPermission(user, roomMemberAuthorizable, { + const res = service.hasPermission(user, roomMembershipAuthorizable, { action: Action.write, requiredPermissions: [], }); @@ -95,15 +95,15 @@ describe(RoomMemberRule.name, () => { describe('when user is not member of room', () => { const setup = () => { const user = userFactory.buildWithId(); - const roomMemberAuthorizable = new RoomMemberAuthorizable('', []); + const roomMembershipAuthorizable = new RoomMembershipAuthorizable('', []); - return { user, roomMemberAuthorizable }; + return { user, roomMembershipAuthorizable }; }; it('should return "false" for read action', () => { - const { user, roomMemberAuthorizable } = setup(); + const { user, roomMembershipAuthorizable } = setup(); - const res = service.hasPermission(user, roomMemberAuthorizable, { + const res = service.hasPermission(user, roomMembershipAuthorizable, { action: Action.read, requiredPermissions: [], }); @@ -112,9 +112,9 @@ describe(RoomMemberRule.name, () => { }); it('should return "false" for write action', () => { - const { user, roomMemberAuthorizable } = setup(); + const { user, roomMembershipAuthorizable } = setup(); - const res = service.hasPermission(user, roomMemberAuthorizable, { + const res = service.hasPermission(user, roomMembershipAuthorizable, { action: Action.write, requiredPermissions: [], }); diff --git a/apps/server/src/modules/room-member/authorization/room-member.rule.ts b/apps/server/src/modules/room-membership/authorization/room-membership.rule.ts similarity index 69% rename from apps/server/src/modules/room-member/authorization/room-member.rule.ts rename to apps/server/src/modules/room-membership/authorization/room-membership.rule.ts index 7a98c93a215..cfcd11c33af 100644 --- a/apps/server/src/modules/room-member/authorization/room-member.rule.ts +++ b/apps/server/src/modules/room-membership/authorization/room-membership.rule.ts @@ -1,22 +1,22 @@ import { Injectable } from '@nestjs/common'; import { User } from '@shared/domain/entity'; import { Permission } from '@shared/domain/interface'; -import { AuthorizationInjectionService, Action, AuthorizationContext, Rule } from '@src/modules/authorization'; -import { RoomMemberAuthorizable } from '../do/room-member-authorizable.do'; +import { AuthorizationInjectionService, Action, AuthorizationContext, Rule } from '@modules/authorization'; +import { RoomMembershipAuthorizable } from '../do/room-membership-authorizable.do'; @Injectable() -export class RoomMemberRule implements Rule { +export class RoomMembershipRule implements Rule { constructor(private readonly authorisationInjectionService: AuthorizationInjectionService) { this.authorisationInjectionService.injectAuthorizationRule(this); } public isApplicable(user: User, object: unknown): boolean { - const isMatched = object instanceof RoomMemberAuthorizable; + const isMatched = object instanceof RoomMembershipAuthorizable; return isMatched; } - public hasPermission(user: User, object: RoomMemberAuthorizable, context: AuthorizationContext): boolean { + public hasPermission(user: User, object: RoomMembershipAuthorizable, context: AuthorizationContext): boolean { const { action } = context; const permissionsThisUserHas = object.members .filter((member) => member.userId === user.id) diff --git a/apps/server/src/modules/room-member/do/room-member-authorizable.do.ts b/apps/server/src/modules/room-membership/do/room-membership-authorizable.do.ts similarity index 79% rename from apps/server/src/modules/room-member/do/room-member-authorizable.do.ts rename to apps/server/src/modules/room-membership/do/room-membership-authorizable.do.ts index 1728d0045b9..61821fa4b82 100644 --- a/apps/server/src/modules/room-member/do/room-member-authorizable.do.ts +++ b/apps/server/src/modules/room-membership/do/room-membership-authorizable.do.ts @@ -1,13 +1,13 @@ import { AuthorizableObject } from '@shared/domain/domain-object'; import { EntityId } from '@shared/domain/types'; -import { RoleDto } from '@src/modules/role'; +import { RoleDto } from '@modules/role'; export type UserWithRoomRoles = { roles: RoleDto[]; userId: EntityId; }; -export class RoomMemberAuthorizable implements AuthorizableObject { +export class RoomMembershipAuthorizable implements AuthorizableObject { public readonly id: EntityId = ''; public readonly roomId: EntityId; diff --git a/apps/server/src/modules/room-member/do/room-member.do.spec.ts b/apps/server/src/modules/room-membership/do/room-membership.do.spec.ts similarity index 60% rename from apps/server/src/modules/room-member/do/room-member.do.spec.ts rename to apps/server/src/modules/room-membership/do/room-membership.do.spec.ts index d7ed3fb03ac..5dc0735fc0d 100644 --- a/apps/server/src/modules/room-member/do/room-member.do.spec.ts +++ b/apps/server/src/modules/room-membership/do/room-membership.do.spec.ts @@ -1,11 +1,11 @@ import { EntityId } from '@shared/domain/types'; -import { roomMemberFactory } from '../testing'; -import { RoomMember, RoomMemberProps } from './room-member.do'; +import { roomMembershipFactory } from '../testing'; +import { RoomMembership, RoomMembershipProps } from './room-membership.do'; -describe('RoomMember', () => { - let roomMember: RoomMember; +describe('RoomMembership', () => { + let roomMember: RoomMembership; const roomMemberId: EntityId = 'roomMemberId'; - const roomMemberProps: RoomMemberProps = { + const roomMembershipProps: RoomMembershipProps = { id: roomMemberId, roomId: 'roomId', userGroupId: 'userGroupId', @@ -14,11 +14,11 @@ describe('RoomMember', () => { }; beforeEach(() => { - roomMember = new RoomMember(roomMemberProps); + roomMember = new RoomMembership(roomMembershipProps); }); it('should props without domainObject', () => { - const mockDomainObject = roomMemberFactory.build(); + const mockDomainObject = roomMembershipFactory.build(); // this tests the hotfix for the mikro-orm issue // eslint-disable-next-line @typescript-eslint/dot-notation roomMember['domainObject'] = mockDomainObject; @@ -29,14 +29,14 @@ describe('RoomMember', () => { const { domainObject, ...props } = roomMember.getProps(); expect(domainObject).toEqual(undefined); - expect(props).toEqual(roomMemberProps); + expect(props).toEqual(roomMembershipProps); }); it('should get roomId', () => { - expect(roomMember.roomId).toEqual(roomMemberProps.roomId); + expect(roomMember.roomId).toEqual(roomMembershipProps.roomId); }); it('should get userGroupId', () => { - expect(roomMember.userGroupId).toEqual(roomMemberProps.userGroupId); + expect(roomMember.userGroupId).toEqual(roomMembershipProps.userGroupId); }); }); diff --git a/apps/server/src/modules/room-member/do/room-member.do.ts b/apps/server/src/modules/room-membership/do/room-membership.do.ts similarity index 75% rename from apps/server/src/modules/room-member/do/room-member.do.ts rename to apps/server/src/modules/room-membership/do/room-membership.do.ts index 8aeebfffbda..e8654923cb4 100644 --- a/apps/server/src/modules/room-member/do/room-member.do.ts +++ b/apps/server/src/modules/room-membership/do/room-membership.do.ts @@ -1,7 +1,7 @@ import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object'; import { EntityId } from '@shared/domain/types'; -export interface RoomMemberProps extends AuthorizableObject { +export interface RoomMembershipProps extends AuthorizableObject { id: EntityId; roomId: EntityId; userGroupId: EntityId; @@ -9,12 +9,12 @@ export interface RoomMemberProps extends AuthorizableObject { updatedAt: Date; } -export class RoomMember extends DomainObject { - public constructor(props: RoomMemberProps) { +export class RoomMembership extends DomainObject { + public constructor(props: RoomMembershipProps) { super(props); } - public getProps(): RoomMemberProps { + public getProps(): RoomMembershipProps { // Note: Propagated hotfix. Will be resolved with mikro-orm update. Look at the comment in board-node.do.ts. // eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/apps/server/src/modules/room-membership/index.ts b/apps/server/src/modules/room-membership/index.ts new file mode 100644 index 00000000000..be6ccd4b3ac --- /dev/null +++ b/apps/server/src/modules/room-membership/index.ts @@ -0,0 +1,9 @@ +import { RoomMembershipEntity } from './repo/entity'; +import { RoomMembershipRepo } from './repo/room-membership.repo'; +import { RoomMembershipService } from './service/room-membership.service'; + +export * from './do/room-membership.do'; +export * from './room-membership.module'; +export { RoomMembershipEntity, RoomMembershipRepo, RoomMembershipService }; + +export { UserWithRoomRoles, RoomMembershipAuthorizable } from './do/room-membership-authorizable.do'; diff --git a/apps/server/src/modules/room-membership/repo/entity/index.ts b/apps/server/src/modules/room-membership/repo/entity/index.ts new file mode 100644 index 00000000000..43e58e0db14 --- /dev/null +++ b/apps/server/src/modules/room-membership/repo/entity/index.ts @@ -0,0 +1 @@ +export * from './room-membership.entity'; diff --git a/apps/server/src/modules/room-member/repo/entity/room-member.entity.ts b/apps/server/src/modules/room-membership/repo/entity/room-membership.entity.ts similarity index 67% rename from apps/server/src/modules/room-member/repo/entity/room-member.entity.ts rename to apps/server/src/modules/room-membership/repo/entity/room-membership.entity.ts index 3aacb3f1069..f9b9c37bebd 100644 --- a/apps/server/src/modules/room-member/repo/entity/room-member.entity.ts +++ b/apps/server/src/modules/room-membership/repo/entity/room-membership.entity.ts @@ -3,9 +3,9 @@ import { AuthorizableObject } from '@shared/domain/domain-object'; import { ObjectIdType } from '@shared/repo/types/object-id.type'; import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity'; import { EntityId } from '@shared/domain/types'; -import { RoomMember } from '../../do/room-member.do'; +import { RoomMembership } from '../../do/room-membership.do'; -export interface RoomMemberEntityProps extends AuthorizableObject { +export interface RoomMembershipEntityProps extends AuthorizableObject { id: EntityId; roomId: EntityId; userGroupId: EntityId; @@ -13,9 +13,9 @@ export interface RoomMemberEntityProps extends AuthorizableObject { updatedAt: Date; } -@Entity({ tableName: 'room-members' }) +@Entity({ tableName: 'room-memberships' }) @Unique({ properties: ['roomId', 'userGroupId'] }) -export class RoomMemberEntity extends BaseEntityWithTimestamps implements RoomMemberEntityProps { +export class RoomMembershipEntity extends BaseEntityWithTimestamps implements RoomMembershipEntityProps { @Unique() @Property({ type: ObjectIdType, fieldName: 'room' }) roomId!: EntityId; @@ -24,5 +24,5 @@ export class RoomMemberEntity extends BaseEntityWithTimestamps implements RoomMe userGroupId!: EntityId; @Property({ persist: false }) - domainObject: RoomMember | undefined; + domainObject: RoomMembership | undefined; } diff --git a/apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.spec.ts b/apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.spec.ts new file mode 100644 index 00000000000..74ae9033575 --- /dev/null +++ b/apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.spec.ts @@ -0,0 +1,93 @@ +import { RoomMembership, RoomMembershipProps } from '../do/room-membership.do'; +import { roomMembershipEntityFactory } from '../testing'; +import { RoomMembershipEntity } from './entity'; +import { RoomMembershipDomainMapper } from './room-membership-domain.mapper'; + +describe('RoomMembershipDomainMapper', () => { + describe('mapEntityToDo', () => { + it('should correctly map roomMembershipEntity to RoomMembership domain object', () => { + const roomMembershipEntity = { + id: '1', + } as RoomMembershipEntity; + + const result = RoomMembershipDomainMapper.mapEntityToDo(roomMembershipEntity); + + expect(result).toBeInstanceOf(RoomMembership); + expect(result.getProps()).toEqual({ + id: '1', + }); + }); + + it('should return existing domainObject if present, regardless of entity properties', () => { + const existingRoomMember = new RoomMembership({ + id: '1', + roomId: 'r1', + userGroupId: 'ug1', + createdAt: new Date('2023-01-01'), + updatedAt: new Date('2023-01-01'), + }); + + const roomMembershipEntity = { + id: '1', + domainObject: existingRoomMember, + } as RoomMembershipEntity; + + const result = RoomMembershipDomainMapper.mapEntityToDo(roomMembershipEntity); + + expect(result).toBe(existingRoomMember); + expect(result).toBeInstanceOf(RoomMembership); + expect(result.getProps()).toEqual({ + id: '1', + roomId: 'r1', + userGroupId: 'ug1', + createdAt: new Date('2023-01-01'), + updatedAt: new Date('2023-01-01'), + }); + expect(result.getProps().id).toBe('1'); + expect(result.getProps().id).toBe(roomMembershipEntity.id); + }); + + it('should wrap the actual entity reference in the domain object', () => { + const roomMembershipEntity = { + id: '1', + } as RoomMembershipEntity; + + const result = RoomMembershipDomainMapper.mapEntityToDo(roomMembershipEntity); + // @ts-expect-error check necessary + const { props } = result; + + expect(props === roomMembershipEntity).toBe(true); + }); + }); + + describe('mapDoToEntity', () => { + describe('when domain object props are instanceof roomMembershipEntity', () => { + it('should return the entity', () => { + const roomMembershipEntity = roomMembershipEntityFactory.build(); + const roomMember = new RoomMembership(roomMembershipEntity); + + const result = RoomMembershipDomainMapper.mapDoToEntity(roomMember); + + expect(result).toBe(roomMembershipEntity); + }); + }); + + describe('when domain object props are not instanceof roomMembershipEntity', () => { + it('should convert them to an entity and return it', () => { + const roomMembershipEntity: RoomMembershipProps = { + id: '66d581c3ef74c548a4efea1d', + roomId: '66d581c3ef74c548a4efea1a', + userGroupId: '66d581c3ef74c548a4efea1b', + createdAt: new Date('2024-10-1'), + updatedAt: new Date('2024-10-1'), + }; + const room = new RoomMembership(roomMembershipEntity); + + const result = RoomMembershipDomainMapper.mapDoToEntity(room); + + expect(result).toBeInstanceOf(RoomMembershipEntity); + expect(result).toMatchObject(roomMembershipEntity); + }); + }); + }); +}); diff --git a/apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.ts b/apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.ts new file mode 100644 index 00000000000..355a366e536 --- /dev/null +++ b/apps/server/src/modules/room-membership/repo/room-membership-domain.mapper.ts @@ -0,0 +1,37 @@ +import { RoomMembership } from '../do/room-membership.do'; +import { RoomMembershipEntity } from './entity'; + +export class RoomMembershipDomainMapper { + static mapEntityToDo(roomMembershipEntity: RoomMembershipEntity): RoomMembership { + // check identity map reference + if (roomMembershipEntity.domainObject) { + return roomMembershipEntity.domainObject; + } + + const roomMember = new RoomMembership(roomMembershipEntity); + + // attach to identity map + roomMembershipEntity.domainObject = roomMember; + + return roomMember; + } + + static mapDoToEntity(roomMember: RoomMembership): RoomMembershipEntity { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const { props } = roomMember; + + if (!(props instanceof RoomMembershipEntity)) { + const entity = new RoomMembershipEntity(); + Object.assign(entity, props); + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + roomMember.props = entity; + + return entity; + } + + return props; + } +} diff --git a/apps/server/src/modules/room-member/repo/room-member.repo.spec.ts b/apps/server/src/modules/room-membership/repo/room-membership.repo.spec.ts similarity index 63% rename from apps/server/src/modules/room-member/repo/room-member.repo.spec.ts rename to apps/server/src/modules/room-membership/repo/room-membership.repo.spec.ts index 3cf9364019e..27afbe63c6a 100644 --- a/apps/server/src/modules/room-member/repo/room-member.repo.spec.ts +++ b/apps/server/src/modules/room-membership/repo/room-membership.repo.spec.ts @@ -3,23 +3,23 @@ import { NotFoundError } from '@mikro-orm/core'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; import { cleanupCollections } from '@shared/testing'; -import { RoomMember } from '../do/room-member.do'; -import { roomMemberEntityFactory, roomMemberFactory } from '../testing'; -import { RoomMemberEntity } from './entity'; -import { RoomMemberRepo } from './room-member.repo'; +import { RoomMembership } from '../do/room-membership.do'; +import { roomMembershipEntityFactory, roomMembershipFactory } from '../testing'; +import { RoomMembershipEntity } from './entity'; +import { RoomMembershipRepo } from './room-membership.repo'; -describe('RoomMemberRepo', () => { +describe('RoomMembershipRepo', () => { let module: TestingModule; - let repo: RoomMemberRepo; + let repo: RoomMembershipRepo; let em: EntityManager; beforeAll(async () => { module = await Test.createTestingModule({ imports: [MongoMemoryDatabaseModule.forRoot()], - providers: [RoomMemberRepo], + providers: [RoomMembershipRepo], }).compile(); - repo = module.get(RoomMemberRepo); + repo = module.get(RoomMembershipRepo); em = module.get(EntityManager); }); @@ -33,20 +33,20 @@ describe('RoomMemberRepo', () => { describe('findByRoomId', () => { const setup = async () => { - const roomMemberEntity = roomMemberEntityFactory.buildWithId(); - await em.persistAndFlush([roomMemberEntity]); + const roomMembershipEntity = roomMembershipEntityFactory.buildWithId(); + await em.persistAndFlush([roomMembershipEntity]); em.clear(); - return { roomMemberEntity }; + return { roomMembershipEntity }; }; it('should find room member by roomId', async () => { - const { roomMemberEntity } = await setup(); + const { roomMembershipEntity } = await setup(); - const roomMember = await repo.findByRoomId(roomMemberEntity.roomId); + const roomMember = await repo.findByRoomId(roomMembershipEntity.roomId); expect(roomMember).toBeDefined(); - expect(roomMember?.getProps()).toEqual(roomMemberEntity); + expect(roomMember?.getProps()).toEqual(roomMembershipEntity); }); }); @@ -56,9 +56,9 @@ describe('RoomMemberRepo', () => { const roomId2 = new ObjectId().toHexString(); const roomMemberEntities = [ - roomMemberEntityFactory.buildWithId({ roomId: roomId1 }), - roomMemberEntityFactory.buildWithId({ roomId: roomId1 }), - roomMemberEntityFactory.buildWithId({ roomId: roomId2 }), + roomMembershipEntityFactory.buildWithId({ roomId: roomId1 }), + roomMembershipEntityFactory.buildWithId({ roomId: roomId1 }), + roomMembershipEntityFactory.buildWithId({ roomId: roomId2 }), ]; await em.persistAndFlush(roomMemberEntities); @@ -80,9 +80,9 @@ describe('RoomMemberRepo', () => { const setup = async () => { const groupId = new ObjectId().toHexString(); const roomMemberEntities = [ - roomMemberEntityFactory.build({ userGroupId: groupId }), - roomMemberEntityFactory.build({ userGroupId: groupId }), - roomMemberEntityFactory.build({ userGroupId: new ObjectId().toHexString() }), + roomMembershipEntityFactory.build({ userGroupId: groupId }), + roomMembershipEntityFactory.build({ userGroupId: groupId }), + roomMembershipEntityFactory.build({ userGroupId: new ObjectId().toHexString() }), ]; await em.persistAndFlush(roomMemberEntities); @@ -102,7 +102,7 @@ describe('RoomMemberRepo', () => { describe('save', () => { const setup = () => { - const roomMembers = roomMemberFactory.buildList(3); + const roomMembers = roomMembershipFactory.buildList(3); return { roomMembers }; }; @@ -110,7 +110,7 @@ describe('RoomMemberRepo', () => { const { roomMembers } = setup(); await repo.save(roomMembers[0]); - const result = await em.findOneOrFail(RoomMemberEntity, roomMembers[0].id); + const result = await em.findOneOrFail(RoomMembershipEntity, roomMembers[0].id); expect(roomMembers[0].getProps()).toMatchObject(result); }); @@ -119,7 +119,7 @@ describe('RoomMemberRepo', () => { const { roomMembers } = setup(); await repo.save(roomMembers); - const result = await em.find(RoomMemberEntity, { id: { $in: roomMembers.map((r) => r.id) } }); + const result = await em.find(RoomMembershipEntity, { id: { $in: roomMembers.map((r) => r.id) } }); expect(result.length).toBe(roomMembers.length); }); @@ -127,9 +127,9 @@ describe('RoomMemberRepo', () => { describe('delete', () => { const setup = async () => { - const roomMemberEntities = roomMemberEntityFactory.buildListWithId(3); + const roomMemberEntities = roomMembershipEntityFactory.buildListWithId(3); await em.persistAndFlush(roomMemberEntities); - const roomMembers = roomMemberEntities.map((entity) => new RoomMember(entity)); + const roomMembers = roomMemberEntities.map((entity) => new RoomMembership(entity)); em.clear(); return { roomMembers }; @@ -140,7 +140,7 @@ describe('RoomMemberRepo', () => { await repo.delete(roomMembers[0]); - await expect(em.findOneOrFail(RoomMemberEntity, roomMembers[0].id)).rejects.toThrow(NotFoundError); + await expect(em.findOneOrFail(RoomMembershipEntity, roomMembers[0].id)).rejects.toThrow(NotFoundError); }); it('should be able to delete many rooms', async () => { @@ -148,7 +148,7 @@ describe('RoomMemberRepo', () => { await repo.delete(roomMembers); - const remainingCount = await em.count(RoomMemberEntity); + const remainingCount = await em.count(RoomMembershipEntity); expect(remainingCount).toBe(0); }); }); diff --git a/apps/server/src/modules/room-membership/repo/room-membership.repo.ts b/apps/server/src/modules/room-membership/repo/room-membership.repo.ts new file mode 100644 index 00000000000..0512fca7dcc --- /dev/null +++ b/apps/server/src/modules/room-membership/repo/room-membership.repo.ts @@ -0,0 +1,64 @@ +import { Utils } from '@mikro-orm/core'; +import { EntityManager } from '@mikro-orm/mongodb'; +import { Injectable } from '@nestjs/common'; +import { EntityId } from '@shared/domain/types'; +import { RoomMembership } from '../do/room-membership.do'; +import { RoomMembershipEntity } from './entity'; +import { RoomMembershipDomainMapper } from './room-membership-domain.mapper'; + +@Injectable() +export class RoomMembershipRepo { + constructor(private readonly em: EntityManager) {} + + async findByRoomId(roomId: EntityId): Promise { + const roomMemberEntities = await this.em.findOne(RoomMembershipEntity, { roomId }); + if (!roomMemberEntities) return null; + + const roomMembers = RoomMembershipDomainMapper.mapEntityToDo(roomMemberEntities); + + return roomMembers; + } + + async findByRoomIds(roomIds: EntityId[]): Promise { + const entities = await this.em.find(RoomMembershipEntity, { roomId: { $in: roomIds } }); + const roomMembers = entities.map((entity) => RoomMembershipDomainMapper.mapEntityToDo(entity)); + + return roomMembers; + } + + async findByGroupId(groupId: EntityId): Promise { + const entities = await this.em.find(RoomMembershipEntity, { userGroupId: groupId }); + const roomMembers = entities.map((entity) => RoomMembershipDomainMapper.mapEntityToDo(entity)); + + return roomMembers; + } + + async findByGroupIds(groupIds: EntityId[]): Promise { + const entities = await this.em.find(RoomMembershipEntity, { userGroupId: { $in: groupIds } }); + const roomMembers = entities.map((entity) => RoomMembershipDomainMapper.mapEntityToDo(entity)); + + return roomMembers; + } + + async save(roomMember: RoomMembership | RoomMembership[]): Promise { + const roomMembers = Utils.asArray(roomMember); + + roomMembers.forEach((member) => { + const entity = RoomMembershipDomainMapper.mapDoToEntity(member); + this.em.persist(entity); + }); + + await this.em.flush(); + } + + async delete(roomMember: RoomMembership | RoomMembership[]): Promise { + const roomMembers = Utils.asArray(roomMember); + + roomMembers.forEach((member) => { + const entity = RoomMembershipDomainMapper.mapDoToEntity(member); + this.em.remove(entity); + }); + + await this.em.flush(); + } +} diff --git a/apps/server/src/modules/room-membership/room-membership.module.ts b/apps/server/src/modules/room-membership/room-membership.module.ts new file mode 100644 index 00000000000..520d8c66628 --- /dev/null +++ b/apps/server/src/modules/room-membership/room-membership.module.ts @@ -0,0 +1,15 @@ +import { GroupModule } from '@modules/group'; +import { Module } from '@nestjs/common'; +import { CqrsModule } from '@nestjs/cqrs'; +import { AuthorizationModule } from '../authorization'; +import { RoleModule } from '../role'; +import { RoomMembershipRule } from './authorization/room-membership.rule'; +import { RoomMembershipRepo } from './repo/room-membership.repo'; +import { RoomMembershipService } from './service/room-membership.service'; + +@Module({ + imports: [AuthorizationModule, CqrsModule, GroupModule, RoleModule], + providers: [RoomMembershipService, RoomMembershipRepo, RoomMembershipRule], + exports: [RoomMembershipService], +}) +export class RoomMembershipModule {} diff --git a/apps/server/src/modules/room-member/service/room-member.service.spec.ts b/apps/server/src/modules/room-membership/service/room-membership.service.spec.ts similarity index 68% rename from apps/server/src/modules/room-member/service/room-member.service.spec.ts rename to apps/server/src/modules/room-membership/service/room-membership.service.spec.ts index c61c9108fee..d768c4abf68 100644 --- a/apps/server/src/modules/room-member/service/room-member.service.spec.ts +++ b/apps/server/src/modules/room-membership/service/room-membership.service.spec.ts @@ -4,18 +4,18 @@ import { Test, TestingModule } from '@nestjs/testing'; import { RoleName } from '@shared/domain/interface'; import { groupFactory, roleDtoFactory, userFactory } from '@shared/testing'; import { MongoMemoryDatabaseModule } from '@src/infra/database'; -import { GroupService, GroupTypes } from '@src/modules/group'; +import { GroupService, GroupTypes } from '@modules/group'; import { RoleService } from '@modules/role'; import { roomFactory } from '@modules/room/testing'; -import { RoomMemberAuthorizable } from '../do/room-member-authorizable.do'; -import { RoomMemberRepo } from '../repo/room-member.repo'; -import { roomMemberFactory } from '../testing'; -import { RoomMemberService } from './room-member.service'; +import { RoomMembershipAuthorizable } from '../do/room-membership-authorizable.do'; +import { RoomMembershipRepo } from '../repo/room-membership.repo'; +import { roomMembershipFactory } from '../testing'; +import { RoomMembershipService } from './room-membership.service'; -describe('RoomMemberService', () => { +describe('RoomMembershipService', () => { let module: TestingModule; - let service: RoomMemberService; - let roomMemberRepo: DeepMocked; + let service: RoomMembershipService; + let roomMembershipRepo: DeepMocked; let groupService: DeepMocked; let roleService: DeepMocked; @@ -23,14 +23,14 @@ describe('RoomMemberService', () => { module = await Test.createTestingModule({ imports: [MongoMemoryDatabaseModule.forRoot()], providers: [ - RoomMemberService, + RoomMembershipService, { provide: GroupService, useValue: createMock(), }, { - provide: RoomMemberRepo, - useValue: createMock(), + provide: RoomMembershipRepo, + useValue: createMock(), }, { provide: RoleService, @@ -39,8 +39,8 @@ describe('RoomMemberService', () => { ], }).compile(); - service = module.get(RoomMemberService); - roomMemberRepo = module.get(RoomMemberRepo); + service = module.get(RoomMembershipService); + roomMembershipRepo = module.get(RoomMembershipRepo); groupService = module.get(GroupService); roleService = module.get(RoleService); }); @@ -60,10 +60,10 @@ describe('RoomMemberService', () => { const room = roomFactory.build(); const group = groupFactory.build({ type: GroupTypes.ROOM }); - roomMemberRepo.findByRoomId.mockResolvedValue(null); + roomMembershipRepo.findByRoomId.mockResolvedValue(null); groupService.createGroup.mockResolvedValue(group); groupService.addUserToGroup.mockResolvedValue(); - roomMemberRepo.save.mockResolvedValue(); + roomMembershipRepo.save.mockResolvedValue(); return { user, @@ -76,14 +76,14 @@ describe('RoomMemberService', () => { await service.addMembersToRoom(room.id, [{ userId: user.id, roleName: RoleName.ROOMEDITOR }]); - expect(roomMemberRepo.save).toHaveBeenCalled(); + expect(roomMembershipRepo.save).toHaveBeenCalled(); }); describe('when no user is provided', () => { it('should throw an exception', async () => { const { room } = setup(); - roomMemberRepo.findByRoomId.mockResolvedValue(null); + roomMembershipRepo.findByRoomId.mockResolvedValue(null); await expect(service.addMembersToRoom(room.id, [])).rejects.toThrow(); }); @@ -95,9 +95,9 @@ describe('RoomMemberService', () => { const user = userFactory.buildWithId(); const group = groupFactory.build({ type: GroupTypes.ROOM }); const room = roomFactory.build(); - const roomMember = roomMemberFactory.build({ roomId: room.id, userGroupId: group.id }); + const roomMember = roomMembershipFactory.build({ roomId: room.id, userGroupId: group.id }); - roomMemberRepo.findByRoomId.mockResolvedValue(roomMember); + roomMembershipRepo.findByRoomId.mockResolvedValue(roomMember); return { user, @@ -126,10 +126,10 @@ describe('RoomMemberService', () => { const room = roomFactory.build(); const group = groupFactory.build({ type: GroupTypes.ROOM }); - roomMemberRepo.findByRoomId.mockResolvedValue(null); + roomMembershipRepo.findByRoomId.mockResolvedValue(null); groupService.createGroup.mockResolvedValue(group); groupService.addUserToGroup.mockResolvedValue(); - roomMemberRepo.save.mockResolvedValue(); + roomMembershipRepo.save.mockResolvedValue(); return { user, @@ -140,7 +140,7 @@ describe('RoomMemberService', () => { describe('when roomMember does not exist', () => { it('should throw an exception', async () => { const { room } = setup(); - roomMemberRepo.findByRoomId.mockResolvedValue(null); + roomMembershipRepo.findByRoomId.mockResolvedValue(null); await expect(service.removeMembersFromRoom(room.id, [])).rejects.toThrowError(BadRequestException); }); @@ -152,9 +152,9 @@ describe('RoomMemberService', () => { const user = userFactory.buildWithId(); const group = groupFactory.build({ type: GroupTypes.ROOM }); const room = roomFactory.build(); - const roomMember = roomMemberFactory.build({ roomId: room.id, userGroupId: group.id }); + const roomMember = roomMembershipFactory.build({ roomId: room.id, userGroupId: group.id }); - roomMemberRepo.findByRoomId.mockResolvedValue(roomMember); + roomMembershipRepo.findByRoomId.mockResolvedValue(roomMember); groupService.findById.mockResolvedValue(group); return { @@ -178,22 +178,22 @@ describe('RoomMemberService', () => { describe('deleteRoomMember', () => { describe('when room member does not exist', () => { const setup = () => { - roomMemberRepo.findByRoomId.mockResolvedValue(null); + roomMembershipRepo.findByRoomId.mockResolvedValue(null); }; it('no nothing', async () => { setup(); await service.deleteRoomMember('roomId'); expect(groupService.delete).not.toHaveBeenCalled(); - expect(roomMemberRepo.delete).not.toHaveBeenCalled(); + expect(roomMembershipRepo.delete).not.toHaveBeenCalled(); }); }); describe('when room member exists', () => { const setup = () => { const group = groupFactory.build(); - const roomMember = roomMemberFactory.build({ userGroupId: group.id }); - roomMemberRepo.findByRoomId.mockResolvedValue(roomMember); + const roomMember = roomMembershipFactory.build({ userGroupId: group.id }); + roomMembershipRepo.findByRoomId.mockResolvedValue(roomMember); groupService.findById.mockResolvedValue(group); return { roomMember, group }; @@ -203,54 +203,54 @@ describe('RoomMemberService', () => { const { roomMember, group } = setup(); await service.deleteRoomMember(roomMember.roomId); expect(groupService.delete).toHaveBeenCalledWith(group); - expect(roomMemberRepo.delete).toHaveBeenCalledWith(roomMember); + expect(roomMembershipRepo.delete).toHaveBeenCalledWith(roomMember); }); }); }); - describe('getRoomMemberAuthorizable', () => { + describe('getRoomMembershipAuthorizable', () => { const setup = () => { const roomId = 'room123'; const userId = 'user456'; const groupId = 'group789'; const roleId = 'role101'; - const roomMember = roomMemberFactory.build({ roomId, userGroupId: groupId }); + const roomMember = roomMembershipFactory.build({ roomId, userGroupId: groupId }); const group = groupFactory.build({ id: groupId, users: [{ userId, roleId }] }); const role = roleDtoFactory.build({ id: roleId }); - roomMemberRepo.findByRoomId.mockResolvedValue(roomMember); + roomMembershipRepo.findByRoomId.mockResolvedValue(roomMember); groupService.findById.mockResolvedValue(group); roleService.findByIds.mockResolvedValue([role]); return { roomId, userId, groupId, roleId, roomMember, group, role }; }; - it('should return RoomMemberAuthorizable when room member exists', async () => { + it('should return RoomMembershipAuthorizable when room member exists', async () => { const { roomId, userId, roleId } = setup(); - const result = await service.getRoomMemberAuthorizable(roomId); + const result = await service.getRoomMembershipAuthorizable(roomId); - expect(result).toBeInstanceOf(RoomMemberAuthorizable); + expect(result).toBeInstanceOf(RoomMembershipAuthorizable); expect(result.roomId).toBe(roomId); expect(result.members).toHaveLength(1); expect(result.members[0].userId).toBe(userId); expect(result.members[0].roles[0].id).toBe(roleId); }); - it('should return empty RoomMemberAuthorizable when room member not exists', async () => { + it('should return empty RoomMembershipAuthorizable when room member not exists', async () => { const roomId = 'nonexistent'; - roomMemberRepo.findByRoomId.mockResolvedValue(null); + roomMembershipRepo.findByRoomId.mockResolvedValue(null); - const result = await service.getRoomMemberAuthorizable(roomId); + const result = await service.getRoomMembershipAuthorizable(roomId); - expect(result).toBeInstanceOf(RoomMemberAuthorizable); + expect(result).toBeInstanceOf(RoomMembershipAuthorizable); expect(result.roomId).toBe(roomId); expect(result.members).toHaveLength(0); }); }); - describe('getRoomMemberAuthorizablesByUserId', () => { + describe('getRoomMembershipAuthorizablesByUserId', () => { const setup = () => { const userId = 'user123'; const groupId1 = 'group456'; @@ -265,29 +265,29 @@ describe('RoomMemberService', () => { groupFactory.build({ id: groupId2, users: [{ userId, roleId: roleId2 }] }), ]; const roomMembers = [ - roomMemberFactory.build({ roomId: roomId1, userGroupId: groupId1 }), - roomMemberFactory.build({ roomId: roomId2, userGroupId: groupId2 }), + roomMembershipFactory.build({ roomId: roomId1, userGroupId: groupId1 }), + roomMembershipFactory.build({ roomId: roomId2, userGroupId: groupId2 }), ]; const roles = [roleDtoFactory.build({ id: roleId1 }), roleDtoFactory.build({ id: roleId2 })]; groupService.findGroups.mockResolvedValue({ data: groups, total: groups.length }); - roomMemberRepo.findByGroupIds.mockResolvedValue(roomMembers); + roomMembershipRepo.findByGroupIds.mockResolvedValue(roomMembers); roleService.findByIds.mockResolvedValue(roles); return { userId, roomMembers, roles }; }; - it('should return RoomMemberAuthorizables for user', async () => { + it('should return RoomMembershipAuthorizables for user', async () => { const { userId, roomMembers, roles } = setup(); - const result = await service.getRoomMemberAuthorizablesByUserId(userId); + const result = await service.getRoomMembershipAuthorizablesByUserId(userId); expect(result).toHaveLength(2); - expect(result[0]).toBeInstanceOf(RoomMemberAuthorizable); + expect(result[0]).toBeInstanceOf(RoomMembershipAuthorizable); expect(result[0].roomId).toBe(roomMembers[0].roomId); expect(result[0].members[0].userId).toBe(userId); expect(result[0].members[0].roles[0].id).toBe(roles[0].id); - expect(result[1]).toBeInstanceOf(RoomMemberAuthorizable); + expect(result[1]).toBeInstanceOf(RoomMembershipAuthorizable); expect(result[1].roomId).toBe(roomMembers[1].roomId); expect(result[1].members[0].userId).toBe(userId); expect(result[1].members[0].roles[0].id).toBe(roles[1].id); @@ -297,7 +297,7 @@ describe('RoomMemberService', () => { const { userId } = setup(); groupService.findGroups.mockResolvedValue({ data: [], total: 0 }); - const result = await service.getRoomMemberAuthorizablesByUserId(userId); + const result = await service.getRoomMembershipAuthorizablesByUserId(userId); expect(result).toHaveLength(0); }); diff --git a/apps/server/src/modules/room-member/service/room-member.service.ts b/apps/server/src/modules/room-membership/service/room-membership.service.ts similarity index 73% rename from apps/server/src/modules/room-member/service/room-member.service.ts rename to apps/server/src/modules/room-membership/service/room-membership.service.ts index 8ac26bdbe15..efd32e5f61f 100644 --- a/apps/server/src/modules/room-member/service/room-member.service.ts +++ b/apps/server/src/modules/room-membership/service/room-membership.service.ts @@ -1,18 +1,18 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import { RoleName } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; -import { Group, GroupService, GroupTypes } from '@src/modules/group'; +import { Group, GroupService, GroupTypes } from '@modules/group'; import { ObjectId } from '@mikro-orm/mongodb'; -import { RoleDto, RoleService } from '@src/modules/role'; -import { RoomMember } from '../do/room-member.do'; -import { RoomMemberRepo } from '../repo/room-member.repo'; -import { RoomMemberAuthorizable, UserWithRoomRoles } from '../do/room-member-authorizable.do'; +import { RoleDto, RoleService } from '@modules/role'; +import { RoomMembership } from '../do/room-membership.do'; +import { RoomMembershipRepo } from '../repo/room-membership.repo'; +import { RoomMembershipAuthorizable, UserWithRoomRoles } from '../do/room-membership-authorizable.do'; @Injectable() -export class RoomMemberService { +export class RoomMembershipService { constructor( private readonly groupService: GroupService, - private readonly roomMembersRepo: RoomMemberRepo, + private readonly roomMembersRepo: RoomMembershipRepo, private readonly roleService: RoleService ) {} @@ -25,7 +25,7 @@ export class RoomMemberService { const group = await this.groupService.createGroup(`Room Members for Room ${roomId}`, GroupTypes.ROOM, schoolId); await this.groupService.addUsersToGroup(group.id, [{ userId, roleName }]); - const roomMember = new RoomMember({ + const roomMember = new RoomMembership({ id: new ObjectId().toHexString(), roomId, userGroupId: group.id, @@ -38,7 +38,11 @@ export class RoomMemberService { return roomMember; } - private buildRoomMemberAuthorizable(roomId: EntityId, group: Group, roleSet: RoleDto[]): RoomMemberAuthorizable { + private buildRoomMembershipAuthorizable( + roomId: EntityId, + group: Group, + roleSet: RoleDto[] + ): RoomMembershipAuthorizable { const members = group.users.map((groupUser): UserWithRoomRoles => { const roleDto = roleSet.find((role) => role.id === groupUser.roleId); if (roleDto === undefined) throw new BadRequestException('Role not found'); @@ -48,9 +52,9 @@ export class RoomMemberService { }; }); - const roomMemberAuthorizable = new RoomMemberAuthorizable(roomId, members); + const roomMembershipAuthorizable = new RoomMembershipAuthorizable(roomId, members); - return roomMemberAuthorizable; + return roomMembershipAuthorizable; } public async deleteRoomMember(roomId: EntityId) { @@ -92,27 +96,27 @@ export class RoomMemberService { await this.groupService.removeUsersFromGroup(group.id, userIds); } - public async getRoomMemberAuthorizablesByUserId(userId: EntityId): Promise { + public async getRoomMembershipAuthorizablesByUserId(userId: EntityId): Promise { const groupPage = await this.groupService.findGroups({ userId, groupTypes: [GroupTypes.ROOM] }); const groupIds = groupPage.data.map((group) => group.id); const roomMembers = await this.roomMembersRepo.findByGroupIds(groupIds); const roleIds = groupPage.data.flatMap((group) => group.users.map((groupUser) => groupUser.roleId)); const roleSet = await this.roleService.findByIds(roleIds); - const roomMemberAuthorizables = roomMembers + const roomMembershipAuthorizables = roomMembers .map((item) => { const group = groupPage.data.find((g) => g.id === item.userGroupId); if (!group) return null; - return this.buildRoomMemberAuthorizable(item.roomId, group, roleSet); + return this.buildRoomMembershipAuthorizable(item.roomId, group, roleSet); }) - .filter((item): item is RoomMemberAuthorizable => item !== null); + .filter((item): item is RoomMembershipAuthorizable => item !== null); - return roomMemberAuthorizables; + return roomMembershipAuthorizables; } - public async getRoomMemberAuthorizable(roomId: EntityId): Promise { + public async getRoomMembershipAuthorizable(roomId: EntityId): Promise { const roomMember = await this.roomMembersRepo.findByRoomId(roomId); if (roomMember === null) { - return new RoomMemberAuthorizable(roomId, []); + return new RoomMembershipAuthorizable(roomId, []); } const group = await this.groupService.findById(roomMember.userGroupId); const roleSet = await this.roleService.findByIds(group.users.map((groupUser) => groupUser.roleId)); @@ -126,8 +130,8 @@ export class RoomMemberService { }; }); - const roomMemberAuthorizable = new RoomMemberAuthorizable(roomId, members); + const roomMembershipAuthorizable = new RoomMembershipAuthorizable(roomId, members); - return roomMemberAuthorizable; + return roomMembershipAuthorizable; } } diff --git a/apps/server/src/modules/room-membership/testing/index.ts b/apps/server/src/modules/room-membership/testing/index.ts new file mode 100644 index 00000000000..a29c3fae4a1 --- /dev/null +++ b/apps/server/src/modules/room-membership/testing/index.ts @@ -0,0 +1,2 @@ +export { roomMembershipEntityFactory } from './room-membership-entity.factory'; +export { roomMembershipFactory } from './room-membership.factory'; diff --git a/apps/server/src/modules/room-member/testing/room-member-entity.factory.ts b/apps/server/src/modules/room-membership/testing/room-membership-entity.factory.ts similarity index 57% rename from apps/server/src/modules/room-member/testing/room-member-entity.factory.ts rename to apps/server/src/modules/room-membership/testing/room-membership-entity.factory.ts index b63f70ecffd..c58746adf96 100644 --- a/apps/server/src/modules/room-member/testing/room-member-entity.factory.ts +++ b/apps/server/src/modules/room-membership/testing/room-membership-entity.factory.ts @@ -1,9 +1,9 @@ import { ObjectId } from '@mikro-orm/mongodb'; import { EntityFactory } from '@shared/testing/factory/entity.factory'; -import { RoomMemberEntity, RoomMemberEntityProps } from '../repo/entity/room-member.entity'; +import { RoomMembershipEntity, RoomMembershipEntityProps } from '../repo/entity/room-membership.entity'; -export const roomMemberEntityFactory = EntityFactory.define( - RoomMemberEntity, +export const roomMembershipEntityFactory = EntityFactory.define( + RoomMembershipEntity, () => { return { id: new ObjectId().toHexString(), diff --git a/apps/server/src/modules/room-member/testing/room-member.factory.ts b/apps/server/src/modules/room-membership/testing/room-membership.factory.ts similarity index 55% rename from apps/server/src/modules/room-member/testing/room-member.factory.ts rename to apps/server/src/modules/room-membership/testing/room-membership.factory.ts index 829f0f1708c..70c80b05a93 100644 --- a/apps/server/src/modules/room-member/testing/room-member.factory.ts +++ b/apps/server/src/modules/room-membership/testing/room-membership.factory.ts @@ -1,9 +1,9 @@ import { ObjectId } from '@mikro-orm/mongodb'; import { BaseFactory } from '@shared/testing'; -import { RoomMember, RoomMemberProps } from '../do/room-member.do'; +import { RoomMembership, RoomMembershipProps } from '../do/room-membership.do'; -export const roomMemberFactory = BaseFactory.define(RoomMember, () => { - const props: RoomMemberProps = { +export const roomMembershipFactory = BaseFactory.define(RoomMembership, () => { + const props: RoomMembershipProps = { id: new ObjectId().toHexString(), roomId: new ObjectId().toHexString(), userGroupId: new ObjectId().toHexString(), diff --git a/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts b/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts index d21d64fd10a..8cb204691a3 100644 --- a/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts +++ b/apps/server/src/modules/room/api/dto/request/create-room.body.params.ts @@ -1,7 +1,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { SanitizeHtml } from '@shared/controller'; -import { RoomCreateProps } from '@src/modules/room/domain'; -import { RoomColor } from '@src/modules/room/domain/type'; +import { RoomCreateProps } from '@modules/room/domain'; +import { RoomColor } from '@modules/room/domain/type'; import { IsDate, IsEnum, IsOptional, IsString, MaxLength, MinLength } from 'class-validator'; export class CreateRoomBodyParams implements Omit { diff --git a/apps/server/src/modules/room/api/dto/request/update-room.body.params.ts b/apps/server/src/modules/room/api/dto/request/update-room.body.params.ts index 8afebced7d3..550357b7aca 100644 --- a/apps/server/src/modules/room/api/dto/request/update-room.body.params.ts +++ b/apps/server/src/modules/room/api/dto/request/update-room.body.params.ts @@ -1,7 +1,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { SanitizeHtml } from '@shared/controller'; -import { RoomUpdateProps } from '@src/modules/room/domain'; -import { RoomColor } from '@src/modules/room/domain/type'; +import { RoomUpdateProps } from '@modules/room/domain'; +import { RoomColor } from '@modules/room/domain/type'; import { IsDate, IsEnum, IsOptional, IsString, MaxLength, MinLength } from 'class-validator'; export class UpdateRoomBodyParams implements RoomUpdateProps { diff --git a/apps/server/src/modules/room/api/dto/response/room-board-item.response.ts b/apps/server/src/modules/room/api/dto/response/room-board-item.response.ts index 0840c1c1d87..f96d927741b 100644 --- a/apps/server/src/modules/room/api/dto/response/room-board-item.response.ts +++ b/apps/server/src/modules/room/api/dto/response/room-board-item.response.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { BoardLayout } from '@src/modules/board'; +import { BoardLayout } from '@modules/board'; export class RoomBoardItemResponse { @ApiProperty() diff --git a/apps/server/src/modules/room/api/dto/response/room-details.response.ts b/apps/server/src/modules/room/api/dto/response/room-details.response.ts index 00b37e38236..bb3a385941e 100644 --- a/apps/server/src/modules/room/api/dto/response/room-details.response.ts +++ b/apps/server/src/modules/room/api/dto/response/room-details.response.ts @@ -1,6 +1,6 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Permission } from '@shared/domain/interface'; -import { RoomColor } from '@src/modules/room/domain/type'; +import { RoomColor } from '@modules/room/domain/type'; import { IsEnum } from 'class-validator'; export class RoomDetailsResponse { diff --git a/apps/server/src/modules/room/api/mapper/room.mapper.ts b/apps/server/src/modules/room/api/mapper/room.mapper.ts index cd5772fbd49..4edc7fc5a63 100644 --- a/apps/server/src/modules/room/api/mapper/room.mapper.ts +++ b/apps/server/src/modules/room/api/mapper/room.mapper.ts @@ -1,5 +1,5 @@ import { Page } from '@shared/domain/domainobject'; -import { ColumnBoard } from '@src/modules/board'; +import { ColumnBoard } from '@modules/board'; import { Room } from '../../domain/do/room.do'; import { RoomPaginationParams } from '../dto/request/room-pagination.params'; import { RoomBoardItemResponse } from '../dto/response/room-board-item.response'; diff --git a/apps/server/src/modules/room/api/room.uc.spec.ts b/apps/server/src/modules/room/api/room.uc.spec.ts index ab0e958ae6c..8910130093e 100644 --- a/apps/server/src/modules/room/api/room.uc.spec.ts +++ b/apps/server/src/modules/room/api/room.uc.spec.ts @@ -1,6 +1,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { AuthorizationService } from '@modules/authorization'; -import { RoomMemberRepo, RoomMemberService } from '@modules/room-member'; +import { RoomMembershipRepo, RoomMembershipService } from '@src/modules/room-membership'; import { UserService } from '@modules/user'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; @@ -8,7 +8,7 @@ import { FeatureDisabledLoggableException } from '@shared/common/loggable-except import { Page } from '@shared/domain/domainobject'; import { IFindOptions } from '@shared/domain/interface'; import { setupEntities, userFactory } from '@shared/testing'; -import { ColumnBoardService } from '@src/modules/board'; +import { ColumnBoardService } from '@modules/board'; import { Room, RoomService } from '../domain'; import { RoomColor } from '../domain/type'; import { roomFactory } from '../testing'; @@ -20,7 +20,7 @@ describe('RoomUc', () => { let configService: DeepMocked; let roomService: DeepMocked; let authorizationService: DeepMocked; - let roomMemberService: DeepMocked; + let roomMembershipService: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ providers: [ @@ -34,8 +34,8 @@ describe('RoomUc', () => { useValue: createMock(), }, { - provide: RoomMemberService, - useValue: createMock(), + provide: RoomMembershipService, + useValue: createMock(), }, { provide: ColumnBoardService, @@ -46,8 +46,8 @@ describe('RoomUc', () => { useValue: createMock(), }, { - provide: RoomMemberRepo, - useValue: createMock(), + provide: RoomMembershipRepo, + useValue: createMock(), }, { provide: UserService, @@ -60,7 +60,7 @@ describe('RoomUc', () => { configService = module.get(ConfigService); roomService = module.get(RoomService); authorizationService = module.get(AuthorizationService); - roomMemberService = module.get(RoomMemberService); + roomMembershipService = module.get(RoomMembershipService); await setupEntities(); }); @@ -117,7 +117,7 @@ describe('RoomUc', () => { authorizationService.checkOneOfPermissions.mockReturnValue(undefined); const room = roomFactory.build(); roomService.createRoom.mockResolvedValue(room); - roomMemberService.addMembersToRoom.mockRejectedValue(new Error('test')); + roomMembershipService.addMembersToRoom.mockRejectedValue(new Error('test')); return { user, room }; }; diff --git a/apps/server/src/modules/room/api/room.uc.ts b/apps/server/src/modules/room/api/room.uc.ts index 0fe0cea00cf..2f7cb691c96 100644 --- a/apps/server/src/modules/room/api/room.uc.ts +++ b/apps/server/src/modules/room/api/room.uc.ts @@ -1,5 +1,5 @@ import { Action, AuthorizationService } from '@modules/authorization'; -import { RoomMemberAuthorizable, RoomMemberService, UserWithRoomRoles } from '@modules/room-member'; +import { RoomMembershipAuthorizable, RoomMembershipService, UserWithRoomRoles } from '@src/modules/room-membership'; import { UserService } from '@modules/user'; import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; @@ -7,7 +7,7 @@ import { FeatureDisabledLoggableException } from '@shared/common/loggable-except import { Page, UserDO } from '@shared/domain/domainobject'; import { IFindOptions, Permission, RoleName, RoomRole } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; -import { BoardExternalReferenceType, ColumnBoard, ColumnBoardService } from '@src/modules/board'; +import { BoardExternalReferenceType, ColumnBoard, ColumnBoardService } from '@modules/board'; import { Room, RoomService } from '../domain'; import { RoomConfig } from '../room.config'; import { CreateRoomBodyParams } from './dto/request/create-room.body.params'; @@ -19,7 +19,7 @@ export class RoomUc { constructor( private readonly configService: ConfigService, private readonly roomService: RoomService, - private readonly roomMemberService: RoomMemberService, + private readonly roomMembershipService: RoomMembershipService, private readonly columnBoardService: ColumnBoardService, private readonly userService: UserService, private readonly authorizationService: AuthorizationService @@ -40,7 +40,7 @@ export class RoomUc { this.authorizationService.checkOneOfPermissions(user, [Permission.ROOM_CREATE]); - await this.roomMemberService + await this.roomMembershipService .addMembersToRoom(room.id, [{ userId: user.id, roleName: RoleName.ROOMEDITOR }], user.school.id) .catch(async (err) => { await this.roomService.deleteRoom(room); @@ -54,8 +54,8 @@ export class RoomUc { this.checkFeatureEnabled(); const room = await this.roomService.getSingleRoom(roomId); - const roomMemberAuthorizable = await this.checkRoomAuthorization(userId, roomId, Action.read); - const permissions = this.getPermissions(userId, roomMemberAuthorizable); + const roomMembershipAuthorizable = await this.checkRoomAuthorization(userId, roomId, Action.read); + const permissions = this.getPermissions(userId, roomMembershipAuthorizable); return { room, permissions }; } @@ -85,8 +85,8 @@ export class RoomUc { this.checkFeatureEnabled(); const room = await this.roomService.getSingleRoom(roomId); - const roomMemberAuthorizable = await this.checkRoomAuthorization(userId, roomId, Action.write); - const permissions = this.getPermissions(userId, roomMemberAuthorizable); + const roomMembershipAuthorizable = await this.checkRoomAuthorization(userId, roomId, Action.write); + const permissions = this.getPermissions(userId, roomMembershipAuthorizable); await this.roomService.updateRoom(room, props); @@ -103,18 +103,18 @@ export class RoomUc { public async getRoomMembers(userId: EntityId, roomId: EntityId): Promise { this.checkFeatureEnabled(); - const roomMemberAuthorizable = await this.roomMemberService.getRoomMemberAuthorizable(roomId); + const roomMembershipAuthorizable = await this.roomMembershipService.getRoomMembershipAuthorizable(roomId); const currentUser = await this.authorizationService.getUserWithPermissions(userId); - this.authorizationService.checkPermission(currentUser, roomMemberAuthorizable, { + this.authorizationService.checkPermission(currentUser, roomMembershipAuthorizable, { action: Action.read, requiredPermissions: [], }); - const userIds = roomMemberAuthorizable.members.map((member) => member.userId); + const userIds = roomMembershipAuthorizable.members.map((member) => member.userId); const users = await this.userService.findByIds(userIds); const memberResponses = users.map((user) => { - const member = roomMemberAuthorizable.members.find((item) => item.userId === user.id); + const member = roomMembershipAuthorizable.members.find((item) => item.userId === user.id); if (!member) { /* istanbul ignore next */ throw new Error('User not found in room members'); @@ -132,7 +132,7 @@ export class RoomUc { ): Promise { this.checkFeatureEnabled(); await this.checkRoomAuthorization(currentUserId, roomId, Action.write); - await this.roomMemberService.addMembersToRoom(roomId, userIdsAndRoles); + await this.roomMembershipService.addMembersToRoom(roomId, userIdsAndRoles); } private mapToMember(member: UserWithRoomRoles, user: UserDO) { @@ -148,12 +148,12 @@ export class RoomUc { public async removeMembersFromRoom(currentUserId: EntityId, roomId: EntityId, userIds: EntityId[]): Promise { this.checkFeatureEnabled(); await this.checkRoomAuthorization(currentUserId, roomId, Action.write); - await this.roomMemberService.removeMembersFromRoom(roomId, userIds); + await this.roomMembershipService.removeMembersFromRoom(roomId, userIds); } private async getAuthorizedRoomIds(userId: EntityId, action: Action): Promise { const user = await this.authorizationService.getUserWithPermissions(userId); - const roomAuthorizables = await this.roomMemberService.getRoomMemberAuthorizablesByUserId(userId); + const roomAuthorizables = await this.roomMembershipService.getRoomMembershipAuthorizablesByUserId(userId); const authorizedRoomIds = roomAuthorizables.filter((item) => this.authorizationService.hasPermission(user, item, { action, requiredPermissions: [] }) @@ -167,16 +167,16 @@ export class RoomUc { roomId: EntityId, action: Action, requiredPermissions: Permission[] = [] - ): Promise { - const roomMemberAuthorizable = await this.roomMemberService.getRoomMemberAuthorizable(roomId); + ): Promise { + const roomMembershipAuthorizable = await this.roomMembershipService.getRoomMembershipAuthorizable(roomId); const user = await this.authorizationService.getUserWithPermissions(userId); - this.authorizationService.checkPermission(user, roomMemberAuthorizable, { action, requiredPermissions }); + this.authorizationService.checkPermission(user, roomMembershipAuthorizable, { action, requiredPermissions }); - return roomMemberAuthorizable; + return roomMembershipAuthorizable; } - private getPermissions(userId: EntityId, roomMemberAuthorizable: RoomMemberAuthorizable): Permission[] { - const permissions = roomMemberAuthorizable.members + private getPermissions(userId: EntityId, roomMembershipAuthorizable: RoomMembershipAuthorizable): Permission[] { + const permissions = roomMembershipAuthorizable.members .filter((member) => member.userId === userId) .flatMap((member) => member.roles) .flatMap((role) => role.permissions ?? []); diff --git a/apps/server/src/modules/room/api/test/room-add-members.api.spec.ts b/apps/server/src/modules/room/api/test/room-add-members.api.spec.ts index 7ba93b377e0..b5647dc3f47 100644 --- a/apps/server/src/modules/room/api/test/room-add-members.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-add-members.api.spec.ts @@ -10,9 +10,9 @@ import { groupEntityFactory, roleFactory, } from '@shared/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity/group.entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing/room-member-entity.factory'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { GroupEntityTypes } from '@modules/group/entity/group.entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing/room-membership-entity.factory'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { roomEntityFactory } from '../../testing/room-entity.factory'; describe('Room Controller (API)', () => { @@ -61,7 +61,7 @@ describe('Room Controller (API)', () => { externalSource: undefined, }); - const roomMembers = roomMemberEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); + const roomMembers = roomMembershipEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); await em.persistAndFlush([ room, roomMembers, diff --git a/apps/server/src/modules/room/api/test/room-create.api.spec.ts b/apps/server/src/modules/room/api/test/room-create.api.spec.ts index 48c93c5b4c6..0c965bdb0b9 100644 --- a/apps/server/src/modules/room/api/test/room-create.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-create.api.spec.ts @@ -2,9 +2,9 @@ import { EntityManager } from '@mikro-orm/mongodb'; import { HttpStatus, INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { TestApiClient, UserAndAccountTestFactory, cleanupCollections, roleFactory } from '@shared/testing'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; -import { RoomMemberEntity } from '@src/modules/room-member'; -import { GroupEntity } from '@src/modules/group/entity'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; +import { RoomMembershipEntity } from '@src/modules/room-membership'; +import { GroupEntity } from '@modules/group/entity'; import { Permission, RoleName } from '@shared/domain/interface'; import { RoomEntity } from '../../repo'; @@ -98,7 +98,7 @@ describe('Room Controller (API)', () => { const response = await loggedInClient.post(undefined, params); const roomId = (response.body as { id: string }).id; - const roomMember = await em.findOneOrFail(RoomMemberEntity, { roomId }); + const roomMember = await em.findOneOrFail(RoomMembershipEntity, { roomId }); const userGroup = await em.findOneOrFail(GroupEntity, { id: roomMember.userGroupId, diff --git a/apps/server/src/modules/room/api/test/room-delete.api.spec.ts b/apps/server/src/modules/room/api/test/room-delete.api.spec.ts index cd290922e6c..e5fb5c5bd0d 100644 --- a/apps/server/src/modules/room/api/test/room-delete.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-delete.api.spec.ts @@ -9,9 +9,9 @@ import { groupEntityFactory, roleFactory, } from '@shared/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity/group.entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing/room-member-entity.factory'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { GroupEntityTypes } from '@modules/group/entity/group.entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing/room-membership-entity.factory'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { RoomEntity } from '../../repo'; import { roomEntityFactory } from '../../testing/room-entity.factory'; @@ -103,7 +103,7 @@ describe('Room Controller (API)', () => { type: GroupEntityTypes.ROOM, users: [{ role, user: teacherUser }], }); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([room, roomMember, teacherAccount, teacherUser, userGroup, role]); em.clear(); diff --git a/apps/server/src/modules/room/api/test/room-get-boards.api.spec.ts b/apps/server/src/modules/room/api/test/room-get-boards.api.spec.ts index ff14ce174e9..89c70bba5b0 100644 --- a/apps/server/src/modules/room/api/test/room-get-boards.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-get-boards.api.spec.ts @@ -9,11 +9,11 @@ import { TestApiClient, UserAndAccountTestFactory, } from '@shared/testing'; -import { BoardExternalReferenceType } from '@src/modules/board'; -import { columnBoardEntityFactory } from '@src/modules/board/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; -import { serverConfig, ServerConfig, ServerTestModule } from '@src/modules/server'; +import { BoardExternalReferenceType } from '@modules/board'; +import { columnBoardEntityFactory } from '@modules/board/testing'; +import { GroupEntityTypes } from '@modules/group/entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; +import { serverConfig, ServerConfig, ServerTestModule } from '@modules/server'; import { roomEntityFactory } from '../../testing'; describe('Room Controller (API)', () => { @@ -109,7 +109,7 @@ describe('Room Controller (API)', () => { organization: studentUser.school, externalSource: undefined, }); - const roomMember = roomMemberEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); + const roomMember = roomMembershipEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); await em.persistAndFlush([room, board, studentAccount, studentUser, role, userGroupEntity, roomMember]); em.clear(); diff --git a/apps/server/src/modules/room/api/test/room-get.api.spec.ts b/apps/server/src/modules/room/api/test/room-get.api.spec.ts index 54961eb25eb..b246d22221e 100644 --- a/apps/server/src/modules/room/api/test/room-get.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-get.api.spec.ts @@ -9,9 +9,9 @@ import { groupEntityFactory, roleFactory, } from '@shared/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity/group.entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { GroupEntityTypes } from '@modules/group/entity/group.entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { roomEntityFactory } from '../../testing/room-entity.factory'; describe('Room Controller (API)', () => { @@ -104,7 +104,7 @@ describe('Room Controller (API)', () => { organization: studentUser.school, externalSource: undefined, }); - const roomMember = roomMemberEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); + const roomMember = roomMembershipEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); await em.persistAndFlush([room, studentAccount, studentUser, role, userGroupEntity, roomMember]); em.clear(); diff --git a/apps/server/src/modules/room/api/test/room-index.api.spec.ts b/apps/server/src/modules/room/api/test/room-index.api.spec.ts index 26b0cd141ad..212ca2db7af 100644 --- a/apps/server/src/modules/room/api/test/room-index.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-index.api.spec.ts @@ -10,9 +10,9 @@ import { groupEntityFactory, roleFactory, } from '@shared/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity/group.entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing/room-member-entity.factory'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { GroupEntityTypes } from '@modules/group/entity/group.entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing/room-membership-entity.factory'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { roomEntityFactory } from '../../testing/room-entity.factory'; import { RoomListResponse } from '../dto/response/room-list.response'; @@ -141,7 +141,7 @@ describe('Room Controller (API)', () => { externalSource: undefined, }); const roomMembers = rooms.map((room) => - roomMemberEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }) + roomMembershipEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }) ); await em.persistAndFlush([...rooms, ...roomMembers, studentAccount, studentUser, userGroupEntity]); em.clear(); diff --git a/apps/server/src/modules/room/api/test/room-members.api.spec.ts b/apps/server/src/modules/room/api/test/room-members.api.spec.ts index 80334fbaa08..98464e46772 100644 --- a/apps/server/src/modules/room/api/test/room-members.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-members.api.spec.ts @@ -11,9 +11,9 @@ import { roleFactory, userFactory, } from '@shared/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity/group.entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing/room-member-entity.factory'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { GroupEntityTypes } from '@modules/group/entity/group.entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing/room-membership-entity.factory'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { roomEntityFactory } from '../../testing/room-entity.factory'; import { RoomMemberListResponse } from '../dto/response/room-member.response'; @@ -71,7 +71,7 @@ describe('Room Controller (API)', () => { organization: teacherUser.school, externalSource: undefined, }); - const roomMembers = roomMemberEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); + const roomMembers = roomMembershipEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); await em.persistAndFlush([ room, roomMembers, diff --git a/apps/server/src/modules/room/api/test/room-remove-members.api.spec.ts b/apps/server/src/modules/room/api/test/room-remove-members.api.spec.ts index 6829f3f5cd9..c35d7bce1aa 100644 --- a/apps/server/src/modules/room/api/test/room-remove-members.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-remove-members.api.spec.ts @@ -10,9 +10,9 @@ import { groupEntityFactory, roleFactory, } from '@shared/testing'; -import { GroupEntityTypes } from '@src/modules/group/entity/group.entity'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing/room-member-entity.factory'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { GroupEntityTypes } from '@modules/group/entity/group.entity'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing/room-membership-entity.factory'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { roomEntityFactory } from '../../testing/room-entity.factory'; describe('Room Controller (API)', () => { @@ -81,7 +81,7 @@ describe('Room Controller (API)', () => { externalSource: undefined, }); - const roomMembers = roomMemberEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); + const roomMembers = roomMembershipEntityFactory.build({ userGroupId: userGroupEntity.id, roomId: room.id }); await em.persistAndFlush([...Object.values(users), room, roomMembers, teacherAccount, userGroupEntity]); em.clear(); diff --git a/apps/server/src/modules/room/api/test/room-update.api.spec.ts b/apps/server/src/modules/room/api/test/room-update.api.spec.ts index 08ed5847d21..c77888b09af 100644 --- a/apps/server/src/modules/room/api/test/room-update.api.spec.ts +++ b/apps/server/src/modules/room/api/test/room-update.api.spec.ts @@ -9,8 +9,8 @@ import { groupEntityFactory, roleFactory, } from '@shared/testing'; -import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; -import { ServerTestModule, serverConfig, type ServerConfig } from '@src/modules/server'; +import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing'; +import { ServerTestModule, serverConfig, type ServerConfig } from '@modules/server'; import { RoomEntity } from '../../repo'; import { roomEntityFactory } from '../../testing'; @@ -106,7 +106,7 @@ describe('Room Controller (API)', () => { const userGroup = groupEntityFactory.buildWithId({ users: [{ role, user: teacherUser }], }); - const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); + const roomMember = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); await em.persistAndFlush([room, roomMember, teacherAccount, teacherUser, userGroup, role]); em.clear(); diff --git a/apps/server/src/modules/room/room-api.module.ts b/apps/server/src/modules/room/room-api.module.ts index 7405a83afe8..7711d7cd842 100644 --- a/apps/server/src/modules/room/room-api.module.ts +++ b/apps/server/src/modules/room/room-api.module.ts @@ -2,13 +2,13 @@ import { AuthorizationModule } from '@modules/authorization'; import { Module } from '@nestjs/common'; import { LoggerModule } from '@src/core/logger'; import { BoardModule } from '../board'; -import { RoomMemberModule } from '../room-member/room-member.module'; +import { RoomMembershipModule } from '../room-membership/room-membership.module'; import { UserModule } from '../user'; import { RoomController, RoomUc } from './api'; import { RoomModule } from './room.module'; @Module({ - imports: [RoomModule, AuthorizationModule, LoggerModule, RoomMemberModule, BoardModule, UserModule], + imports: [RoomModule, AuthorizationModule, LoggerModule, RoomMembershipModule, BoardModule, UserModule], controllers: [RoomController], providers: [RoomUc], }) diff --git a/apps/server/src/modules/sharing/sharing-api.module.ts b/apps/server/src/modules/sharing/sharing-api.module.ts index e81e4a8b48e..3c30c03a883 100644 --- a/apps/server/src/modules/sharing/sharing-api.module.ts +++ b/apps/server/src/modules/sharing/sharing-api.module.ts @@ -1,13 +1,13 @@ +import { AuthorizationModule } from '@modules/authorization'; +import { BoardModule } from '@modules/board'; +import { LearnroomModule } from '@modules/learnroom'; +import { LessonModule } from '@modules/lesson'; +import { RoomModule } from '@modules/room'; +import { RoomMembershipModule } from '@src/modules/room-membership'; +import { SchoolModule } from '@modules/school'; +import { TaskModule } from '@modules/task'; import { Module } from '@nestjs/common'; import { LoggerModule } from '@src/core/logger'; -import { AuthorizationModule } from '../authorization'; -import { BoardModule } from '../board'; -import { LearnroomModule } from '../learnroom'; -import { LessonModule } from '../lesson'; -import { RoomModule } from '../room'; -import { RoomMemberModule } from '../room-member'; -import { SchoolModule } from '../school'; -import { TaskModule } from '../task'; import { ShareTokenController } from './controller/share-token.controller'; import { SharingModule } from './sharing.module'; import { ShareTokenUC } from './uc'; @@ -20,7 +20,7 @@ import { ShareTokenUC } from './uc'; LessonModule, TaskModule, BoardModule, - RoomMemberModule, + RoomMembershipModule, RoomModule, SchoolModule, LoggerModule, diff --git a/apps/server/src/modules/sharing/uc/share-token.uc.spec.ts b/apps/server/src/modules/sharing/uc/share-token.uc.spec.ts index 52fe2e0c9b9..3ef5be161e7 100644 --- a/apps/server/src/modules/sharing/uc/share-token.uc.spec.ts +++ b/apps/server/src/modules/sharing/uc/share-token.uc.spec.ts @@ -23,10 +23,10 @@ import { userFactory, } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; -import { CopyColumnBoardParams } from '@src/modules/board/service/internal'; -import { StorageLocation } from '@src/modules/files-storage/interface'; -import { RoomService } from '@src/modules/room'; -import { RoomMemberService } from '@src/modules/room-member'; +import { CopyColumnBoardParams } from '@modules/board/service/internal'; +import { StorageLocation } from '@modules/files-storage/interface'; +import { RoomService } from '@modules/room'; +import { RoomMembershipService } from '@src/modules/room-membership'; import { ShareTokenContextType, ShareTokenParentType, ShareTokenPayload } from '../domainobject/share-token.do'; import { ShareTokenService } from '../service'; import { ShareTokenUC } from './share-token.uc'; @@ -91,8 +91,8 @@ describe('ShareTokenUC', () => { useValue: createMock(), }, { - provide: RoomMemberService, - useValue: createMock(), + provide: RoomMembershipService, + useValue: createMock(), }, { provide: ColumnBoardService, diff --git a/apps/server/src/modules/sharing/uc/share-token.uc.ts b/apps/server/src/modules/sharing/uc/share-token.uc.ts index fbc655190e8..b009c81cc7f 100644 --- a/apps/server/src/modules/sharing/uc/share-token.uc.ts +++ b/apps/server/src/modules/sharing/uc/share-token.uc.ts @@ -15,11 +15,11 @@ import { Course, User } from '@shared/domain/entity'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; import { LegacyLogger } from '@src/core/logger'; -import { StorageLocationReference } from '@src/modules/board/service/internal'; -import { StorageLocation } from '@src/modules/files-storage/interface'; -import { RoomService } from '@src/modules/room'; -import { RoomMemberService } from '@src/modules/room-member'; -import { SchoolService } from '@src/modules/school'; +import { StorageLocationReference } from '@modules/board/service/internal'; +import { StorageLocation } from '@modules/files-storage/interface'; +import { RoomService } from '@modules/room'; +import { RoomMembershipService } from '@src/modules/room-membership'; +import { SchoolService } from '@modules/school'; import { ShareTokenContext, ShareTokenContextType, @@ -42,7 +42,7 @@ export class ShareTokenUC { private readonly lessonService: LessonService, private readonly taskService: TaskService, private readonly roomService: RoomService, - private readonly roomMemberService: RoomMemberService, + private readonly roomMembershipService: RoomMembershipService, private readonly columnBoardService: ColumnBoardService, private readonly schoolService: SchoolService, private readonly boardNodeAuthorizableService: BoardNodeAuthorizableService, @@ -249,11 +249,11 @@ export class ShareTokenUC { } private async checkRoomWritePermission(user: User, roomId: EntityId, permissions: Permission[] = []) { - const roomMemberAuthorizable = await this.roomMemberService.getRoomMemberAuthorizable(roomId); + const roomMembershipAuthorizable = await this.roomMembershipService.getRoomMembershipAuthorizable(roomId); this.authorizationService.checkPermission( user, - roomMemberAuthorizable, + roomMembershipAuthorizable, AuthorizationContextBuilder.write(permissions) ); } diff --git a/apps/server/src/shared/domain/entity/all-entities.ts b/apps/server/src/shared/domain/entity/all-entities.ts index 537d17b30d5..23c52671aeb 100644 --- a/apps/server/src/shared/domain/entity/all-entities.ts +++ b/apps/server/src/shared/domain/entity/all-entities.ts @@ -11,7 +11,7 @@ import { ExternalToolPseudonymEntity, PseudonymEntity } from '@modules/pseudonym import { RegistrationPinEntity } from '@modules/registration-pin/entity'; import { RocketChatUserEntity } from '@modules/rocketchat-user/entity'; import { RoomEntity } from '@modules/room/repo/entity'; -import { RoomMemberEntity } from '@src/modules/room-member/repo/entity/room-member.entity'; +import { RoomMembershipEntity } from '@modules/room-membership/repo/entity/room-membership.entity'; import { ShareToken } from '@modules/sharing/entity/share-token.entity'; import { SystemEntity } from '@modules/system/entity/system.entity'; import { TldrawDrawing } from '@modules/tldraw/entities'; @@ -77,7 +77,7 @@ export const ALL_ENTITIES = [ RocketChatUserEntity, Role, RoomEntity, - RoomMemberEntity, + RoomMembershipEntity, SchoolEntity, SchoolExternalToolEntity, SchoolNews, diff --git a/backup/setup/migrations.json b/backup/setup/migrations.json index 211631c68b9..9d02afcf4b9 100644 --- a/backup/setup/migrations.json +++ b/backup/setup/migrations.json @@ -340,5 +340,14 @@ "created_at": { "$date": "2024-11-14T15:43:35.024Z" } + }, + { + "_id": { + "$oid": "67477a7455d881b78f7a79fa" + }, + "name": "Migration202411271951208", + "created_at": { + "$date": "2024-11-27T20:00:52.582Z" + } } ]