diff --git a/backend/src/project/service/project.service.ts b/backend/src/project/service/project.service.ts index d5b5a0f..0fd1c93 100644 --- a/backend/src/project/service/project.service.ts +++ b/backend/src/project/service/project.service.ts @@ -59,6 +59,14 @@ export class ProjectService { return true; } + async isProjectLeader(project: Project, member: Member): Promise { + const projectToMember = await this.projectRepository.getProjectToMember( + project, + member, + ); + return projectToMember?.role === MemberRole.LEADER; + } + getProjectByLinkId(projectLinkId: string): Promise { return this.projectRepository.getProjectByLinkId(projectLinkId); } diff --git a/backend/src/project/ws-controller/ws-project.controller.ts b/backend/src/project/ws-controller/ws-project.controller.ts index 282860e..67a45bf 100644 --- a/backend/src/project/ws-controller/ws-project.controller.ts +++ b/backend/src/project/ws-controller/ws-project.controller.ts @@ -65,6 +65,16 @@ export class WsProjectController { } async joinSettingPage(client: ClientSocket) { + if ( + !(await this.projectService.isProjectLeader( + client.project, + client.member, + )) + ) { + client.disconnect(true); + return; + } + client.leave('landing'); client.leave('backlog'); client.join('setting'); diff --git a/backend/test/project/ws-setting-page/ws-project-landing-page.e2e-spec.ts b/backend/test/project/ws-setting-page/ws-project-landing-page.e2e-spec.ts index ee12c0b..43874f0 100644 --- a/backend/test/project/ws-setting-page/ws-project-landing-page.e2e-spec.ts +++ b/backend/test/project/ws-setting-page/ws-project-landing-page.e2e-spec.ts @@ -72,4 +72,26 @@ describe('WS Setting', () => { socket1.close(); }); }); + + it('Should close connection when member(not leader) enters setting page', async () => { + let socket2: Socket; + + return new Promise(async (resolve) => { + const accessToken1 = (await createMember(memberFixture, app)).accessToken; + const project = await createProject(accessToken1, projectPayload, app); + const projectLinkId = await getProjectLinkId(accessToken1, project.id); + + const accessToken2 = (await createMember(memberFixture2, app)) + .accessToken; + await joinProject(accessToken2, projectLinkId); + + socket2 = connectServer(project.id, accessToken2); + socket2.emit('joinSetting'); + socket2.on('disconnect', () => { + resolve(); + }); + }).finally(() => { + socket2.close(); + }); + }); });