Skip to content

Commit

Permalink
BC-7236 - refactor how to get rootid in socket gateway (#5080)
Browse files Browse the repository at this point in the history
For any action that is executed on a board we have to find out who needs to get the resulting update. Socket.io organizes users in rooms. For the board - all clients on the same board are in the same room.
The room name is based on the boardid. So we always need to find out the rootId of the boardNode the action was executed on. For example: if a card title was rename, the card is the boardNode-object and has the rootId of the board the card is placed on.
*Until now*: the rootId was determined by (re)using the BoardAuthorisableService
*Now*: the rootId can be taken directly from the boardNode (due to boardPersisting-refactorings of Team MilkyWay) which reduces the number of queries that need to be executed

---------

Co-authored-by: hoeppner-dataport <[email protected]>
  • Loading branch information
Metauriel and hoeppner-dataport authored Jul 2, 2024
1 parent 0efdae2 commit c88e496
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 99 deletions.
158 changes: 74 additions & 84 deletions apps/server/src/modules/board/gateway/board-collaboration.gateway.ts

Large diffs are not rendered by default.

39 changes: 36 additions & 3 deletions apps/server/src/modules/board/gateway/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
import { MoveCardMessageParams } from './move-card.message.param';
import { CreateCardMessageParams } from './create-card.message.param';
import { UpdateColumnTitleMessageParams } from './update-column-title.message.param';
import { CreateColumnMessageParams } from './create-column.message.param';
import { CreateContentElementMessageParams } from './create-content-element.message.param';
import { DeleteBoardMessageParams } from './delete-board.message.param';
import { DeleteCardMessageParams } from './delete-card.message.param';
import { DeleteContentElementMessageParams } from './delete-content-element.message.param';
import { DeleteColumnMessageParams } from './delete-column.message.param';
import { FetchBoardMessageParams } from './fetch-board.message.param';
import { FetchCardsMessageParams } from './fetch-cards.message.param';
import { MoveCardMessageParams } from './move-card.message.param';
import { MoveColumnMessageParams } from './move-column.message.param';
import { MoveContentElementMessageParams } from './move-content-element.message.param';
import { UpdateBoardTitleMessageParams } from './update-board-title.message.param';
import { UpdateBoardVisibilityMessageParams } from './update-board-visibility.message.param';
import { UpdateCardHeightMessageParams } from './update-card-height.message.param';
import { UpdateCardTitleMessageParams } from './update-card-title.message.param';
import { UpdateColumnTitleMessageParams } from './update-column-title.message.param';
import { UpdateContentElementMessageParams } from './update-content-element.message.param';

export { MoveCardMessageParams, CreateCardMessageParams, UpdateColumnTitleMessageParams, DeleteColumnMessageParams };
export {
CreateCardMessageParams,
CreateColumnMessageParams,
CreateContentElementMessageParams,
DeleteBoardMessageParams,
DeleteCardMessageParams,
DeleteColumnMessageParams,
DeleteContentElementMessageParams,
FetchBoardMessageParams,
FetchCardsMessageParams,
MoveCardMessageParams,
MoveColumnMessageParams,
MoveContentElementMessageParams,
UpdateBoardTitleMessageParams,
UpdateBoardVisibilityMessageParams,
UpdateCardHeightMessageParams,
UpdateCardTitleMessageParams,
UpdateColumnTitleMessageParams,
UpdateContentElementMessageParams,
};
12 changes: 8 additions & 4 deletions apps/server/src/modules/board/uc/board.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,24 @@ export class BoardUc {
return board.context;
}

async deleteBoard(userId: EntityId, boardId: EntityId): Promise<void> {
async deleteBoard(userId: EntityId, boardId: EntityId): Promise<ColumnBoard> {
this.logger.debug({ action: 'deleteBoard', userId, boardId });

const board = await this.boardNodeService.findByClassAndId(ColumnBoard, boardId);
await this.boardPermissionService.checkPermission(userId, board, Action.write);

await this.boardNodeService.delete(board);
return board;
}

async updateBoardTitle(userId: EntityId, boardId: EntityId, title: string): Promise<void> {
async updateBoardTitle(userId: EntityId, boardId: EntityId, title: string): Promise<ColumnBoard> {
this.logger.debug({ action: 'updateBoardTitle', userId, boardId, title });

const board = await this.boardNodeService.findByClassAndId(ColumnBoard, boardId);
await this.boardPermissionService.checkPermission(userId, board, Action.write);

await this.boardNodeService.updateTitle(board, title);
return board;
}

async createColumn(userId: EntityId, boardId: EntityId): Promise<Column> {
Expand All @@ -101,7 +103,7 @@ export class BoardUc {
columnId: EntityId,
targetBoardId: EntityId,
targetPosition: number
): Promise<void> {
): Promise<Column> {
this.logger.debug({ action: 'moveColumn', userId, columnId, targetBoardId, targetPosition });

const column = await this.boardNodeService.findByClassAndId(Column, columnId);
Expand All @@ -111,6 +113,7 @@ export class BoardUc {
await this.boardPermissionService.checkPermission(userId, targetBoard, Action.write);

await this.boardNodeService.move(column, targetBoard, targetPosition);
return column;
}

async copyBoard(userId: EntityId, boardId: EntityId): Promise<CopyStatus> {
Expand All @@ -137,10 +140,11 @@ export class BoardUc {
return copyStatus;
}

async updateVisibility(userId: EntityId, boardId: EntityId, isVisible: boolean): Promise<void> {
async updateVisibility(userId: EntityId, boardId: EntityId, isVisible: boolean): Promise<ColumnBoard> {
const board = await this.boardNodeService.findByClassAndId(ColumnBoard, boardId);
await this.boardPermissionService.checkPermission(userId, board, Action.write);

await this.boardNodeService.updateVisibility(board, isVisible);
return board;
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/board/uc/card.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ describe(CardUc.name, () => {
describe('when deleting a card', () => {
it('should call the service to find the card', async () => {
const { user, card } = setup();
boardNodeService.findByClassAndId.mockResolvedValueOnce(card);

await uc.deleteCard(user.id, card.id);

Expand Down
14 changes: 10 additions & 4 deletions apps/server/src/modules/board/uc/card.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,35 @@ export class CardUc {
return allowedCards;
}

async updateCardHeight(userId: EntityId, cardId: EntityId, height: number): Promise<void> {
async updateCardHeight(userId: EntityId, cardId: EntityId, height: number): Promise<Card> {
this.logger.debug({ action: 'updateCardHeight', userId, cardId, height });

const card = await this.boardNodeService.findByClassAndId(Card, cardId);
await this.boardNodePermissionService.checkPermission(userId, card, Action.write);

await this.boardNodeService.updateHeight(card, height);
return card;
}

async updateCardTitle(userId: EntityId, cardId: EntityId, title: string): Promise<void> {
async updateCardTitle(userId: EntityId, cardId: EntityId, title: string): Promise<Card> {
this.logger.debug({ action: 'updateCardTitle', userId, cardId, title });

const card = await this.boardNodeService.findByClassAndId(Card, cardId);
await this.boardNodePermissionService.checkPermission(userId, card, Action.write);

await this.boardNodeService.updateTitle(card, title);
return card;
}

async deleteCard(userId: EntityId, cardId: EntityId): Promise<void> {
async deleteCard(userId: EntityId, cardId: EntityId): Promise<EntityId> {
this.logger.debug({ action: 'deleteCard', userId, cardId });

const card = await this.boardNodeService.findByClassAndId(Card, cardId);
const { rootId } = card;
await this.boardNodePermissionService.checkPermission(userId, card, Action.write);

await this.boardNodeService.delete(card);
return rootId;
}

// --- elements ---
Expand Down Expand Up @@ -98,7 +102,7 @@ export class CardUc {
elementId: EntityId,
targetCardId: EntityId,
targetPosition: number
): Promise<void> {
): Promise<AnyContentElement> {
this.logger.debug({ action: 'moveElement', userId, elementId, targetCardId, targetPosition });

const element = await this.boardNodeService.findContentElementById(elementId);
Expand All @@ -108,5 +112,7 @@ export class CardUc {
await this.boardNodePermissionService.checkPermission(userId, targetCard, Action.write);

await this.boardNodeService.move(element, targetCard, targetPosition);

return element;
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/board/uc/column.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe(ColumnUc.name, () => {
describe('when deleting a column', () => {
it('should call the service to find the column', async () => {
const { user, column } = setup();
boardNodeService.findByClassAndId.mockResolvedValueOnce(column);

await uc.deleteColumn(user.id, column.id);

Expand Down
11 changes: 8 additions & 3 deletions apps/server/src/modules/board/uc/column.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ export class ColumnUc {
this.logger.setContext(ColumnUc.name);
}

async deleteColumn(userId: EntityId, columnId: EntityId): Promise<void> {
async deleteColumn(userId: EntityId, columnId: EntityId): Promise<EntityId> {
this.logger.debug({ action: 'deleteColumn', userId, columnId });

const column = await this.boardNodeService.findByClassAndId(Column, columnId);
const { rootId } = column;
await this.boardNodePermissionService.checkPermission(userId, column, Action.write);

await this.boardNodeService.delete(column);

return rootId;
}

async updateColumnTitle(userId: EntityId, columnId: EntityId, title: string): Promise<void> {
async updateColumnTitle(userId: EntityId, columnId: EntityId, title: string): Promise<Column> {
this.logger.debug({ action: 'updateColumnTitle', userId, columnId, title });

const column = await this.boardNodeService.findByClassAndId(Column, columnId);
await this.boardNodePermissionService.checkPermission(userId, column, Action.write);

await this.boardNodeService.updateTitle(column, title);
return column;
}

async createCard(
Expand All @@ -53,7 +57,7 @@ export class ColumnUc {
return card;
}

async moveCard(userId: EntityId, cardId: EntityId, targetColumnId: EntityId, targetPosition: number): Promise<void> {
async moveCard(userId: EntityId, cardId: EntityId, targetColumnId: EntityId, targetPosition: number): Promise<Card> {
this.logger.debug({ action: 'moveCard', userId, cardId, targetColumnId, toPosition: targetPosition });

const card = await this.boardNodeService.findByClassAndId(Card, cardId);
Expand All @@ -63,5 +67,6 @@ export class ColumnUc {
await this.boardNodePermissionService.checkPermission(userId, targetColumn, Action.write);

await this.boardNodeService.move(card, targetColumn, targetPosition);
return card;
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/board/uc/element.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe(ElementUc.name, () => {

it('should call the service to find the element', async () => {
const { user, element } = setup();
boardNodeService.findContentElementById.mockResolvedValueOnce(element);

await uc.deleteElement(user.id, element.id);

Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/modules/board/uc/element.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export class ElementUc {
return element;
}

async deleteElement(userId: EntityId, elementId: EntityId): Promise<void> {
async deleteElement(userId: EntityId, elementId: EntityId): Promise<EntityId> {
const element = await this.boardNodeService.findContentElementById(elementId);
const { rootId } = element;
await this.boardPermissionService.checkPermission(userId, element, Action.write);

await this.boardNodeService.delete(element);
return rootId;
}

async checkElementReadPermission(userId: EntityId, elementId: EntityId): Promise<void> {
Expand Down

0 comments on commit c88e496

Please sign in to comment.