diff --git a/apps/server/doc/file-structure.md b/apps/server/doc/file-structure.md index 9f63d339c30..8b0c2969a8c 100644 --- a/apps/server/doc/file-structure.md +++ b/apps/server/doc/file-structure.md @@ -158,7 +158,7 @@ The main responsibilities of a controller is to define the REST API interface as ```TypeScript @Post() - async create(@CurrentUser() currentUser: CurrentUserInterface, @Body() params: CreateNewsParams): Promise { + async create(@CurrentUser() currentUser: ICurrentUser, @Body() params: CreateNewsParams): Promise { const news = await this.newsUc.create( currentUser.userId, currentUser.schoolId, @@ -171,7 +171,7 @@ The main responsibilities of a controller is to define the REST API interface as #### JWT-Authentication -For **authentication**, use [guards](https://docs.nestjs.com/guards) like JwtAuthGuard. It can be applied to a whole controller or a single controller method only. Then, [CurrentUserInterface](/apps/server/src/modules/authentication/interface/jwt-payload.ts) can be injected using the `@CurrentUser()` decorator. +For **authentication**, use [guards](https://docs.nestjs.com/guards) like JwtAuthGuard. It can be applied to a whole controller or a single controller method only. Then, [ICurrentUser](/apps/server/src/modules/authentication/interface/jwt-payload.ts) can be injected using the `@CurrentUser()` decorator. #### Validation diff --git a/apps/server/src/modules/account/controller/account.controller.ts b/apps/server/src/modules/account/controller/account.controller.ts index c9d141cc4c3..3265693915c 100644 --- a/apps/server/src/modules/account/controller/account.controller.ts +++ b/apps/server/src/modules/account/controller/account.controller.ts @@ -1,7 +1,7 @@ import { Body, Controller, Delete, Get, Param, Patch, Query } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { EntityNotFoundError, ForbiddenOperationError, ValidationError } from '@shared/common'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator'; import { AccountUc } from '../uc/account.uc'; import { @@ -29,7 +29,7 @@ export class AccountController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero or administrator.' }) async searchAccounts( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() query: AccountSearchQueryParams ): Promise { return this.accountUc.searchAccounts(currentUser, query); @@ -42,7 +42,7 @@ export class AccountController { @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero.' }) @ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' }) async findAccountById( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: AccountByIdParams ): Promise { return this.accountUc.findAccountById(currentUser, params); @@ -57,10 +57,7 @@ export class AccountController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'Invalid password.' }) @ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' }) - async updateMyAccount( - @CurrentUser() currentUser: CurrentUserInterface, - @Body() params: PatchMyAccountParams - ): Promise { + async updateMyAccount(@CurrentUser() currentUser: ICurrentUser, @Body() params: PatchMyAccountParams): Promise { return this.accountUc.updateMyAccount(currentUser.userId, params); } @@ -71,7 +68,7 @@ export class AccountController { @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero.' }) @ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' }) async updateAccountById( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: AccountByIdParams, @Body() body: AccountByIdBodyParams ): Promise { @@ -85,7 +82,7 @@ export class AccountController { @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero.' }) @ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' }) async deleteAccountById( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: AccountByIdParams ): Promise { return this.accountUc.deleteAccountById(currentUser, params); @@ -98,7 +95,7 @@ export class AccountController { @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'Invalid password.' }) @ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account or user not found.' }) async replaceMyPassword( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() params: PatchMyPasswordParams ): Promise { return this.accountUc.replaceMyTemporaryPassword(currentUser.userId, params.password, params.confirmPassword); diff --git a/apps/server/src/modules/account/controller/api-test/account.api.spec.ts b/apps/server/src/modules/account/controller/api-test/account.api.spec.ts index 412ef54a2f4..7a920a40a97 100644 --- a/apps/server/src/modules/account/controller/api-test/account.api.spec.ts +++ b/apps/server/src/modules/account/controller/api-test/account.api.spec.ts @@ -10,7 +10,7 @@ import { PatchMyAccountParams, PatchMyPasswordParams, } from '@src/modules/account/controller/dto'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@src/modules/server/server.module'; import { Request } from 'express'; @@ -32,7 +32,7 @@ describe('Account Controller (API)', () => { let studentUser: User; let superheroUser: User; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; const defaultPassword = 'DummyPasswd!1'; const defaultPasswordHash = '$2a$10$/DsztV5o6P5piW2eWJsxw.4nHovmJGBA.QNwiTmuZ/uvUc40b.Uhu'; diff --git a/apps/server/src/modules/account/uc/account.uc.spec.ts b/apps/server/src/modules/account/uc/account.uc.spec.ts index f9a16fea991..6810c2baa5c 100644 --- a/apps/server/src/modules/account/uc/account.uc.spec.ts +++ b/apps/server/src/modules/account/uc/account.uc.spec.ts @@ -2,7 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { AccountService } from '@modules/account/services/account.service'; import { AccountSaveDto } from '@modules/account/services/dto'; import { AccountDto } from '@modules/account/services/dto/account.dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { AuthorizationError, EntityNotFoundError, ForbiddenOperationError, ValidationError } from '@shared/common'; @@ -795,7 +795,7 @@ describe('AccountUc', () => { describe('searchAccounts', () => { it('should return one account, if search type is userId', async () => { const accounts = await accountUc.searchAccounts( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { type: AccountSearchType.USER_ID, value: mockStudentUser.id } as AccountSearchQueryParams ); const expected = new AccountSearchListResponse( @@ -808,7 +808,7 @@ describe('AccountUc', () => { }); it('should return empty list, if account is not found', async () => { const accounts = await accountUc.searchAccounts( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { type: AccountSearchType.USER_ID, value: mockUserWithoutAccount.id } as AccountSearchQueryParams ); const expected = new AccountSearchListResponse([], 0, 0, 0); @@ -816,7 +816,7 @@ describe('AccountUc', () => { }); it('should return one or more accounts, if search type is username', async () => { const accounts = await accountUc.searchAccounts( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { type: AccountSearchType.USERNAME, value: '' } as AccountSearchQueryParams ); expect(accounts.skip).toEqual(0); @@ -827,21 +827,21 @@ describe('AccountUc', () => { it('should throw, if user has not the right permissions', async () => { await expect( accountUc.searchAccounts( - { userId: mockTeacherUser.id } as CurrentUserInterface, + { userId: mockTeacherUser.id } as ICurrentUser, { type: AccountSearchType.USER_ID, value: mockAdminUser.id } as AccountSearchQueryParams ) ).rejects.toThrow(ForbiddenOperationError); await expect( accountUc.searchAccounts( - { userId: mockStudentUser.id } as CurrentUserInterface, + { userId: mockStudentUser.id } as ICurrentUser, { type: AccountSearchType.USER_ID, value: mockOtherStudentUser.id } as AccountSearchQueryParams ) ).rejects.toThrow(ForbiddenOperationError); await expect( accountUc.searchAccounts( - { userId: mockStudentUser.id } as CurrentUserInterface, + { userId: mockStudentUser.id } as ICurrentUser, { type: AccountSearchType.USER_ID, value: mockTeacherUser.id } as AccountSearchQueryParams ) ).rejects.toThrow(ForbiddenOperationError); @@ -849,7 +849,7 @@ describe('AccountUc', () => { it('should throw, if search type is unknown', async () => { await expect( accountUc.searchAccounts( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { type: '' as AccountSearchType } as AccountSearchQueryParams ) ).rejects.toThrow('Invalid search type.'); @@ -857,7 +857,7 @@ describe('AccountUc', () => { it('should throw, if user is no superhero', async () => { await expect( accountUc.searchAccounts( - { userId: mockTeacherUser.id } as CurrentUserInterface, + { userId: mockTeacherUser.id } as ICurrentUser, { type: AccountSearchType.USERNAME, value: mockStudentUser.id } as AccountSearchQueryParams ) ).rejects.toThrow(ForbiddenOperationError); @@ -868,22 +868,22 @@ describe('AccountUc', () => { configService.get.mockReturnValue(false); }); it('admin can access teacher of the same school via user id', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockTeacherUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).resolves.not.toThrow(); }); it('admin can access student of the same school via user id', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockStudentUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).resolves.not.toThrow(); }); it('admin can not access admin of the same school via user id', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockAdminUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); }); it('admin can not access any account of a foreign school via user id', async () => { - const currentUser = { userId: mockDifferentSchoolAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockDifferentSchoolAdminUser.id } as ICurrentUser; let params = { type: AccountSearchType.USER_ID, value: mockTeacherUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); @@ -892,22 +892,22 @@ describe('AccountUc', () => { await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); }); it('teacher can access teacher of the same school via user id', async () => { - const currentUser = { userId: mockTeacherUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockOtherTeacherUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).resolves.not.toThrow(); }); it('teacher can access student of the same school via user id', async () => { - const currentUser = { userId: mockTeacherUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockStudentUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).resolves.not.toThrow(); }); it('teacher can not access admin of the same school via user id', async () => { - const currentUser = { userId: mockTeacherUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockAdminUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); }); it('teacher can not access any account of a foreign school via user id', async () => { - const currentUser = { userId: mockDifferentSchoolTeacherUser.id } as CurrentUserInterface; + const currentUser = { userId: mockDifferentSchoolTeacherUser.id } as ICurrentUser; let params = { type: AccountSearchType.USER_ID, value: mockTeacherUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); @@ -917,7 +917,7 @@ describe('AccountUc', () => { }); it('teacher can access student of the same school via user id if school has global permission', async () => { configService.get.mockReturnValue(true); - const currentUser = { userId: mockTeacherNoUserPermissionUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherNoUserPermissionUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockStudentSchoolPermissionUser.id, @@ -926,14 +926,14 @@ describe('AccountUc', () => { }); it('teacher can not access student of the same school if school has no global permission', async () => { configService.get.mockReturnValue(true); - const currentUser = { userId: mockTeacherNoUserNoSchoolPermissionUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherNoUserNoSchoolPermissionUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockStudentUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(ForbiddenOperationError); }); it('student can not access student of the same school if school has global permission', async () => { configService.get.mockReturnValue(true); - const currentUser = { userId: mockStudentSchoolPermissionUser.id } as CurrentUserInterface; + const currentUser = { userId: mockStudentSchoolPermissionUser.id } as ICurrentUser; const params = { type: AccountSearchType.USER_ID, value: mockOtherStudentSchoolPermissionUser.id, @@ -941,7 +941,7 @@ describe('AccountUc', () => { await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(ForbiddenOperationError); }); it('student can not access any other account via user id', async () => { - const currentUser = { userId: mockStudentUser.id } as CurrentUserInterface; + const currentUser = { userId: mockStudentUser.id } as ICurrentUser; let params = { type: AccountSearchType.USER_ID, value: mockAdminUser.id } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); @@ -953,7 +953,7 @@ describe('AccountUc', () => { await expect(accountUc.searchAccounts(currentUser, params)).rejects.toThrow(); }); it('superhero can access any account via username', async () => { - const currentUser = { userId: mockSuperheroUser.id } as CurrentUserInterface; + const currentUser = { userId: mockSuperheroUser.id } as ICurrentUser; let params = { type: AccountSearchType.USERNAME, value: mockAdminAccount.username } as AccountSearchQueryParams; await expect(accountUc.searchAccounts(currentUser, params)).resolves.not.toThrow(); @@ -988,7 +988,7 @@ describe('AccountUc', () => { describe('findAccountById', () => { it('should return an account, if the current user is a superhero', async () => { const account = await accountUc.findAccountById( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { id: mockStudentAccount.id } as AccountByIdParams ); expect(account).toStrictEqual( @@ -1003,25 +1003,19 @@ describe('AccountUc', () => { it('should throw, if the current user is no superhero', async () => { await expect( accountUc.findAccountById( - { userId: mockTeacherUser.id } as CurrentUserInterface, + { userId: mockTeacherUser.id } as ICurrentUser, { id: mockStudentAccount.id } as AccountByIdParams ) ).rejects.toThrow(ForbiddenOperationError); }); it('should throw, if no account matches the search term', async () => { await expect( - accountUc.findAccountById( - { userId: mockSuperheroUser.id } as CurrentUserInterface, - { id: 'xxx' } as AccountByIdParams - ) + accountUc.findAccountById({ userId: mockSuperheroUser.id } as ICurrentUser, { id: 'xxx' } as AccountByIdParams) ).rejects.toThrow(EntityNotFoundError); }); it('should throw, if target account has no user', async () => { await expect( - accountUc.findAccountById( - { userId: mockSuperheroUser.id } as CurrentUserInterface, - { id: 'xxx' } as AccountByIdParams - ) + accountUc.findAccountById({ userId: mockSuperheroUser.id } as ICurrentUser, { id: 'xxx' } as AccountByIdParams) ).rejects.toThrow(EntityNotFoundError); }); }); @@ -1048,20 +1042,20 @@ describe('AccountUc', () => { describe('updateAccountById', () => { it('should throw if executing user does not exist', async () => { - const currentUser = { userId: '000000000000000' } as CurrentUserInterface; + const currentUser = { userId: '000000000000000' } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(EntityNotFoundError); }); it('should throw if target account does not exist', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: '000000000000000' } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(EntityNotFoundError); }); it('should update target account password', async () => { const previousPasswordHash = mockStudentAccount.password; - const currentUser = { userId: mockSuperheroUser.id } as CurrentUserInterface; + const currentUser = { userId: mockSuperheroUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = { password: defaultPassword } as AccountByIdBodyParams; expect(mockStudentUser.forcePasswordChange).toBeFalsy(); @@ -1071,7 +1065,7 @@ describe('AccountUc', () => { }); it('should update target account username', async () => { const newUsername = 'newUsername'; - const currentUser = { userId: mockSuperheroUser.id } as CurrentUserInterface; + const currentUser = { userId: mockSuperheroUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = { username: newUsername } as AccountByIdBodyParams; expect(mockStudentAccount.username).not.toBe(newUsername); @@ -1079,20 +1073,20 @@ describe('AccountUc', () => { expect(mockStudentAccount.username).toBe(newUsername.toLowerCase()); }); it('should update target account activation state', async () => { - const currentUser = { userId: mockSuperheroUser.id } as CurrentUserInterface; + const currentUser = { userId: mockSuperheroUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = { activated: false } as AccountByIdBodyParams; await accountUc.updateAccountById(currentUser, params, body); expect(mockStudentAccount.activated).toBeFalsy(); }); it('should throw if account can not be updated', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = { username: 'fail@to.update' } as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(EntityNotFoundError); }); it('should throw if user can not be updated', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = { username: 'user-fail@to.update' } as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(EntityNotFoundError); @@ -1100,7 +1094,7 @@ describe('AccountUc', () => { it('should throw if target account has no user', async () => { await expect( accountUc.updateAccountById( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { id: mockAccountWithoutUser.id } as AccountByIdParams, { username: 'user-fail@to.update' } as AccountByIdBodyParams ) @@ -1109,7 +1103,7 @@ describe('AccountUc', () => { it('should throw if new username already in use', async () => { const accountIsUniqueEmailSpy = jest.spyOn(accountValidationService, 'isUniqueEmail'); accountIsUniqueEmailSpy.mockResolvedValueOnce(false); - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = { username: mockOtherTeacherAccount.username } as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(ValidationError); @@ -1117,49 +1111,49 @@ describe('AccountUc', () => { describe('hasPermissionsToUpdateAccount', () => { it('admin can edit teacher', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: mockTeacherAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).resolves.not.toThrow(); }); it('teacher can edit student', async () => { - const currentUser = { userId: mockTeacherUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).resolves.not.toThrow(); }); it('admin can edit student', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: mockStudentAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).resolves.not.toThrow(); }); it('teacher cannot edit other teacher', async () => { - const currentUser = { userId: mockTeacherUser.id } as CurrentUserInterface; + const currentUser = { userId: mockTeacherUser.id } as ICurrentUser; const params = { id: mockOtherTeacherAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(ForbiddenOperationError); }); it("other school's admin cannot edit teacher", async () => { - const currentUser = { userId: mockDifferentSchoolAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockDifferentSchoolAdminUser.id } as ICurrentUser; const params = { id: mockTeacherAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(ForbiddenOperationError); }); it('superhero can edit admin', async () => { - const currentUser = { userId: mockSuperheroUser.id } as CurrentUserInterface; + const currentUser = { userId: mockSuperheroUser.id } as ICurrentUser; const params = { id: mockAdminAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).resolves.not.toThrow(); }); it('undefined user role fails by default', async () => { - const currentUser = { userId: mockUnknownRoleUser.id } as CurrentUserInterface; + const currentUser = { userId: mockUnknownRoleUser.id } as ICurrentUser; const params = { id: mockAccountWithoutRole.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(ForbiddenOperationError); }); it('user without role cannot be edited', async () => { - const currentUser = { userId: mockAdminUser.id } as CurrentUserInterface; + const currentUser = { userId: mockAdminUser.id } as ICurrentUser; const params = { id: mockUnknownRoleUserAccount.id } as AccountByIdParams; const body = {} as AccountByIdBodyParams; await expect(accountUc.updateAccountById(currentUser, params, body)).rejects.toThrow(ForbiddenOperationError); @@ -1171,7 +1165,7 @@ describe('AccountUc', () => { it('should delete an account, if current user is authorized', async () => { await expect( accountUc.deleteAccountById( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { id: mockStudentAccount.id } as AccountByIdParams ) ).resolves.not.toThrow(); @@ -1179,7 +1173,7 @@ describe('AccountUc', () => { it('should throw, if the current user is no superhero', async () => { await expect( accountUc.deleteAccountById( - { userId: mockAdminUser.id } as CurrentUserInterface, + { userId: mockAdminUser.id } as ICurrentUser, { id: mockStudentAccount.id } as AccountByIdParams ) ).rejects.toThrow(ForbiddenOperationError); @@ -1187,7 +1181,7 @@ describe('AccountUc', () => { it('should throw, if no account matches the search term', async () => { await expect( accountUc.deleteAccountById( - { userId: mockSuperheroUser.id } as CurrentUserInterface, + { userId: mockSuperheroUser.id } as ICurrentUser, { id: 'xxx' } as AccountByIdParams ) ).rejects.toThrow(EntityNotFoundError); diff --git a/apps/server/src/modules/account/uc/account.uc.ts b/apps/server/src/modules/account/uc/account.uc.ts index e3f33d20c14..dac0b936ba5 100644 --- a/apps/server/src/modules/account/uc/account.uc.ts +++ b/apps/server/src/modules/account/uc/account.uc.ts @@ -11,7 +11,7 @@ import { import { Account, EntityId, Permission, PermissionService, Role, RoleName, SchoolEntity, User } from '@shared/domain'; import { UserRepo } from '@shared/repo'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { BruteForcePrevention } from '@src/imports-from-feathers'; import { ObjectId } from 'bson'; import { AccountConfig } from '../account-config'; @@ -50,10 +50,7 @@ export class AccountUc { * @throws {ValidationError} * @throws {ForbiddenOperationError} */ - async searchAccounts( - currentUser: CurrentUserInterface, - query: AccountSearchQueryParams - ): Promise { + async searchAccounts(currentUser: ICurrentUser, query: AccountSearchQueryParams): Promise { const skip = query.skip ?? 0; const limit = query.limit ?? 10; const executingUser = await this.userRepo.findById(currentUser.userId, true); @@ -91,7 +88,7 @@ export class AccountUc { * @throws {ForbiddenOperationError} * @throws {EntityNotFoundError} */ - async findAccountById(currentUser: CurrentUserInterface, params: AccountByIdParams): Promise { + async findAccountById(currentUser: ICurrentUser, params: AccountByIdParams): Promise { if (!(await this.isSuperhero(currentUser))) { throw new ForbiddenOperationError('Current user is not authorized to search for accounts.'); } @@ -113,7 +110,7 @@ export class AccountUc { * @throws {EntityNotFoundError} */ async updateAccountById( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, params: AccountByIdParams, body: AccountByIdBodyParams ): Promise { @@ -176,7 +173,7 @@ export class AccountUc { * @throws {ForbiddenOperationError} * @throws {EntityNotFoundError} */ - async deleteAccountById(currentUser: CurrentUserInterface, params: AccountByIdParams): Promise { + async deleteAccountById(currentUser: ICurrentUser, params: AccountByIdParams): Promise { if (!(await this.isSuperhero(currentUser))) { throw new ForbiddenOperationError('Current user is not authorized to delete an account.'); } @@ -333,7 +330,7 @@ export class AccountUc { return user.roles.getItems().some((role) => role.name === roleName); } - private async isSuperhero(currentUser: CurrentUserInterface): Promise { + private async isSuperhero(currentUser: ICurrentUser): Promise { const user = await this.userRepo.findById(currentUser.userId, true); return user.roles.getItems().some((role) => role.name === RoleName.SUPERHERO); } diff --git a/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts b/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts index 4f62addfebe..04683e182a8 100644 --- a/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts +++ b/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts @@ -11,7 +11,7 @@ import MockAdapter from 'axios-mock-adapter'; import crypto, { KeyPairKeyObjectResult } from 'crypto'; import jwt from 'jsonwebtoken'; import request, { Response } from 'supertest'; -import { CurrentUserInterface } from '../../interface'; +import { ICurrentUser } from '../../interface'; import { LdapAuthorizationBodyParams, LocalAuthorizationBodyParams, OauthLoginResponse } from '../dto'; const ldapAccountUserName = 'ldapAccountUserName'; @@ -282,7 +282,7 @@ describe('Login Controller (api)', () => { expect(response.body.accessToken).toBeDefined(); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument const decodedToken = jwt.decode(response.body.accessToken); - expect(decodedToken).toMatchObject({ + expect(decodedToken).toMatchObject({ userId: user.id, systemId: system.id, roles: [studentRole.id], diff --git a/apps/server/src/modules/authentication/controllers/login.controller.ts b/apps/server/src/modules/authentication/controllers/login.controller.ts index a747358b6ee..68af396233e 100644 --- a/apps/server/src/modules/authentication/controllers/login.controller.ts +++ b/apps/server/src/modules/authentication/controllers/login.controller.ts @@ -3,7 +3,7 @@ import { AuthGuard } from '@nestjs/passport'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { ForbiddenOperationError, ValidationError } from '@shared/common'; import { CurrentUser } from '../decorator'; -import type { CurrentUserInterface, OauthCurrentUser } from '../interface'; +import type { ICurrentUser, OauthCurrentUser } from '../interface'; import { LoginDto } from '../uc/dto'; import { LoginUc } from '../uc/login.uc'; import { @@ -28,10 +28,7 @@ export class LoginController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'Invalid user credentials.' }) // eslint-disable-next-line @typescript-eslint/no-unused-vars - async loginLdap( - @CurrentUser() user: CurrentUserInterface, - @Body() _: LdapAuthorizationBodyParams - ): Promise { + async loginLdap(@CurrentUser() user: ICurrentUser, @Body() _: LdapAuthorizationBodyParams): Promise { const loginDto: LoginDto = await this.loginUc.getLoginData(user); const mapped: LoginResponse = LoginResponseMapper.mapToLoginResponse(loginDto); @@ -47,10 +44,7 @@ export class LoginController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'Invalid user credentials.' }) // eslint-disable-next-line @typescript-eslint/no-unused-vars - async loginLocal( - @CurrentUser() user: CurrentUserInterface, - @Body() _: LocalAuthorizationBodyParams - ): Promise { + async loginLocal(@CurrentUser() user: ICurrentUser, @Body() _: LocalAuthorizationBodyParams): Promise { const loginDto: LoginDto = await this.loginUc.getLoginData(user); const mapped: LoginResponse = LoginResponseMapper.mapToLoginResponse(loginDto); diff --git a/apps/server/src/modules/authentication/decorator/auth.decorator.spec.ts b/apps/server/src/modules/authentication/decorator/auth.decorator.spec.ts index 4cfc981f89d..cc6006228b8 100644 --- a/apps/server/src/modules/authentication/decorator/auth.decorator.spec.ts +++ b/apps/server/src/modules/authentication/decorator/auth.decorator.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { ServerTestModule } from '@modules/server/server.module'; import { Controller, ExecutionContext, ForbiddenException, Get, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -11,7 +11,7 @@ import { Authenticate, CurrentUser, JWT } from './auth.decorator'; @Controller('test_decorator_currentUser') export class TestDecoratorCurrentUserController { @Get('test') - async test(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async test(@CurrentUser() currentUser: ICurrentUser): Promise { return Promise.resolve(); } } @@ -27,7 +27,7 @@ export class TestDecoratorJWTController { describe('auth.decorator', () => { let app: INestApplication; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let module: TestingModule; beforeAll(async () => { diff --git a/apps/server/src/modules/authentication/decorator/auth.decorator.ts b/apps/server/src/modules/authentication/decorator/auth.decorator.ts index 48b069e97d1..6d36784af0d 100644 --- a/apps/server/src/modules/authentication/decorator/auth.decorator.ts +++ b/apps/server/src/modules/authentication/decorator/auth.decorator.ts @@ -10,7 +10,7 @@ import { ApiBearerAuth } from '@nestjs/swagger'; import { Request } from 'express'; import { ExtractJwt } from 'passport-jwt'; import { JwtAuthGuard } from '../guard/jwt-auth.guard'; -import { CurrentUserInterface } from '../interface/user'; +import { ICurrentUser } from '../interface/user'; import { JwtExtractor } from '../strategy/jwt-extractor'; const STRATEGIES = ['jwt'] as const; @@ -40,16 +40,14 @@ export const Authenticate = (...strategies: Strategies) => { * @requires Authenticated */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export const CurrentUser = createParamDecorator( - (data: unknown, ctx: ExecutionContext) => { - const { user }: Request = ctx.switchToHttp().getRequest(); - if (!user) - throw new UnauthorizedException( - 'CurrentUser missing in request context. This route requires jwt authentication guard enabled.' - ); - return user as CurrentUserInterface; - } -); +export const CurrentUser = createParamDecorator((data: unknown, ctx: ExecutionContext) => { + const { user }: Request = ctx.switchToHttp().getRequest(); + if (!user) + throw new UnauthorizedException( + 'CurrentUser missing in request context. This route requires jwt authentication guard enabled.' + ); + return user as ICurrentUser; +}); /** * Returns the current JWT. diff --git a/apps/server/src/modules/authentication/index.ts b/apps/server/src/modules/authentication/index.ts index 1a2212989b0..80e9d64ab69 100644 --- a/apps/server/src/modules/authentication/index.ts +++ b/apps/server/src/modules/authentication/index.ts @@ -1,4 +1,4 @@ export { AuthenticationModule } from './authentication.module'; export { Authenticate, CurrentUser, JWT } from './decorator'; -export { CurrentUserInterface } from './interface'; +export { ICurrentUser } from './interface'; export { AuthenticationService } from './services'; diff --git a/apps/server/src/modules/authentication/interface/oauth-current-user.ts b/apps/server/src/modules/authentication/interface/oauth-current-user.ts index 22301f844ae..ddf15e1ca5d 100644 --- a/apps/server/src/modules/authentication/interface/oauth-current-user.ts +++ b/apps/server/src/modules/authentication/interface/oauth-current-user.ts @@ -1,6 +1,6 @@ -import { CurrentUserInterface } from './user'; +import { ICurrentUser } from './user'; -export interface OauthCurrentUser extends CurrentUserInterface { +export interface OauthCurrentUser extends ICurrentUser { /** Contains the idToken of the external idp. Will be set during oAuth2 login and used for rp initiated logout */ externalIdToken?: string; } diff --git a/apps/server/src/modules/authentication/interface/user.ts b/apps/server/src/modules/authentication/interface/user.ts index 5c57713742e..82b6d292d50 100644 --- a/apps/server/src/modules/authentication/interface/user.ts +++ b/apps/server/src/modules/authentication/interface/user.ts @@ -1,6 +1,6 @@ import { EntityId } from '@shared/domain'; -export interface CurrentUserInterface { +export interface ICurrentUser { /** authenticated users id */ userId: EntityId; /** users role ids as EntityId[] */ diff --git a/apps/server/src/modules/authentication/mapper/current-user.mapper.spec.ts b/apps/server/src/modules/authentication/mapper/current-user.mapper.spec.ts index 1339d54cb4c..104ca1219a4 100644 --- a/apps/server/src/modules/authentication/mapper/current-user.mapper.spec.ts +++ b/apps/server/src/modules/authentication/mapper/current-user.mapper.spec.ts @@ -2,7 +2,7 @@ import { ValidationError } from '@shared/common'; import { Permission, RoleName } from '@shared/domain'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { roleFactory, schoolFactory, setupEntities, userDoFactory, userFactory } from '@shared/testing'; -import { CurrentUserInterface, OauthCurrentUser } from '../interface'; +import { ICurrentUser, OauthCurrentUser } from '../interface'; import { CreateJwtPayload, JwtPayload } from '../interface/jwt-payload'; import { CurrentUserMapper } from './current-user.mapper'; @@ -13,7 +13,7 @@ describe('CurrentUserMapper', () => { await setupEntities(); }); - describe('userToCurrentUserInterface', () => { + describe('userToICurrentUser', () => { describe('when mapping from a user entity to the current user object', () => { describe('when user has roles', () => { const setup = () => { @@ -34,11 +34,7 @@ describe('CurrentUserMapper', () => { it('should map with roles', () => { const { teacherRole, user } = setup(); - const currentUser: CurrentUserInterface = CurrentUserMapper.userToCurrentUserInterface( - accountId, - user, - false - ); + const currentUser: ICurrentUser = CurrentUserMapper.userToICurrentUser(accountId, user, false); expect(currentUser).toMatchObject({ accountId, @@ -54,7 +50,7 @@ describe('CurrentUserMapper', () => { it('should map without roles', () => { const user = userFactory.buildWithId(); - const currentUser: CurrentUserInterface = CurrentUserMapper.userToCurrentUserInterface(accountId, user, true); + const currentUser: ICurrentUser = CurrentUserMapper.userToICurrentUser(accountId, user, true); expect(currentUser).toMatchObject({ accountId, @@ -82,12 +78,7 @@ describe('CurrentUserMapper', () => { it('should map system and school', () => { const { user, systemId } = setup(); - const currentUser: CurrentUserInterface = CurrentUserMapper.userToCurrentUserInterface( - accountId, - user, - false, - systemId - ); + const currentUser: ICurrentUser = CurrentUserMapper.userToICurrentUser(accountId, user, false, systemId); expect(currentUser).toMatchObject({ accountId, @@ -169,7 +160,7 @@ describe('CurrentUserMapper', () => { }; }; - it('should return valid CurrentUserInterface instance with systemId', () => { + it('should return valid ICurrentUser instance with systemId', () => { const { user, userId, systemId, idToken } = setup(); const currentUser: OauthCurrentUser = CurrentUserMapper.mapToOauthCurrentUser( @@ -211,7 +202,7 @@ describe('CurrentUserMapper', () => { }; }; - it('should return valid CurrentUserInterface instance without systemId', () => { + it('should return valid ICurrentUser instance without systemId', () => { const { user } = setup(); const currentUser = CurrentUserMapper.mapToOauthCurrentUser(accountId, user, undefined, 'idToken'); @@ -227,7 +218,7 @@ describe('CurrentUserMapper', () => { }); }); - describe('jwtToCurrentUserInterface', () => { + describe('jwtToICurrentUser', () => { describe('when JWT is provided with all claims', () => { const setup = () => { const jwtPayload: JwtPayload = { @@ -254,7 +245,7 @@ describe('CurrentUserMapper', () => { it('should return current user', () => { const { jwtPayload } = setup(); - const currentUser = CurrentUserMapper.jwtToCurrentUserInterface(jwtPayload); + const currentUser = CurrentUserMapper.jwtToICurrentUser(jwtPayload); expect(currentUser).toMatchObject({ accountId: jwtPayload.accountId, @@ -269,7 +260,7 @@ describe('CurrentUserMapper', () => { it('should return current user with default for isExternalUser', () => { const { jwtPayload } = setup(); - const currentUser = CurrentUserMapper.jwtToCurrentUserInterface(jwtPayload); + const currentUser = CurrentUserMapper.jwtToICurrentUser(jwtPayload); expect(currentUser).toMatchObject({ isExternalUser: jwtPayload.isExternalUser, @@ -301,7 +292,7 @@ describe('CurrentUserMapper', () => { it('should return current user', () => { const { jwtPayload } = setup(); - const currentUser = CurrentUserMapper.jwtToCurrentUserInterface(jwtPayload); + const currentUser = CurrentUserMapper.jwtToICurrentUser(jwtPayload); expect(currentUser).toMatchObject({ accountId: jwtPayload.accountId, @@ -315,7 +306,7 @@ describe('CurrentUserMapper', () => { it('should return current user with default for isExternalUser', () => { const { jwtPayload } = setup(); - const currentUser = CurrentUserMapper.jwtToCurrentUserInterface(jwtPayload); + const currentUser = CurrentUserMapper.jwtToICurrentUser(jwtPayload); expect(currentUser).toMatchObject({ isExternalUser: false, @@ -326,7 +317,7 @@ describe('CurrentUserMapper', () => { describe('mapCurrentUserToCreateJwtPayload', () => { it('should map current user to create jwt payload', () => { - const currentUser: CurrentUserInterface = { + const currentUser: ICurrentUser = { accountId: 'dummyAccountId', systemId: 'dummySystemId', roles: ['mockRoleId'], diff --git a/apps/server/src/modules/authentication/mapper/current-user.mapper.ts b/apps/server/src/modules/authentication/mapper/current-user.mapper.ts index 61cf3dcf7da..35dd6c5fe7c 100644 --- a/apps/server/src/modules/authentication/mapper/current-user.mapper.ts +++ b/apps/server/src/modules/authentication/mapper/current-user.mapper.ts @@ -2,16 +2,11 @@ import { ValidationError } from '@shared/common'; import { Role, User } from '@shared/domain'; import { RoleReference } from '@shared/domain/domainobject'; import { UserDO } from '@shared/domain/domainobject/user.do'; -import { CurrentUserInterface, OauthCurrentUser } from '../interface'; +import { ICurrentUser, OauthCurrentUser } from '../interface'; import { CreateJwtPayload, JwtPayload } from '../interface/jwt-payload'; export class CurrentUserMapper { - static userToCurrentUserInterface( - accountId: string, - user: User, - isExternalUser: boolean, - systemId?: string - ): CurrentUserInterface { + static userToICurrentUser(accountId: string, user: User, isExternalUser: boolean, systemId?: string): ICurrentUser { return { accountId, systemId, @@ -43,7 +38,7 @@ export class CurrentUserMapper { }; } - static mapCurrentUserToCreateJwtPayload(currentUser: CurrentUserInterface): CreateJwtPayload { + static mapCurrentUserToCreateJwtPayload(currentUser: ICurrentUser): CreateJwtPayload { return { accountId: currentUser.accountId, userId: currentUser.userId, @@ -55,7 +50,7 @@ export class CurrentUserMapper { }; } - static jwtToCurrentUserInterface(jwtPayload: JwtPayload): CurrentUserInterface { + static jwtToICurrentUser(jwtPayload: JwtPayload): ICurrentUser { return { accountId: jwtPayload.accountId, systemId: jwtPayload.systemId, diff --git a/apps/server/src/modules/authentication/services/authentication.service.spec.ts b/apps/server/src/modules/authentication/services/authentication.service.spec.ts index 6c010e4cead..de80540a65a 100644 --- a/apps/server/src/modules/authentication/services/authentication.service.spec.ts +++ b/apps/server/src/modules/authentication/services/authentication.service.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { AccountService } from '@modules/account/services/account.service'; import { AccountDto } from '@modules/account/services/dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { UnauthorizedException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { JwtService } from '@nestjs/jwt'; @@ -94,7 +94,7 @@ describe('AuthenticationService', () => { describe('generateJwt', () => { describe('when generating new jwt', () => { it('should pass the correct parameters', async () => { - const mockCurrentUser: CurrentUserInterface = { + const mockCurrentUser: ICurrentUser = { accountId: 'mockAccountId', roles: ['student'], schoolId: 'mockSchoolId', diff --git a/apps/server/src/modules/authentication/strategy/jwt.strategy.ts b/apps/server/src/modules/authentication/strategy/jwt.strategy.ts index 76a9b46ce17..6133cf28a69 100644 --- a/apps/server/src/modules/authentication/strategy/jwt.strategy.ts +++ b/apps/server/src/modules/authentication/strategy/jwt.strategy.ts @@ -2,7 +2,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; import { jwtConstants } from '../constants'; -import { CurrentUserInterface } from '../interface'; +import { ICurrentUser } from '../interface'; import { JwtPayload } from '../interface/jwt-payload'; import { CurrentUserMapper } from '../mapper'; import { JwtExtractor } from './jwt-extractor'; @@ -22,14 +22,14 @@ export class JwtStrategy extends PassportStrategy(Strategy) { }); } - async validate(payload: JwtPayload): Promise { + async validate(payload: JwtPayload): Promise { const { accountId, jti } = payload; // check user exists try { // TODO: check user/account is active and has one role // check jwt is whitelisted and extend whitelist entry await this.jwtValidationAdapter.isWhitelisted(accountId, jti); - const currentUser = CurrentUserMapper.jwtToCurrentUserInterface(payload); + const currentUser = CurrentUserMapper.jwtToICurrentUser(payload); return currentUser; } catch (err) { throw new UnauthorizedException('Unauthorized.', { cause: err as Error }); diff --git a/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts b/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts index 5a1b7c7c676..b3067de04eb 100644 --- a/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts +++ b/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts @@ -17,7 +17,7 @@ import { } from '@shared/testing'; import { Logger } from '@src/core/logger'; import { LdapAuthorizationBodyParams } from '../controllers/dto'; -import { CurrentUserInterface } from '../interface'; +import { ICurrentUser } from '../interface'; import { AuthenticationService } from '../services/authentication.service'; import { LdapService } from '../services/ldap.service'; import { LdapStrategy } from './ldap.strategy'; @@ -428,7 +428,7 @@ describe('LdapStrategy', () => { it('should authentication with LDAP successfully and return the user', async () => { const { request, user, school, account, system } = setup(); - const result: CurrentUserInterface = await strategy.validate(request); + const result: ICurrentUser = await strategy.validate(request); expect(result).toEqual({ userId: user.id, @@ -492,7 +492,7 @@ describe('LdapStrategy', () => { it('should authentication with LDAP successfully and return the user', async () => { const { request, user, school, account, system } = setup(); - const result: CurrentUserInterface = await strategy.validate(request); + const result: ICurrentUser = await strategy.validate(request); expect(authenticationServiceMock.loadAccount).toHaveBeenCalledTimes(2); expect(result).toEqual({ diff --git a/apps/server/src/modules/authentication/strategy/ldap.strategy.ts b/apps/server/src/modules/authentication/strategy/ldap.strategy.ts index 3f7e9bf3f9f..6f33e92f21a 100644 --- a/apps/server/src/modules/authentication/strategy/ldap.strategy.ts +++ b/apps/server/src/modules/authentication/strategy/ldap.strategy.ts @@ -7,7 +7,7 @@ import { ErrorLoggable } from '@src/core/error/loggable/error.loggable'; import { Logger } from '@src/core/logger'; import { Strategy } from 'passport-custom'; import { LdapAuthorizationBodyParams } from '../controllers/dto'; -import { CurrentUserInterface } from '../interface'; +import { ICurrentUser } from '../interface'; import { CurrentUserMapper } from '../mapper'; import { AuthenticationService } from '../services/authentication.service'; import { LdapService } from '../services/ldap.service'; @@ -25,7 +25,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { super(); } - async validate(request: { body: LdapAuthorizationBodyParams }): Promise { + async validate(request: { body: LdapAuthorizationBodyParams }): Promise { const { username, password, systemId, schoolId } = this.extractParamsFromRequest(request); const system: SystemEntity = await this.systemRepo.findById(systemId); @@ -48,12 +48,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { await this.checkCredentials(account, system, ldapDn, password); - const currentUser: CurrentUserInterface = CurrentUserMapper.userToCurrentUserInterface( - account.id, - user, - true, - systemId - ); + const currentUser: ICurrentUser = CurrentUserMapper.userToICurrentUser(account.id, user, true, systemId); return currentUser; } diff --git a/apps/server/src/modules/authentication/strategy/local.strategy.ts b/apps/server/src/modules/authentication/strategy/local.strategy.ts index cfceb6f4ed3..c423fc396ff 100644 --- a/apps/server/src/modules/authentication/strategy/local.strategy.ts +++ b/apps/server/src/modules/authentication/strategy/local.strategy.ts @@ -7,7 +7,7 @@ import { GuardAgainst } from '@shared/common/utils/guard-against'; import { UserRepo } from '@shared/repo'; import bcrypt from 'bcryptjs'; import { Strategy } from 'passport-local'; -import { CurrentUserInterface } from '../interface'; +import { ICurrentUser } from '../interface'; import { CurrentUserMapper } from '../mapper'; import { AuthenticationService } from '../services/authentication.service'; @@ -22,7 +22,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) { super(); } - async validate(username?: string, password?: string): Promise { + async validate(username?: string, password?: string): Promise { ({ username, password } = this.cleanupInput(username, password)); const account = await this.authenticationService.loadAccount(username); @@ -39,7 +39,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) { new Error(`login failing, because account ${account.id} has no userId`) ); const user = await this.userRepo.findById(accountUserId, true); - const currentUser = CurrentUserMapper.userToCurrentUserInterface(account.id, user, false); + const currentUser = CurrentUserMapper.userToICurrentUser(account.id, user, false); return currentUser; } diff --git a/apps/server/src/modules/authentication/strategy/oauth2.strategy.spec.ts b/apps/server/src/modules/authentication/strategy/oauth2.strategy.spec.ts index 48e3e3f4174..9f47f0e1d6a 100644 --- a/apps/server/src/modules/authentication/strategy/oauth2.strategy.spec.ts +++ b/apps/server/src/modules/authentication/strategy/oauth2.strategy.spec.ts @@ -8,7 +8,7 @@ import { EntityId, RoleName } from '@shared/domain'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { userDoFactory } from '@shared/testing'; -import { CurrentUserInterface, OauthCurrentUser } from '../interface'; +import { ICurrentUser, OauthCurrentUser } from '../interface'; import { SchoolInMigrationLoggableException } from '../loggable'; @@ -76,10 +76,10 @@ describe('Oauth2Strategy', () => { return { systemId, user, account, idToken }; }; - it('should return the CurrentUserInterface', async () => { + it('should return the ICurrentUser', async () => { const { systemId, user, account, idToken } = setup(); - const result: CurrentUserInterface = await strategy.validate({ + const result: ICurrentUser = await strategy.validate({ body: { code: 'code', redirectUri: 'redirectUri', systemId }, }); diff --git a/apps/server/src/modules/authentication/strategy/oauth2.strategy.ts b/apps/server/src/modules/authentication/strategy/oauth2.strategy.ts index a8dc3517dbc..320387a7d00 100644 --- a/apps/server/src/modules/authentication/strategy/oauth2.strategy.ts +++ b/apps/server/src/modules/authentication/strategy/oauth2.strategy.ts @@ -6,7 +6,7 @@ import { PassportStrategy } from '@nestjs/passport'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { Strategy } from 'passport-custom'; import { Oauth2AuthorizationBodyParams } from '../controllers/dto'; -import { CurrentUserInterface, OauthCurrentUser } from '../interface'; +import { ICurrentUser, OauthCurrentUser } from '../interface'; import { SchoolInMigrationLoggableException } from '../loggable'; import { CurrentUserMapper } from '../mapper'; @@ -16,7 +16,7 @@ export class Oauth2Strategy extends PassportStrategy(Strategy, 'oauth2') { super(); } - async validate(request: { body: Oauth2AuthorizationBodyParams }): Promise { + async validate(request: { body: Oauth2AuthorizationBodyParams }): Promise { const { systemId, redirectUri, code } = request.body; const tokenDto: OAuthTokenDto = await this.oauthService.authenticateUser(systemId, redirectUri, code); diff --git a/apps/server/src/modules/authentication/uc/login.uc.ts b/apps/server/src/modules/authentication/uc/login.uc.ts index fbb50f6a693..2a6404b0a87 100644 --- a/apps/server/src/modules/authentication/uc/login.uc.ts +++ b/apps/server/src/modules/authentication/uc/login.uc.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { CurrentUserInterface } from '../interface'; +import { ICurrentUser } from '../interface'; import { CreateJwtPayload } from '../interface/jwt-payload'; import { CurrentUserMapper } from '../mapper'; import { AuthenticationService } from '../services/authentication.service'; @@ -9,7 +9,7 @@ import { LoginDto } from './dto'; export class LoginUc { constructor(private readonly authService: AuthenticationService) {} - async getLoginData(userInfo: CurrentUserInterface): Promise { + async getLoginData(userInfo: ICurrentUser): Promise { const createJwtPayload: CreateJwtPayload = CurrentUserMapper.mapCurrentUserToCreateJwtPayload(userInfo); const accessTokenDto: LoginDto = await this.authService.generateJwt(createJwtPayload); diff --git a/apps/server/src/modules/board/controller/api-test/board-delete.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-delete.api.spec.ts index 9875001374b..5d7633e4c99 100644 --- a/apps/server/src/modules/board/controller/api-test/board-delete.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-delete.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -43,7 +43,7 @@ class API { describe(`board delete (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/board-lookup.api.spec.ts b/apps/server/src/modules/board/controller/api-test/board-lookup.api.spec.ts index 33ada0e8a18..c4f685b9a6a 100644 --- a/apps/server/src/modules/board/controller/api-test/board-lookup.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/board-lookup.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -44,7 +44,7 @@ class API { describe(`board lookup (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/card-create.api.spec.ts b/apps/server/src/modules/board/controller/api-test/card-create.api.spec.ts index c7b12b8e48a..de006926e8f 100644 --- a/apps/server/src/modules/board/controller/api-test/card-create.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/card-create.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -44,7 +44,7 @@ class API { describe(`card create (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/card-delete.api.spec.ts b/apps/server/src/modules/board/controller/api-test/card-delete.api.spec.ts index 8b21a8b0004..d2b9a02efda 100644 --- a/apps/server/src/modules/board/controller/api-test/card-delete.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/card-delete.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -43,7 +43,7 @@ class API { describe(`card delete (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/card-lookup.api.spec.ts b/apps/server/src/modules/board/controller/api-test/card-lookup.api.spec.ts index cb7dce16180..f43fb954e68 100644 --- a/apps/server/src/modules/board/controller/api-test/card-lookup.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/card-lookup.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -48,7 +48,7 @@ class API { describe(`card lookup (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/card-move.api.spec.ts b/apps/server/src/modules/board/controller/api-test/card-move.api.spec.ts index ef35c254025..fa67220072a 100644 --- a/apps/server/src/modules/board/controller/api-test/card-move.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/card-move.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -43,7 +43,7 @@ class API { describe(`card move (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/column-create.api.spec.ts b/apps/server/src/modules/board/controller/api-test/column-create.api.spec.ts index b0dfc362af9..dd63155d4a5 100644 --- a/apps/server/src/modules/board/controller/api-test/column-create.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/column-create.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -42,7 +42,7 @@ class API { describe(`board create (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/column-delete.api.spec.ts b/apps/server/src/modules/board/controller/api-test/column-delete.api.spec.ts index 0d978999022..8b7dc463f98 100644 --- a/apps/server/src/modules/board/controller/api-test/column-delete.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/column-delete.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -42,7 +42,7 @@ class API { describe(`column delete (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/column-move.api.spec.ts b/apps/server/src/modules/board/controller/api-test/column-move.api.spec.ts index 46df08c17af..f467646766a 100644 --- a/apps/server/src/modules/board/controller/api-test/column-move.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/column-move.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -43,7 +43,7 @@ class API { describe(`column move (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/content-element-delete.api.spec.ts b/apps/server/src/modules/board/controller/api-test/content-element-delete.api.spec.ts index 1ee2538781e..b19aa8ff11c 100644 --- a/apps/server/src/modules/board/controller/api-test/content-element-delete.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/content-element-delete.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -43,7 +43,7 @@ class API { describe(`content element delete (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/api-test/content-element-move.api.spec.ts b/apps/server/src/modules/board/controller/api-test/content-element-move.api.spec.ts index ef6d43e422e..f913a547f59 100644 --- a/apps/server/src/modules/board/controller/api-test/content-element-move.api.spec.ts +++ b/apps/server/src/modules/board/controller/api-test/content-element-move.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -44,7 +44,7 @@ class API { describe(`content element move (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/board/controller/board-submission.controller.ts b/apps/server/src/modules/board/controller/board-submission.controller.ts index c575dc75404..bc6f7298668 100644 --- a/apps/server/src/modules/board/controller/board-submission.controller.ts +++ b/apps/server/src/modules/board/controller/board-submission.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, @@ -42,7 +42,7 @@ export class BoardSubmissionController { @ApiResponse({ status: 403, type: ForbiddenException }) @Get(':submissionContainerId') async getSubmissionItems( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: SubmissionContainerUrlParams ): Promise { const { submissionItems, users } = await this.submissionItemUc.findSubmissionItems( @@ -63,7 +63,7 @@ export class BoardSubmissionController { @HttpCode(204) @Patch(':submissionItemId') async updateSubmissionItem( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: SubmissionItemUrlParams, @Body() bodyParams: UpdateSubmissionItemBodyParams ) { @@ -89,7 +89,7 @@ export class BoardSubmissionController { async createElement( @Param() urlParams: SubmissionItemUrlParams, @Body() bodyParams: CreateContentElementBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const { type } = bodyParams; const element = await this.submissionItemUc.createElement(currentUser.userId, urlParams.submissionItemId, type); diff --git a/apps/server/src/modules/board/controller/board.controller.ts b/apps/server/src/modules/board/controller/board.controller.ts index 82bea1bccb0..55a54e8f77b 100644 --- a/apps/server/src/modules/board/controller/board.controller.ts +++ b/apps/server/src/modules/board/controller/board.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, @@ -32,7 +32,7 @@ export class BoardController { @Get(':boardId') async getBoardSkeleton( @Param() urlParams: BoardUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const board = await this.boardUc.findBoard(currentUser.userId, urlParams.boardId); @@ -49,7 +49,7 @@ export class BoardController { @Get(':boardId/context') async getBoardContext( @Param() urlParams: BoardUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const boardContext = await this.boardUc.findBoardContext(currentUser.userId, urlParams.boardId); @@ -68,7 +68,7 @@ export class BoardController { async updateBoardTitle( @Param() urlParams: BoardUrlParams, @Body() bodyParams: RenameBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.boardUc.updateBoardTitle(currentUser.userId, urlParams.boardId, bodyParams.title); } @@ -80,10 +80,7 @@ export class BoardController { @ApiResponse({ status: 404, type: NotFoundException }) @HttpCode(204) @Delete(':boardId') - async deleteBoard( - @Param() urlParams: BoardUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async deleteBoard(@Param() urlParams: BoardUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { await this.boardUc.deleteBoard(currentUser.userId, urlParams.boardId); } @@ -95,7 +92,7 @@ export class BoardController { @Post(':boardId/columns') async createColumn( @Param() urlParams: BoardUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const column = await this.boardUc.createColumn(currentUser.userId, urlParams.boardId); diff --git a/apps/server/src/modules/board/controller/card.controller.ts b/apps/server/src/modules/board/controller/card.controller.ts index 573405d7c7a..71a6d2ab0f9 100644 --- a/apps/server/src/modules/board/controller/card.controller.ts +++ b/apps/server/src/modules/board/controller/card.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, @@ -45,7 +45,7 @@ export class CardController { @ApiResponse({ status: 403, type: ForbiddenException }) @Get() async getCards( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() cardIdParams: CardIdsParams ): Promise { const cardIds = Array.isArray(cardIdParams.ids) ? cardIdParams.ids : [cardIdParams.ids]; @@ -68,7 +68,7 @@ export class CardController { async moveCard( @Param() urlParams: CardUrlParams, @Body() bodyParams: MoveCardBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.columnUc.moveCard(currentUser.userId, urlParams.cardId, bodyParams.toColumnId, bodyParams.toPosition); } @@ -83,7 +83,7 @@ export class CardController { async updateCardHeight( @Param() urlParams: CardUrlParams, @Body() bodyParams: SetHeightBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.cardUc.updateCardHeight(currentUser.userId, urlParams.cardId, bodyParams.height); } @@ -98,7 +98,7 @@ export class CardController { async updateCardTitle( @Param() urlParams: CardUrlParams, @Body() bodyParams: RenameBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.cardUc.updateCardTitle(currentUser.userId, urlParams.cardId, bodyParams.title); } @@ -110,7 +110,7 @@ export class CardController { @ApiResponse({ status: 404, type: NotFoundException }) @HttpCode(204) @Delete(':cardId') - async deleteCard(@Param() urlParams: CardUrlParams, @CurrentUser() currentUser: CurrentUserInterface): Promise { + async deleteCard(@Param() urlParams: CardUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { await this.cardUc.deleteCard(currentUser.userId, urlParams.cardId); } @@ -141,7 +141,7 @@ export class CardController { async createElement( @Param() urlParams: CardUrlParams, @Body() bodyParams: CreateContentElementBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const { type, toPosition } = bodyParams; const element = await this.cardUc.createElement(currentUser.userId, urlParams.cardId, type, toPosition); diff --git a/apps/server/src/modules/board/controller/column.controller.ts b/apps/server/src/modules/board/controller/column.controller.ts index 09cd7c5e61a..9a3da989159 100644 --- a/apps/server/src/modules/board/controller/column.controller.ts +++ b/apps/server/src/modules/board/controller/column.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, @@ -34,7 +34,7 @@ export class ColumnController { async moveColumn( @Param() urlParams: ColumnUrlParams, @Body() bodyParams: MoveColumnBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.boardUc.moveColumn(currentUser.userId, urlParams.columnId, bodyParams.toBoardId, bodyParams.toPosition); } @@ -49,7 +49,7 @@ export class ColumnController { async updateColumnTitle( @Param() urlParams: ColumnUrlParams, @Body() bodyParams: RenameBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.columnUc.updateColumnTitle(currentUser.userId, urlParams.columnId, bodyParams.title); } @@ -61,10 +61,7 @@ export class ColumnController { @ApiResponse({ status: 404, type: NotFoundException }) @HttpCode(204) @Delete(':columnId') - async deleteColumn( - @Param() urlParams: ColumnUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async deleteColumn(@Param() urlParams: ColumnUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { await this.columnUc.deleteColumn(currentUser.userId, urlParams.columnId); } @@ -77,7 +74,7 @@ export class ColumnController { @Post(':columnId/cards') async createCard( @Param() urlParams: ColumnUrlParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() createCardBodyParams?: CreateCardBodyParams ): Promise { const { requiredEmptyElements } = createCardBodyParams || {}; diff --git a/apps/server/src/modules/board/controller/element.controller.ts b/apps/server/src/modules/board/controller/element.controller.ts index 8c62ebbf493..71ade95db66 100644 --- a/apps/server/src/modules/board/controller/element.controller.ts +++ b/apps/server/src/modules/board/controller/element.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, @@ -51,7 +51,7 @@ export class ElementController { async moveElement( @Param() urlParams: ContentElementUrlParams, @Body() bodyParams: MoveContentElementBody, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.cardUc.moveElement( currentUser.userId, @@ -89,7 +89,7 @@ export class ElementController { async updateElement( @Param() urlParams: ContentElementUrlParams, @Body() bodyParams: UpdateElementContentBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const element = await this.elementUc.updateElementContent( currentUser.userId, @@ -109,7 +109,7 @@ export class ElementController { @Delete(':contentElementId') async deleteElement( @Param() urlParams: ContentElementUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.elementUc.deleteElement(currentUser.userId, urlParams.contentElementId); } @@ -125,7 +125,7 @@ export class ElementController { async createSubmissionItem( @Param() urlParams: ContentElementUrlParams, @Body() bodyParams: CreateSubmissionItemBodyParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const submissionItem = await this.elementUc.createSubmissionItem( currentUser.userId, diff --git a/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.spec.ts b/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.spec.ts index 92cfb9042d2..77b958f9c7a 100644 --- a/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.spec.ts +++ b/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.spec.ts @@ -1,5 +1,5 @@ import { createMock } from '@golevelup/ts-jest'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { CollaborativeStorageController } from '@modules/collaborative-storage/controller/collaborative-storage.controller'; import { CollaborativeStorageUc } from '@modules/collaborative-storage/uc/collaborative-storage.uc'; import { Test, TestingModule } from '@nestjs/testing'; @@ -29,7 +29,7 @@ describe('CollaborativeStorage Controller', () => { describe('Update TeamPermissions For Role', () => { it('should call the UC', async () => { await controller.updateTeamPermissionsForRole( - { userId: 'userId' } as CurrentUserInterface, + { userId: 'userId' } as ICurrentUser, { teamId: 'testTeam', roleId: 'testRole' }, { read: false, write: false, create: false, delete: false, share: false } ); diff --git a/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.ts b/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.ts index 81f2152b352..4e11b3c46bd 100644 --- a/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.ts +++ b/apps/server/src/modules/collaborative-storage/controller/collaborative-storage.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Param, Patch } from '@nestjs/common'; import { ApiResponse, ApiTags } from '@nestjs/swagger'; import { LegacyLogger } from '@src/core/logger'; @@ -30,7 +30,7 @@ export class CollaborativeStorageController { @ApiResponse({ status: 403, description: 'User does not have the correct permission' }) @ApiResponse({ status: 404, description: 'Team or Role not found!' }) updateTeamPermissionsForRole( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() teamRole: TeamRoleDto, @Body() permissionsBody: TeamPermissionsBody ): Promise { diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts index d449cb5f4b3..4694b1817ac 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts @@ -1,6 +1,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -48,7 +48,7 @@ class API { describe(`${baseRouteName} (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let validId: string; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts index 6bf8d5f4fb8..1711acba050 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts @@ -2,7 +2,7 @@ import { createMock } from '@golevelup/ts-jest'; import { AntivirusService } from '@infra/antivirus'; import { S3ClientAdapter } from '@infra/s3-client'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -85,7 +85,7 @@ class API { describe(`${baseRouteName} (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts index 638f6634b07..ea85d9b656b 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts @@ -2,7 +2,7 @@ import { createMock } from '@golevelup/ts-jest'; import { AntivirusService } from '@infra/antivirus'; import { S3ClientAdapter } from '@infra/s3-client'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -84,7 +84,7 @@ class API { describe(`${baseRouteName} (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts index ed272ef5d0b..8d8e7dbf912 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts @@ -2,7 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { AntivirusService } from '@infra/antivirus'; import { S3ClientAdapter } from '@infra/s3-client'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -93,7 +93,7 @@ describe('files-storage controller (API)', () => { let app: INestApplication; let em: EntityManager; let s3ClientAdapter: DeepMocked; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let validId: EntityId; let appPort: number; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts index 65b8c285af7..35410d712c8 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts @@ -1,6 +1,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -48,7 +48,7 @@ class API { describe(`${baseRouteName} (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let validId: string; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts index 609d6f62dec..6ccc6d0d5ea 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts @@ -3,7 +3,7 @@ import { AntivirusService } from '@infra/antivirus'; import { PreviewProducer } from '@infra/preview-generator'; import { S3ClientAdapter } from '@infra/s3-client'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication, NotFoundException, StreamableFile } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -104,7 +104,7 @@ describe('File Controller (API) - preview', () => { let em: EntityManager; let s3ClientAdapter: DeepMocked; let antivirusService: DeepMocked; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let schoolId: EntityId; let appPort: number; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts index bada5cf5723..fb1dfa866eb 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts @@ -1,6 +1,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -47,7 +47,7 @@ class API { describe(`${baseRouteName} (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let fileRecord: FileRecord; let fileRecords: FileRecord[]; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts index d3efedf02e9..7f56152f7da 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts @@ -2,7 +2,7 @@ import { createMock } from '@golevelup/ts-jest'; import { AntivirusService } from '@infra/antivirus'; import { S3ClientAdapter } from '@infra/s3-client'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -109,7 +109,7 @@ class API { describe(`${baseRouteName} (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/files-storage/controller/files-storage.controller.ts b/apps/server/src/modules/files-storage/controller/files-storage.controller.ts index 22926c2d01a..7269336c44c 100644 --- a/apps/server/src/modules/files-storage/controller/files-storage.controller.ts +++ b/apps/server/src/modules/files-storage/controller/files-storage.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { BadRequestException, Body, @@ -63,7 +63,7 @@ export class FilesStorageController { async uploadFromUrl( @Body() body: FileUrlParams, @Param() params: FileRecordParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const fileRecord = await this.filesStorageUC.uploadFromUrl(currentUser.userId, { ...body, ...params }); @@ -83,7 +83,7 @@ export class FilesStorageController { async upload( @Body() _: FileParams, @Param() params: FileRecordParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Req() req: Request ): Promise { const fileRecord = await this.filesStorageUC.upload(currentUser.userId, params, req); @@ -105,7 +105,7 @@ export class FilesStorageController { @Get('/download/:fileRecordId/:fileName') async download( @Param() params: DownloadFileParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Req() req: Request, @Res({ passthrough: true }) response: Response, @Headers('Range') bytesRange?: string @@ -131,7 +131,7 @@ export class FilesStorageController { @RequestTimeout(config().INCOMING_REQUEST_TIMEOUT) async downloadPreview( @Param() params: DownloadFileParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() previewParams: PreviewParams, @Req() req: Request, @Res({ passthrough: true }) response: Response, @@ -192,7 +192,7 @@ export class FilesStorageController { @Get('/list/:schoolId/:parentType/:parentId') async list( @Param() params: FileRecordParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() pagination: PaginationParams ): Promise { const [fileRecords, total] = await this.filesStorageUC.getFileRecordsOfParent(currentUser.userId, params); @@ -217,7 +217,7 @@ export class FilesStorageController { async patchFilename( @Param() params: SingleFileParams, @Body() renameFileParam: RenameFileParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const fileRecord = await this.filesStorageUC.patchFilename(currentUser.userId, params, renameFileParam); @@ -238,7 +238,7 @@ export class FilesStorageController { @UseInterceptors(RequestLoggingInterceptor) async deleteByParent( @Param() params: FileRecordParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const [fileRecords, total] = await this.filesStorageUC.deleteFilesOfParent(currentUser.userId, params); const response = FileRecordMapper.mapToFileRecordListResponse(fileRecords, total); @@ -255,7 +255,7 @@ export class FilesStorageController { @UseInterceptors(RequestLoggingInterceptor) async deleteFile( @Param() params: SingleFileParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const fileRecord = await this.filesStorageUC.deleteOneFile(currentUser.userId, params); @@ -271,7 +271,7 @@ export class FilesStorageController { @Post('/restore/:schoolId/:parentType/:parentId') async restore( @Param() params: FileRecordParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const [fileRecords, total] = await this.filesStorageUC.restoreFilesOfParent(currentUser.userId, params); @@ -287,7 +287,7 @@ export class FilesStorageController { @Post('/restore/:fileRecordId') async restoreFile( @Param() params: SingleFileParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const fileRecord = await this.filesStorageUC.restoreOneFile(currentUser.userId, params); @@ -305,7 +305,7 @@ export class FilesStorageController { async copy( @Param() params: FileRecordParams, @Body() copyFilesParam: CopyFilesOfParentParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const [response, count] = await this.filesStorageUC.copyFilesOfParent(currentUser.userId, params, copyFilesParam); @@ -322,7 +322,7 @@ export class FilesStorageController { async copyFile( @Param() params: SingleFileParams, @Body() copyFileParam: CopyFileParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const response = await this.filesStorageUC.copyOneFile(currentUser.userId, params, copyFileParam); diff --git a/apps/server/src/modules/group/controller/group.controller.ts b/apps/server/src/modules/group/controller/group.controller.ts index 4aba6ad39cf..2ae47b54552 100644 --- a/apps/server/src/modules/group/controller/group.controller.ts +++ b/apps/server/src/modules/group/controller/group.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, HttpStatus, Param, Query } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { PaginationParams } from '@shared/controller'; @@ -24,7 +24,7 @@ export class GroupController { @Query() pagination: PaginationParams, @Query() sortingQuery: ClassSortParams, @Query() filterParams: ClassFilterParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const board: Page = await this.groupUc.findAllClasses( currentUser.userId, @@ -51,7 +51,7 @@ export class GroupController { @ApiResponse({ status: '4XX', type: ErrorResponse }) @ApiResponse({ status: '5XX', type: ErrorResponse }) public async getGroup( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: GroupIdParams ): Promise { const group: ResolvedGroupDto = await this.groupUc.getGroup(currentUser.userId, params.groupId); diff --git a/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-delete.api.spec.ts b/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-delete.api.spec.ts index 0306a5ee710..ff093b2c712 100644 --- a/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-delete.api.spec.ts +++ b/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-delete.api.spec.ts @@ -5,7 +5,7 @@ import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { Permission } from '@shared/domain'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard'; import { Request } from 'express'; import request from 'supertest'; @@ -35,7 +35,7 @@ describe('H5PEditor Controller (api)', () => { let app: INestApplication; let api: API; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let h5PEditorUc: DeepMocked; beforeAll(async () => { diff --git a/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-editor.api.spec.ts b/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-editor.api.spec.ts index 51fd9bb90f3..c22c7394fab 100644 --- a/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-editor.api.spec.ts +++ b/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-editor.api.spec.ts @@ -5,7 +5,7 @@ import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { Permission } from '@shared/domain'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard'; import { Request } from 'express'; import request from 'supertest'; @@ -53,7 +53,7 @@ describe('H5PEditor Controller (api)', () => { let app: INestApplication; let api: API; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let h5PEditorUc: DeepMocked; beforeAll(async () => { diff --git a/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-player.api.spec.ts b/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-player.api.spec.ts index 19a2002503d..cb5a3d487eb 100644 --- a/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-player.api.spec.ts +++ b/apps/server/src/modules/h5p-editor/controller/api-test/h5p-editor-get-player.api.spec.ts @@ -6,7 +6,7 @@ import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { Permission } from '@shared/domain'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard'; import { Request } from 'express'; import request from 'supertest'; @@ -45,7 +45,7 @@ describe('H5PEditor Controller (api)', () => { let app: INestApplication; let api: API; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let h5PEditorUc: DeepMocked; beforeAll(async () => { diff --git a/apps/server/src/modules/h5p-editor/controller/h5p-editor.controller.ts b/apps/server/src/modules/h5p-editor/controller/h5p-editor.controller.ts index 7271ff6c551..c46c782da2d 100644 --- a/apps/server/src/modules/h5p-editor/controller/h5p-editor.controller.ts +++ b/apps/server/src/modules/h5p-editor/controller/h5p-editor.controller.ts @@ -1,4 +1,4 @@ -import { CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { CurrentUser, ICurrentUser } from '@modules/authentication'; import { Authenticate } from '@modules/authentication/decorator/auth.decorator'; import { BadRequestException, @@ -51,7 +51,7 @@ export class H5PEditorController { @ApiResponse({ status: 403, type: ForbiddenException }) @ApiResponse({ status: 500, type: InternalServerErrorException }) @Get('/play/:contentId') - async getPlayer(@CurrentUser() currentUser: CurrentUserInterface, @Param() params: GetH5PContentParams) { + async getPlayer(@CurrentUser() currentUser: ICurrentUser, @Param() params: GetH5PContentParams) { return this.h5pEditorUc.getH5pPlayer(currentUser, params.contentId); } @@ -73,7 +73,7 @@ export class H5PEditorController { } @Get('params/:id') - async getContentParameters(@Param('id') id: string, @CurrentUser() currentUser: CurrentUserInterface) { + async getContentParameters(@Param('id') id: string, @CurrentUser() currentUser: ICurrentUser) { const content = await this.h5pEditorUc.getContentParameters(id, currentUser); return content; @@ -84,7 +84,7 @@ export class H5PEditorController { @Param() params: ContentFileUrlParams, @Req() req: Request, @Res({ passthrough: true }) res: Response, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ) { const { data, contentType, contentLength, contentRange } = await this.h5pEditorUc.getContentFile( params.id, @@ -102,7 +102,7 @@ export class H5PEditorController { @Get('temp-files/:file(*)') async getTemporaryFile( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param('file') file: string, @Req() req: Request, @Res({ passthrough: true }) res: Response @@ -121,7 +121,7 @@ export class H5PEditorController { } @Get('ajax') - async getAjax(@Query() query: AjaxGetQueryParams, @CurrentUser() currentUser: CurrentUserInterface) { + async getAjax(@Query() query: AjaxGetQueryParams, @CurrentUser() currentUser: ICurrentUser) { const response = this.h5pEditorUc.getAjax(query, currentUser); return response; @@ -137,7 +137,7 @@ export class H5PEditorController { async postAjax( @Body(AjaxPostBodyParamsTransformPipe) body: AjaxPostBodyParams, @Query() query: AjaxPostQueryParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @UploadedFiles() files?: { file?: Express.Multer.File[]; h5p?: Express.Multer.File[] } ) { const contentFile = files?.file?.[0]; @@ -151,7 +151,7 @@ export class H5PEditorController { @Post('/delete/:contentId') async deleteH5pContent( @Param() params: GetH5PContentParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const deleteSuccessfull = this.h5pEditorUc.deleteH5pContent(currentUser, params.contentId); @@ -160,7 +160,7 @@ export class H5PEditorController { @Get('/edit/:language') @ApiResponse({ status: 200, type: H5PEditorModelResponse }) - async getNewH5PEditor(@Param() params: GetH5PEditorParamsCreate, @CurrentUser() currentUser: CurrentUserInterface) { + async getNewH5PEditor(@Param() params: GetH5PEditorParamsCreate, @CurrentUser() currentUser: ICurrentUser) { const editorModel = await this.h5pEditorUc.getEmptyH5pEditor(currentUser, params.language); return new H5PEditorModelResponse(editorModel); @@ -168,7 +168,7 @@ export class H5PEditorController { @Get('/edit/:contentId/:language') @ApiResponse({ status: 200, type: H5PEditorModelContentResponse }) - async getH5PEditor(@Param() params: GetH5PEditorParams, @CurrentUser() currentUser: CurrentUserInterface) { + async getH5PEditor(@Param() params: GetH5PEditorParams, @CurrentUser() currentUser: ICurrentUser) { const { editorModel, content } = await this.h5pEditorUc.getH5pEditor( currentUser, params.contentId, @@ -180,7 +180,7 @@ export class H5PEditorController { @Post('/edit') @ApiResponse({ status: 201, type: H5PSaveResponse }) - async createH5pContent(@Body() body: PostH5PContentCreateParams, @CurrentUser() currentUser: CurrentUserInterface) { + async createH5pContent(@Body() body: PostH5PContentCreateParams, @CurrentUser() currentUser: ICurrentUser) { const response = await this.h5pEditorUc.createH5pContentGetMetadata( currentUser, body.params.params, @@ -200,7 +200,7 @@ export class H5PEditorController { async saveH5pContent( @Body() body: PostH5PContentCreateParams, @Param() params: SaveH5PEditorParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ) { const response = await this.h5pEditorUc.saveH5pContentGetMetadata( params.contentId, diff --git a/apps/server/src/modules/h5p-editor/uc/h5p-delete.uc.spec.ts b/apps/server/src/modules/h5p-editor/uc/h5p-delete.uc.spec.ts index e6a67661761..040d5817f8a 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p-delete.uc.spec.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p-delete.uc.spec.ts @@ -3,7 +3,7 @@ import { H5PEditor, H5PPlayer } from '@lumieducation/h5p-server'; import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { h5pContentFactory, setupEntities } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContextBuilder, AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; import { H5PAjaxEndpointProvider } from '../provider'; @@ -14,7 +14,7 @@ import { H5PEditorUc } from './h5p.uc'; const createParams = () => { const content = h5pContentFactory.build(); - const mockCurrentUser: CurrentUserInterface = { + const mockCurrentUser: ICurrentUser = { accountId: 'mockAccountId', roles: ['student'], schoolId: 'mockSchoolId', diff --git a/apps/server/src/modules/h5p-editor/uc/h5p-files.uc.spec.ts b/apps/server/src/modules/h5p-editor/uc/h5p-files.uc.spec.ts index 01666e42ebe..c1c7987ace8 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p-files.uc.spec.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p-files.uc.spec.ts @@ -3,7 +3,7 @@ import { H5PAjaxEndpoint, H5PEditor, IPlayerModel } from '@lumieducation/h5p-ser import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { h5pContentFactory, setupEntities } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContextBuilder, AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; import { Request } from 'express'; @@ -17,7 +17,7 @@ import { H5PEditorUc } from './h5p.uc'; const createParams = () => { const content = h5pContentFactory.build(); - const mockCurrentUser: CurrentUserInterface = { + const mockCurrentUser: ICurrentUser = { accountId: 'mockAccountId', roles: ['student'], schoolId: 'mockSchoolId', diff --git a/apps/server/src/modules/h5p-editor/uc/h5p-get-editor.uc.spec.ts b/apps/server/src/modules/h5p-editor/uc/h5p-get-editor.uc.spec.ts index 02fdeebe80d..824b1f7de8a 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p-get-editor.uc.spec.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p-get-editor.uc.spec.ts @@ -5,7 +5,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { LanguageType } from '@shared/domain'; import { UserRepo } from '@shared/repo'; import { h5pContentFactory, setupEntities } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContextBuilder, AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; import { H5PAjaxEndpointProvider } from '../provider'; @@ -16,7 +16,7 @@ import { H5PEditorUc } from './h5p.uc'; const createParams = () => { const content = h5pContentFactory.build(); - const mockCurrentUser: CurrentUserInterface = { + const mockCurrentUser: ICurrentUser = { accountId: 'mockAccountId', roles: ['student'], schoolId: 'mockSchoolId', diff --git a/apps/server/src/modules/h5p-editor/uc/h5p-get-player.uc.spec.ts b/apps/server/src/modules/h5p-editor/uc/h5p-get-player.uc.spec.ts index e44ff01fc3d..c8648cb413c 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p-get-player.uc.spec.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p-get-player.uc.spec.ts @@ -3,7 +3,7 @@ import { H5PEditor, H5PPlayer, IPlayerModel } from '@lumieducation/h5p-server'; import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { h5pContentFactory, setupEntities } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContextBuilder, AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; import { H5PAjaxEndpointProvider } from '../provider'; @@ -14,7 +14,7 @@ import { H5PEditorUc } from './h5p.uc'; const createParams = () => { const content = h5pContentFactory.build(); - const mockCurrentUser: CurrentUserInterface = { + const mockCurrentUser: ICurrentUser = { accountId: 'mockAccountId', roles: ['student'], schoolId: 'mockSchoolId', diff --git a/apps/server/src/modules/h5p-editor/uc/h5p-save-create.uc.spec.ts b/apps/server/src/modules/h5p-editor/uc/h5p-save-create.uc.spec.ts index efac96eeefa..2fba57f5bc2 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p-save-create.uc.spec.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p-save-create.uc.spec.ts @@ -4,7 +4,7 @@ import { ObjectId } from '@mikro-orm/mongodb'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { h5pContentFactory, setupEntities } from '@shared/testing'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContextBuilder, AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; import { H5PContentParentType } from '../entity'; @@ -22,7 +22,7 @@ const createParams = () => { const contentId = new ObjectId().toHexString(); const parentId = new ObjectId().toHexString(); - const mockCurrentUser: CurrentUserInterface = { + const mockCurrentUser: ICurrentUser = { accountId: 'mockAccountId', roles: ['student'], schoolId: 'mockSchoolId', diff --git a/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts b/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts index 0bafba101f6..f456491509a 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts @@ -22,7 +22,7 @@ import { NotFoundException, } from '@nestjs/common'; import { EntityId, LanguageType } from '@shared/domain'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContext, AuthorizationContextBuilder } from '@src/modules/authorization'; import { AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; @@ -92,7 +92,7 @@ export class H5PEditorUc { public async getAjax( query: AjaxGetQueryParams, - currentUser: CurrentUserInterface + currentUser: ICurrentUser ): Promise { const user = this.changeUserType(currentUser); const language = await this.getUserLanguage(currentUser); @@ -116,7 +116,7 @@ export class H5PEditorUc { } public async postAjax( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, query: AjaxPostQueryParams, body: AjaxPostBodyParams, contentFile?: Express.Multer.File, @@ -167,7 +167,7 @@ export class H5PEditorUc { } } - public async getContentParameters(contentId: string, currentUser: CurrentUserInterface) { + public async getContentParameters(contentId: string, currentUser: ICurrentUser) { const { parentType, parentId } = await this.h5pContentRepo.findById(contentId); await this.checkContentPermission(currentUser.userId, parentType, parentId, AuthorizationContextBuilder.read([])); @@ -186,7 +186,7 @@ export class H5PEditorUc { contentId: string, file: string, req: Request, - currentUser: CurrentUserInterface + currentUser: ICurrentUser ): Promise { const { parentType, parentId } = await this.h5pContentRepo.findById(contentId); await this.checkContentPermission(currentUser.userId, parentType, parentId, AuthorizationContextBuilder.read([])); @@ -227,11 +227,7 @@ export class H5PEditorUc { } } - public async getTemporaryFile( - file: string, - req: Request, - currentUser: CurrentUserInterface - ): Promise { + public async getTemporaryFile(file: string, req: Request, currentUser: ICurrentUser): Promise { const user = this.changeUserType(currentUser); try { @@ -266,7 +262,7 @@ export class H5PEditorUc { } } - public async getH5pPlayer(currentUser: CurrentUserInterface, contentId: string): Promise { + public async getH5pPlayer(currentUser: ICurrentUser, contentId: string): Promise { const { parentType, parentId } = await this.h5pContentRepo.findById(contentId); await this.checkContentPermission(currentUser.userId, parentType, parentId, AuthorizationContextBuilder.read([])); @@ -277,7 +273,7 @@ export class H5PEditorUc { return playerModel; } - public async getEmptyH5pEditor(currentUser: CurrentUserInterface, language: LanguageType) { + public async getEmptyH5pEditor(currentUser: ICurrentUser, language: LanguageType) { const user = this.changeUserType(currentUser); const fakeUndefinedString = this.fakeUndefinedAsString(); @@ -291,7 +287,7 @@ export class H5PEditorUc { return createdH5PEditor; } - public async getH5pEditor(currentUser: CurrentUserInterface, contentId: string, language: LanguageType) { + public async getH5pEditor(currentUser: ICurrentUser, contentId: string, language: LanguageType) { const { parentType, parentId } = await this.h5pContentRepo.findById(contentId); await this.checkContentPermission(currentUser.userId, parentType, parentId, AuthorizationContextBuilder.write([])); @@ -308,7 +304,7 @@ export class H5PEditorUc { }; } - public async deleteH5pContent(currentUser: CurrentUserInterface, contentId: string): Promise { + public async deleteH5pContent(currentUser: ICurrentUser, contentId: string): Promise { const { parentType, parentId } = await this.h5pContentRepo.findById(contentId); await this.checkContentPermission(currentUser.userId, parentType, parentId, AuthorizationContextBuilder.write([])); @@ -328,7 +324,7 @@ export class H5PEditorUc { } public async createH5pContentGetMetadata( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, params: unknown, metadata: IContentMetadata, mainLibraryUbername: string, @@ -353,7 +349,7 @@ export class H5PEditorUc { public async saveH5pContentGetMetadata( contentId: string, - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, params: unknown, metadata: IContentMetadata, mainLibraryUbername: string, @@ -375,7 +371,7 @@ export class H5PEditorUc { return newContentId; } - private changeUserType(currentUser: CurrentUserInterface): LumiIUser { + private changeUserType(currentUser: ICurrentUser): LumiIUser { const user: LumiIUser = { canCreateRestricted: false, canInstallRecommended: true, @@ -390,7 +386,7 @@ export class H5PEditorUc { } private createAugmentedLumiUser( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, contentParentType: H5PContentParentType, contentParentId: EntityId ) { @@ -403,7 +399,7 @@ export class H5PEditorUc { return user; } - private async getUserLanguage(currentUser: CurrentUserInterface): Promise { + private async getUserLanguage(currentUser: ICurrentUser): Promise { const languageUser = await this.userService.findById(currentUser.userId); let userLanguage = LanguageType.DE; if (languageUser?.language) { diff --git a/apps/server/src/modules/learnroom/controller/api-test/dashboard.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/dashboard.api.spec.ts index e0b8476dde8..18a9cc28acf 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/dashboard.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/dashboard.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { DashboardResponse } from '@modules/learnroom/controller/dto'; import { ServerTestModule } from '@modules/server/server.module'; @@ -15,7 +15,7 @@ describe('Dashboard Controller (API)', () => { let app: INestApplication; let em: EntityManager; let dashboardRepo: DashboardRepoInterface; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ diff --git a/apps/server/src/modules/learnroom/controller/api-test/rooms-copy-timeout.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/rooms-copy-timeout.api.spec.ts index e76043d41de..c73b9861c1f 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/rooms-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/rooms-copy-timeout.api.spec.ts @@ -1,7 +1,7 @@ import { createMock } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { FilesStorageClientAdapterService } from '@modules/files-storage-client'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -30,7 +30,7 @@ import { ServerTestModule } from '@modules/server'; describe('Rooms copy (API)', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ diff --git a/apps/server/src/modules/learnroom/controller/api-test/rooms.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/rooms.api.spec.ts index 68fb3e5b3b9..ec6114f8f60 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/rooms.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/rooms.api.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { CopyApiResponse } from '@modules/copy-helper'; import { FilesStorageClientAdapterService } from '@modules/files-storage-client'; @@ -26,7 +26,7 @@ import request from 'supertest'; describe('Rooms Controller (API)', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let filesStorageClientAdapterService: DeepMocked; const setConfig = () => { diff --git a/apps/server/src/modules/learnroom/controller/course.controller.ts b/apps/server/src/modules/learnroom/controller/course.controller.ts index cebb03a864a..7f026002ea7 100644 --- a/apps/server/src/modules/learnroom/controller/course.controller.ts +++ b/apps/server/src/modules/learnroom/controller/course.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, NotFoundException, Param, Query, Res, StreamableFile } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ApiTags } from '@nestjs/swagger'; @@ -21,7 +21,7 @@ export class CourseController { @Get() async findForUser( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() pagination: PaginationParams ): Promise { const [courses, total] = await this.courseUc.findAllByUser(currentUser.userId, pagination); @@ -34,7 +34,7 @@ export class CourseController { @Get(':courseId/export') async exportCourse( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: CourseUrlParams, @Query() queryParams: CourseQueryParams, @Res({ passthrough: true }) response: Response diff --git a/apps/server/src/modules/learnroom/controller/dashboard.controller.spec.ts b/apps/server/src/modules/learnroom/controller/dashboard.controller.spec.ts index 9f12a182716..76ebe449829 100644 --- a/apps/server/src/modules/learnroom/controller/dashboard.controller.spec.ts +++ b/apps/server/src/modules/learnroom/controller/dashboard.controller.spec.ts @@ -1,4 +1,4 @@ -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { Test, TestingModule } from '@nestjs/testing'; import { DashboardEntity, @@ -65,7 +65,7 @@ describe('dashboard uc', () => { const dashboard = new DashboardEntity('someid', { grid: [], userId: 'userId' }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const response = await controller.findForUser(currentUser); expect(response instanceof DashboardResponse).toEqual(true); @@ -76,7 +76,7 @@ describe('dashboard uc', () => { const dashboard = new DashboardEntity('someid', { grid: [], userId: 'userId' }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const response = await controller.findForUser(currentUser); expect(response instanceof DashboardResponse).toEqual(true); @@ -98,7 +98,7 @@ describe('dashboard uc', () => { }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const response = await controller.findForUser(currentUser); expect(response instanceof DashboardResponse).toEqual(true); @@ -110,7 +110,7 @@ describe('dashboard uc', () => { const dashboard = new DashboardEntity('someid', { grid: [], userId: 'userId' }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; await controller.findForUser(currentUser); expect(spy).toHaveBeenCalledWith('userId'); @@ -133,7 +133,7 @@ describe('dashboard uc', () => { }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; await controller.moveElement( { dashboardId: 'dashboardId' }, { from: { x: 1, y: 2 }, to: { x: 2, y: 1 } }, @@ -157,7 +157,7 @@ describe('dashboard uc', () => { }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const response = await controller.moveElement( { dashboardId: 'dashboardId' }, { @@ -189,7 +189,7 @@ describe('dashboard uc', () => { }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; await controller.patchGroup({ dashboardId: 'dashboardId' }, 3, 4, { title: 'groupTitle' }, currentUser); expect(spy).toHaveBeenCalledWith('dashboardId', { x: 3, y: 4 }, 'groupTitle', currentUser.userId); }); @@ -212,7 +212,7 @@ describe('dashboard uc', () => { }); return Promise.resolve(dashboard); }); - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const response = await controller.patchGroup( { dashboardId: 'dashboardId' }, 3, diff --git a/apps/server/src/modules/learnroom/controller/dashboard.controller.ts b/apps/server/src/modules/learnroom/controller/dashboard.controller.ts index 1559be97f59..c2c2ff6d9ee 100644 --- a/apps/server/src/modules/learnroom/controller/dashboard.controller.ts +++ b/apps/server/src/modules/learnroom/controller/dashboard.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Get, Param, Patch, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { DashboardMapper } from '../mapper/dashboard.mapper'; @@ -12,7 +12,7 @@ export class DashboardController { constructor(private readonly dashboardUc: DashboardUc) {} @Get() - async findForUser(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async findForUser(@CurrentUser() currentUser: ICurrentUser): Promise { const dashboard = await this.dashboardUc.getUsersDashboard(currentUser.userId); const dto = DashboardMapper.mapToResponse(dashboard); return dto; @@ -22,7 +22,7 @@ export class DashboardController { async moveElement( @Param() { dashboardId }: DashboardUrlParams, @Body() params: MoveElementParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const dashboard = await this.dashboardUc.moveElementOnDashboard( dashboardId, @@ -40,7 +40,7 @@ export class DashboardController { @Query('x') x: number, @Query('y') y: number, @Body() params: PatchGroupParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const dashboard = await this.dashboardUc.renameGroupOnDashboard( urlParams.dashboardId, diff --git a/apps/server/src/modules/learnroom/controller/rooms.controller.spec.ts b/apps/server/src/modules/learnroom/controller/rooms.controller.spec.ts index c87462f3b2f..4e10bd706a3 100644 --- a/apps/server/src/modules/learnroom/controller/rooms.controller.spec.ts +++ b/apps/server/src/modules/learnroom/controller/rooms.controller.spec.ts @@ -1,5 +1,5 @@ import { createMock } from '@golevelup/ts-jest'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { CopyApiResponse, CopyElementType, CopyStatus, CopyStatusEnum } from '@modules/copy-helper'; import { Test, TestingModule } from '@nestjs/testing'; import { EntityId } from '@shared/domain'; @@ -73,7 +73,7 @@ describe('rooms controller', () => { describe('getRoomBoard', () => { describe('when simple room is fetched', () => { const setup = () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const ucResult = { roomId: 'id', @@ -123,7 +123,7 @@ describe('rooms controller', () => { describe('patchVisibility', () => { it('should call uc', async () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const ucSpy = jest.spyOn(uc, 'updateVisibilityOfBoardElement').mockImplementation(() => Promise.resolve()); await controller.patchElementVisibility( { roomId: 'roomid', elementId: 'elementId' }, @@ -136,7 +136,7 @@ describe('rooms controller', () => { describe('patchOrder', () => { it('should call uc', async () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const ucSpy = jest.spyOn(uc, 'reorderBoardElements').mockImplementation(() => Promise.resolve()); await controller.patchOrderingOfElements({ roomId: 'roomid' }, { elements: ['id', 'id', 'id'] }, currentUser); expect(ucSpy).toHaveBeenCalledWith('roomid', 'userId', ['id', 'id', 'id']); @@ -146,7 +146,7 @@ describe('rooms controller', () => { describe('copyCourse', () => { describe('when course should be copied via API call', () => { const setup = () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const ucResult = { title: 'example title', type: 'COURSE' as CopyElementType, @@ -175,7 +175,7 @@ describe('rooms controller', () => { describe('copyLesson', () => { describe('when lesson should be copied via API call', () => { const setup = () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const ucResult = { title: 'example title', type: 'LESSON' as CopyElementType, diff --git a/apps/server/src/modules/learnroom/controller/rooms.controller.ts b/apps/server/src/modules/learnroom/controller/rooms.controller.ts index 24a3dabc34d..c81b40d6bba 100644 --- a/apps/server/src/modules/learnroom/controller/rooms.controller.ts +++ b/apps/server/src/modules/learnroom/controller/rooms.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { CopyApiResponse, CopyMapper } from '@modules/copy-helper'; import { serverConfig } from '@modules/server/server.config'; import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'; @@ -32,7 +32,7 @@ export class RoomsController { @Get(':roomId/board') async getRoomBoard( @Param() urlParams: RoomUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const board = await this.roomsUc.getBoard(urlParams.roomId, currentUser.userId); const mapped = this.mapper.mapToResponse(board); @@ -43,7 +43,7 @@ export class RoomsController { async patchElementVisibility( @Param() urlParams: RoomElementUrlParams, @Body() params: PatchVisibilityParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.roomsUc.updateVisibilityOfBoardElement( urlParams.roomId, @@ -57,7 +57,7 @@ export class RoomsController { async patchOrderingOfElements( @Param() urlParams: RoomUrlParams, @Body() params: PatchOrderParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { await this.roomsUc.reorderBoardElements(urlParams.roomId, currentUser.userId, params.elements); } @@ -65,7 +65,7 @@ export class RoomsController { @Post(':roomId/copy') @RequestTimeout(serverConfig().INCOMING_REQUEST_TIMEOUT_COPY_API) async copyCourse( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: RoomUrlParams ): Promise { const copyStatus = await this.courseCopyUc.copyCourse(currentUser.userId, urlParams.roomId); @@ -76,7 +76,7 @@ export class RoomsController { @Post('lessons/:lessonId/copy') @RequestTimeout(serverConfig().INCOMING_REQUEST_TIMEOUT_COPY_API) async copyLesson( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: LessonUrlParams, @Body() params: LessonCopyApiParams ): Promise { diff --git a/apps/server/src/modules/lesson/controller/lesson.controller.ts b/apps/server/src/modules/lesson/controller/lesson.controller.ts index edd926642e0..66e52b06478 100644 --- a/apps/server/src/modules/lesson/controller/lesson.controller.ts +++ b/apps/server/src/modules/lesson/controller/lesson.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Delete, Param } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { LessonUC } from '../uc'; @@ -11,10 +11,7 @@ export class LessonController { constructor(private readonly lessonUC: LessonUC) {} @Delete(':lessonId') - async delete( - @Param() urlParams: LessonUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async delete(@Param() urlParams: LessonUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const result = await this.lessonUC.delete(currentUser.userId, urlParams.lessonId); return result; diff --git a/apps/server/src/modules/meta-tag-extractor/controller/meta-tag-extractor.controller.ts b/apps/server/src/modules/meta-tag-extractor/controller/meta-tag-extractor.controller.ts index 146513d1e38..8133c4c0b83 100644 --- a/apps/server/src/modules/meta-tag-extractor/controller/meta-tag-extractor.controller.ts +++ b/apps/server/src/modules/meta-tag-extractor/controller/meta-tag-extractor.controller.ts @@ -1,6 +1,6 @@ import { Body, Controller, InternalServerErrorException, Post, UnauthorizedException } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { CurrentUserInterface } from '@src/modules/authentication'; +import { ICurrentUser } from '@src/modules/authentication'; import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator'; import { MetaTagExtractorUc } from '../uc'; import { MetaTagExtractorResponse } from './dto'; @@ -18,7 +18,7 @@ export class MetaTagExtractorController { @ApiResponse({ status: 500, type: InternalServerErrorException }) @Post('') async getData( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() bodyParams: GetMetaTagDataBody ): Promise { const result = await this.metaTagExtractorUc.fetchMetaData(currentUser.userId, bodyParams.url); diff --git a/apps/server/src/modules/news/controller/news.controller.ts b/apps/server/src/modules/news/controller/news.controller.ts index dfad2718345..c2cf6ba4e98 100644 --- a/apps/server/src/modules/news/controller/news.controller.ts +++ b/apps/server/src/modules/news/controller/news.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { PaginationParams } from '@shared/controller'; @@ -23,10 +23,7 @@ export class NewsController { * Create a news by a user in a given scope (school or team). */ @Post() - async create( - @CurrentUser() currentUser: CurrentUserInterface, - @Body() params: CreateNewsParams - ): Promise { + async create(@CurrentUser() currentUser: ICurrentUser, @Body() params: CreateNewsParams): Promise { const news = await this.newsUc.create( currentUser.userId, currentUser.schoolId, @@ -41,7 +38,7 @@ export class NewsController { */ @Get() async findAll( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() scope: FilterNewsParams, @Query() pagination: PaginationParams ): Promise { @@ -61,10 +58,7 @@ export class NewsController { * The news entity has school and user names populated. */ @Get(':newsId') - async findOne( - @Param() urlParams: NewsUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async findOne(@Param() urlParams: NewsUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const news = await this.newsUc.findOneByIdForUser(urlParams.newsId, currentUser.userId); const dto = NewsMapper.mapToResponse(news); return dto; @@ -76,7 +70,7 @@ export class NewsController { @Patch(':newsId') async update( @Param() urlParams: NewsUrlParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() params: UpdateNewsParams ): Promise { const news = await this.newsUc.update( @@ -92,7 +86,7 @@ export class NewsController { * Delete a news. */ @Delete(':newsId') - async delete(@Param() urlParams: NewsUrlParams, @CurrentUser() currentUser: CurrentUserInterface): Promise { + async delete(@Param() urlParams: NewsUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const deletedId = await this.newsUc.delete(urlParams.newsId, currentUser.userId); return deletedId; } diff --git a/apps/server/src/modules/news/controller/team-news.controller.ts b/apps/server/src/modules/news/controller/team-news.controller.ts index 71e66c6c34c..ac70748e439 100644 --- a/apps/server/src/modules/news/controller/team-news.controller.ts +++ b/apps/server/src/modules/news/controller/team-news.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, Param, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { PaginationParams } from '@shared/controller'; @@ -18,7 +18,7 @@ export class TeamNewsController { @Get(':teamId/news') async findAllForTeam( @Param() urlParams: TeamUrlParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() scope: FilterNewsParams, @Query() pagination: PaginationParams ): Promise { diff --git a/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.spec.ts b/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.spec.ts index 7df890ee1f0..515f54f0a39 100644 --- a/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.spec.ts +++ b/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.spec.ts @@ -6,7 +6,7 @@ import { ProviderLoginResponse, ProviderRedirectResponse, } from '@infra/oauth-provider/dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AcceptQuery, ChallengeParams, @@ -40,7 +40,7 @@ describe('OauthProviderController', () => { let responseMapper: DeepMocked; const hydraUri = 'http://hydra.uri'; - const currentUser: CurrentUserInterface = { userId: 'userId' } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: 'userId' } as ICurrentUser; beforeAll(async () => { jest.spyOn(Configuration, 'get').mockReturnValue(hydraUri); diff --git a/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.ts b/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.ts index 0eb5323d368..29644154a3a 100644 --- a/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.ts +++ b/apps/server/src/modules/oauth-provider/controller/oauth-provider.controller.ts @@ -1,5 +1,5 @@ import { Configuration } from '@hpi-schul-cloud/commons'; -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query } from '@nestjs/common'; // import should be @infra/oauth-provider import { @@ -47,7 +47,7 @@ export class OauthProviderController { @Authenticate('jwt') @Get('clients/:id') async getOAuth2Client( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: IdParams ): Promise { const client: ProviderOauthClient = await this.crudUc.getOAuth2Client(currentUser, params.id); @@ -58,7 +58,7 @@ export class OauthProviderController { @Authenticate('jwt') @Get('clients') async listOAuth2Clients( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ListOauthClientsParams ): Promise { const clients: ProviderOauthClient[] = await this.crudUc.listOAuth2Clients( @@ -78,7 +78,7 @@ export class OauthProviderController { @Authenticate('jwt') @Post('clients') async createOAuth2Client( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() body: OauthClientBody ): Promise { const client: ProviderOauthClient = await this.crudUc.createOAuth2Client(currentUser, body); @@ -89,7 +89,7 @@ export class OauthProviderController { @Authenticate('jwt') @Put('clients/:id') async updateOAuth2Client( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: IdParams, @Body() body: OauthClientBody ): Promise { @@ -100,7 +100,7 @@ export class OauthProviderController { @Authenticate('jwt') @Delete('clients/:id') - deleteOAuth2Client(@CurrentUser() currentUser: CurrentUserInterface, @Param() params: IdParams): Promise { + deleteOAuth2Client(@CurrentUser() currentUser: ICurrentUser, @Param() params: IdParams): Promise { const promise: Promise = this.crudUc.deleteOAuth2Client(currentUser, params.id); return promise; } @@ -118,7 +118,7 @@ export class OauthProviderController { @Param() params: ChallengeParams, @Query() query: AcceptQuery, @Body() body: LoginRequestBody, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const redirectResponse: ProviderRedirectResponse = await this.oauthProviderLoginFlowUc.patchLoginRequest( currentUser.userId, @@ -152,7 +152,7 @@ export class OauthProviderController { @Param() params: ChallengeParams, @Query() query: AcceptQuery, @Body() body: ConsentRequestBody, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const redirectResponse: ProviderRedirectResponse = await this.consentFlowUc.patchConsentRequest( params.challenge, @@ -166,7 +166,7 @@ export class OauthProviderController { @Authenticate('jwt') @Get('auth/sessions/consent') - async listConsentSessions(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async listConsentSessions(@CurrentUser() currentUser: ICurrentUser): Promise { const sessions: ProviderConsentSessionResponse[] = await this.oauthProviderUc.listConsentSessions( currentUser.userId ); @@ -179,10 +179,7 @@ export class OauthProviderController { @Authenticate('jwt') @Delete('auth/sessions/consent') - revokeConsentSession( - @CurrentUser() currentUser: CurrentUserInterface, - @Param() params: RevokeConsentParams - ): Promise { + revokeConsentSession(@CurrentUser() currentUser: ICurrentUser, @Param() params: RevokeConsentParams): Promise { const promise: Promise = this.oauthProviderUc.revokeConsentSession(currentUser.userId, params.client); return promise; } diff --git a/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.spec.ts b/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.spec.ts index ad90d21c502..8e80da47969 100644 --- a/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.spec.ts +++ b/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { OauthProviderService } from '@infra/oauth-provider'; import { ProviderOauthClient } from '@infra/oauth-provider/dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AuthorizationService } from '@modules/authorization'; import { UnauthorizedException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -19,7 +19,7 @@ describe('OauthProviderUc', () => { let user: User; - const currentUser: CurrentUserInterface = { userId: 'userId' } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: 'userId' } as ICurrentUser; const defaultOauthClientBody: ProviderOauthClient = { scope: 'openid offline', grant_types: ['authorization_code', 'refresh_token'], diff --git a/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.ts b/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.ts index e29c23249f7..84221847796 100644 --- a/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.ts +++ b/apps/server/src/modules/oauth-provider/uc/oauth-provider.client-crud.uc.ts @@ -1,6 +1,6 @@ import { ProviderOauthClient } from '@infra/oauth-provider/dto'; import { OauthProviderService } from '@infra/oauth-provider/index'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AuthorizationService } from '@modules/authorization'; import { Injectable } from '@nestjs/common'; import { Permission, User } from '@shared/domain/index'; @@ -20,7 +20,7 @@ export class OauthProviderClientCrudUc { }; async listOAuth2Clients( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, limit?: number, offset?: number, client_name?: string, @@ -38,7 +38,7 @@ export class OauthProviderClientCrudUc { return client; } - async getOAuth2Client(currentUser: CurrentUserInterface, id: string): Promise { + async getOAuth2Client(currentUser: ICurrentUser, id: string): Promise { const user: User = await this.authorizationService.getUserWithPermissions(currentUser.userId); this.authorizationService.checkAllPermissions(user, [Permission.OAUTH_CLIENT_VIEW]); @@ -47,7 +47,7 @@ export class OauthProviderClientCrudUc { return client; } - async createOAuth2Client(currentUser: CurrentUserInterface, data: ProviderOauthClient): Promise { + async createOAuth2Client(currentUser: ICurrentUser, data: ProviderOauthClient): Promise { const user: User = await this.authorizationService.getUserWithPermissions(currentUser.userId); this.authorizationService.checkAllPermissions(user, [Permission.OAUTH_CLIENT_EDIT]); @@ -57,7 +57,7 @@ export class OauthProviderClientCrudUc { } async updateOAuth2Client( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, id: string, data: ProviderOauthClient ): Promise { @@ -69,7 +69,7 @@ export class OauthProviderClientCrudUc { return client; } - async deleteOAuth2Client(currentUser: CurrentUserInterface, id: string): Promise { + async deleteOAuth2Client(currentUser: ICurrentUser, id: string): Promise { const user: User = await this.authorizationService.getUserWithPermissions(currentUser.userId); this.authorizationService.checkAllPermissions(user, [Permission.OAUTH_CLIENT_EDIT]); diff --git a/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.spec.ts b/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.spec.ts index 3a61544bb37..e1a1663818e 100644 --- a/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.spec.ts +++ b/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { OauthProviderService } from '@infra/oauth-provider'; import { AcceptConsentRequestBody, ProviderConsentResponse, ProviderRedirectResponse } from '@infra/oauth-provider/dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AcceptQuery, ConsentRequestBody } from '@modules/oauth-provider/controller/dto'; import { IdToken } from '@modules/oauth-provider/interface/id-token'; import { IdTokenService } from '@modules/oauth-provider/service/id-token.service'; @@ -45,12 +45,12 @@ describe('OauthProviderConsentFlowUc', () => { describe('consent', () => { let challenge: string; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let consentResponse: ProviderConsentResponse; beforeEach(() => { challenge = 'challengexyz'; - currentUser = { userId: 'userId' } as CurrentUserInterface; + currentUser = { userId: 'userId' } as ICurrentUser; consentResponse = { challenge, subject: currentUser.userId, diff --git a/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.ts b/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.ts index a38cbcd6d5c..a9c54b4f502 100644 --- a/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.ts +++ b/apps/server/src/modules/oauth-provider/uc/oauth-provider.consent-flow.uc.ts @@ -5,7 +5,7 @@ import { ProviderRedirectResponse, RejectRequestBody, } from '@infra/oauth-provider/dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AcceptQuery, ConsentRequestBody } from '@modules/oauth-provider/controller/dto'; import { IdToken } from '@modules/oauth-provider/interface/id-token'; import { IdTokenService } from '@modules/oauth-provider/service/id-token.service'; @@ -27,7 +27,7 @@ export class OauthProviderConsentFlowUc { challenge: string, query: AcceptQuery, body: ConsentRequestBody, - currentUser: CurrentUserInterface + currentUser: ICurrentUser ): Promise { const consentResponse = await this.oauthProviderService.getConsentRequest(challenge); this.validateSubject(currentUser, consentResponse); @@ -77,7 +77,7 @@ export class OauthProviderConsentFlowUc { return redirectResponse; } - private validateSubject(currentUser: CurrentUserInterface, response: ProviderConsentResponse): void { + private validateSubject(currentUser: ICurrentUser, response: ProviderConsentResponse): void { if (response.subject !== currentUser.userId) { throw new ForbiddenException("You want to patch another user's consent"); } diff --git a/apps/server/src/modules/oauth/controller/oauth-sso.controller.spec.ts b/apps/server/src/modules/oauth/controller/oauth-sso.controller.spec.ts index 6f8c2fd5911..e98100d3e43 100644 --- a/apps/server/src/modules/oauth/controller/oauth-sso.controller.spec.ts +++ b/apps/server/src/modules/oauth/controller/oauth-sso.controller.spec.ts @@ -1,6 +1,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { HydraOauthUc } from '@modules/oauth/uc/hydra-oauth.uc'; import { UnauthorizedException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -85,7 +85,7 @@ describe('OAuthController', () => { }); describe('requestAuthToken', () => { - const currentUser: CurrentUserInterface = { userId: 'userId' } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: 'userId' } as ICurrentUser; const oauthClientId = 'clientId'; it('should call the hydraOauthUc', async () => { diff --git a/apps/server/src/modules/oauth/controller/oauth-sso.controller.ts b/apps/server/src/modules/oauth/controller/oauth-sso.controller.ts index 85e73c67c00..61ed319d1cd 100644 --- a/apps/server/src/modules/oauth/controller/oauth-sso.controller.ts +++ b/apps/server/src/modules/oauth/controller/oauth-sso.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, Param, Query, Req, UnauthorizedException } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { LegacyLogger } from '@src/core/logger'; @@ -28,7 +28,7 @@ export class OauthSSOController { @Get('auth/:oauthClientId') @Authenticate('jwt') async requestAuthToken( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Req() req: Request, @Param('oauthClientId') oauthClientId: string ): Promise { diff --git a/apps/server/src/modules/pseudonym/controller/pseudonym.controller.ts b/apps/server/src/modules/pseudonym/controller/pseudonym.controller.ts index 82e3dc9f584..993f3ba9ded 100644 --- a/apps/server/src/modules/pseudonym/controller/pseudonym.controller.ts +++ b/apps/server/src/modules/pseudonym/controller/pseudonym.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, Param } from '@nestjs/common'; import { ApiForbiddenResponse, @@ -26,7 +26,7 @@ export class PseudonymController { @ApiOperation({ summary: 'Returns the related user and tool information to a pseudonym' }) async getPseudonym( @Param() params: PseudonymParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const pseudonym: Pseudonym = await this.pseudonymUc.findPseudonymByPseudonym(currentUser.userId, params.pseudonym); diff --git a/apps/server/src/modules/sharing/controller/api-test/sharing-create-token.api.spec.ts b/apps/server/src/modules/sharing/controller/api-test/sharing-create-token.api.spec.ts index c9aae09c483..a79b02046ac 100644 --- a/apps/server/src/modules/sharing/controller/api-test/sharing-create-token.api.spec.ts +++ b/apps/server/src/modules/sharing/controller/api-test/sharing-create-token.api.spec.ts @@ -1,6 +1,6 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ExecutionContext, HttpStatus, INestApplication } from '@nestjs/common'; @@ -46,7 +46,7 @@ class API { describe(`share token creation (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/sharing/controller/api-test/sharing-import-token.api.spec.ts b/apps/server/src/modules/sharing/controller/api-test/sharing-import-token.api.spec.ts index 306c16fe118..9d8df39e195 100644 --- a/apps/server/src/modules/sharing/controller/api-test/sharing-import-token.api.spec.ts +++ b/apps/server/src/modules/sharing/controller/api-test/sharing-import-token.api.spec.ts @@ -1,6 +1,6 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { CopyApiResponse, CopyElementType, CopyStatusEnum } from '@modules/copy-helper'; import { ServerTestModule } from '@modules/server'; @@ -49,7 +49,7 @@ class API { describe(`share token import (api)`, () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let shareTokenService: ShareTokenService; let api: API; diff --git a/apps/server/src/modules/sharing/controller/share-token.controller.spec.ts b/apps/server/src/modules/sharing/controller/share-token.controller.spec.ts index ca17e72738c..d37b8b435ff 100644 --- a/apps/server/src/modules/sharing/controller/share-token.controller.spec.ts +++ b/apps/server/src/modules/sharing/controller/share-token.controller.spec.ts @@ -1,5 +1,5 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { CopyElementType, CopyStatus, CopyStatusEnum } from '@modules/copy-helper'; import { Test, TestingModule } from '@nestjs/testing'; import { courseFactory, setupEntities, shareTokenFactory } from '@shared/testing'; @@ -39,7 +39,7 @@ describe('ShareTokenController', () => { describe('creating a token', () => { const setup = () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const shareToken = shareTokenFactory.build({ token: 'ctuW1FG0RsTo' }); uc.createShareToken.mockResolvedValue(shareToken); const body = { @@ -84,7 +84,7 @@ describe('ShareTokenController', () => { describe('looking up a token', () => { it('should call the use case', async () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const token = 'ctuW1FG0RsTo'; await controller.lookupShareToken(currentUser, { token }); @@ -93,7 +93,7 @@ describe('ShareTokenController', () => { }); it('should return the token data', async () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const shareTokenInfo: ShareTokenInfoDto = { token: 'ctuW1FG0RsTo', parentType: ShareTokenParentType.Course, @@ -110,7 +110,7 @@ describe('ShareTokenController', () => { describe('importing a share token', () => { const setup = () => { - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const token = 'ctuW1FG0RsTo'; const course = courseFactory.buildWithId(); const status: CopyStatus = { diff --git a/apps/server/src/modules/sharing/controller/share-token.controller.ts b/apps/server/src/modules/sharing/controller/share-token.controller.ts index f5793033b9d..5d990e1d99f 100644 --- a/apps/server/src/modules/sharing/controller/share-token.controller.ts +++ b/apps/server/src/modules/sharing/controller/share-token.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { CopyApiResponse, CopyMapper } from '@modules/copy-helper'; import { Body, @@ -38,7 +38,7 @@ export class ShareTokenController { @ApiResponse({ status: 500, type: InternalServerErrorException }) @Post() async createShareToken( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() body: ShareTokenBodyParams ): Promise { const shareToken = await this.shareTokenUC.createShareToken( @@ -65,7 +65,7 @@ export class ShareTokenController { @ApiResponse({ status: 500, type: InternalServerErrorException }) @Get(':token') async lookupShareToken( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: ShareTokenUrlParams ): Promise { const shareTokenInfo = await this.shareTokenUC.lookupShareToken(currentUser.userId, urlParams.token); @@ -84,7 +84,7 @@ export class ShareTokenController { @Post(':token/import') @RequestTimeout(serverConfig().INCOMING_REQUEST_TIMEOUT_COPY_API) async importShareToken( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: ShareTokenUrlParams, @Body() body: ShareTokenImportBodyParams ): Promise { diff --git a/apps/server/src/modules/system/controller/api-test/system.api.spec.ts b/apps/server/src/modules/system/controller/api-test/system.api.spec.ts index 3657b4a92a7..3167558461d 100644 --- a/apps/server/src/modules/system/controller/api-test/system.api.spec.ts +++ b/apps/server/src/modules/system/controller/api-test/system.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -14,7 +14,7 @@ import { PublicSystemResponse } from '../dto/public-system-response'; describe('System (API)', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; beforeAll(async () => { const moduleRef: TestingModule = await Test.createTestingModule({ diff --git a/apps/server/src/modules/task/controller/api-test/submission.api.spec.ts b/apps/server/src/modules/task/controller/api-test/submission.api.spec.ts index 27a6a7eb77e..aed731a86e8 100644 --- a/apps/server/src/modules/task/controller/api-test/submission.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/submission.api.spec.ts @@ -1,6 +1,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { FilesStorageClientAdapterService } from '@modules/files-storage-client'; import { ServerTestModule } from '@modules/server/server.module'; @@ -58,7 +58,7 @@ class API { describe('Submission Controller (API)', () => { describe('find statuses by task', () => { let app: INestApplication; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let em: EntityManager; @@ -182,7 +182,7 @@ describe('Submission Controller (API)', () => { describe('delete submission', () => { let app: INestApplication; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; let em: EntityManager; let filesStorageClientAdapterService: DeepMocked; diff --git a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts index 7a69fbecdee..d5546c435da 100644 --- a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts @@ -2,7 +2,7 @@ import { createMock } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig'; import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { FilesStorageClientAdapterService } from '@modules/files-storage-client'; import { ExecutionContext, INestApplication } from '@nestjs/common'; @@ -30,7 +30,7 @@ import { ServerTestModule } from '@modules/server/server.module'; describe('Task copy (API)', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let configBefore: IConfig; beforeAll(async () => { diff --git a/apps/server/src/modules/task/controller/api-test/task-finished.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-finished.api.spec.ts index 4177ce1ed18..f8261f9649b 100644 --- a/apps/server/src/modules/task/controller/api-test/task-finished.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-finished.api.spec.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { TaskListResponse } from '@modules/task/controller/dto'; @@ -44,7 +44,7 @@ class API { describe('Task controller (API)', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/task/controller/submission.controller.ts b/apps/server/src/modules/task/controller/submission.controller.ts index ccaed6fc403..48f0899b07e 100644 --- a/apps/server/src/modules/task/controller/submission.controller.ts +++ b/apps/server/src/modules/task/controller/submission.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Delete, Get, Param } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { SubmissionMapper } from '../mapper'; @@ -13,7 +13,7 @@ export class SubmissionController { @Get('status/task/:taskId') async findStatusesByTask( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: TaskUrlParams ): Promise { const submissions = await this.submissionUc.findAllByTask(currentUser.userId, params.taskId); @@ -26,10 +26,7 @@ export class SubmissionController { } @Delete(':submissionId') - async delete( - @Param() urlParams: SubmissionUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async delete(@Param() urlParams: SubmissionUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const result = await this.submissionUc.delete(currentUser.userId, urlParams.submissionId); return result; diff --git a/apps/server/src/modules/task/controller/task.controller.spec.ts b/apps/server/src/modules/task/controller/task.controller.spec.ts index 219418c521b..b76bb66d4da 100644 --- a/apps/server/src/modules/task/controller/task.controller.spec.ts +++ b/apps/server/src/modules/task/controller/task.controller.spec.ts @@ -1,5 +1,5 @@ import { createMock } from '@golevelup/ts-jest'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { CopyElementType, CopyStatus, CopyStatusEnum } from '@modules/copy-helper'; import { CopyApiResponse } from '@modules/copy-helper/dto/copy.response'; import { Test, TestingModule } from '@nestjs/testing'; @@ -42,7 +42,7 @@ describe('TaskController', () => { describe('when task should be copied via API call', () => { const setup = () => { // todo: why not use builder instead of as - const currentUser = { userId: 'userId' } as CurrentUserInterface; + const currentUser = { userId: 'userId' } as ICurrentUser; const ucResult = { title: 'example title', type: 'TASK' as CopyElementType, diff --git a/apps/server/src/modules/task/controller/task.controller.ts b/apps/server/src/modules/task/controller/task.controller.ts index b4dcf47724e..b8e7231a1b6 100644 --- a/apps/server/src/modules/task/controller/task.controller.ts +++ b/apps/server/src/modules/task/controller/task.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { CopyApiResponse, CopyMapper } from '@modules/copy-helper'; import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; @@ -20,7 +20,7 @@ export class TaskController { @Get() async findAll( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() pagination: PaginationParams ): Promise { return this.findAllTasks(currentUser, pagination); @@ -28,14 +28,14 @@ export class TaskController { @Get('finished') async findAllFinished( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() pagination: PaginationParams ): Promise { return this.findAllTasks(currentUser, pagination, true); } private async findAllTasks( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() pagination: PaginationParams, finished = false ): Promise { @@ -51,10 +51,7 @@ export class TaskController { } @Patch(':taskId/finish') - async finish( - @Param() urlParams: TaskUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async finish(@Param() urlParams: TaskUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const task = await this.taskUc.changeFinishedForUser(currentUser.userId, urlParams.taskId, true); const response = TaskMapper.mapToResponse(task); @@ -63,10 +60,7 @@ export class TaskController { } @Patch(':taskId/restore') - async restore( - @Param() urlParams: TaskUrlParams, - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async restore(@Param() urlParams: TaskUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const task = await this.taskUc.changeFinishedForUser(currentUser.userId, urlParams.taskId, false); const response = TaskMapper.mapToResponse(task); @@ -77,7 +71,7 @@ export class TaskController { @Patch(':taskId/revertPublished') async revertPublished( @Param() urlParams: TaskUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const task = await this.taskUc.revertPublished(currentUser.userId, urlParams.taskId); @@ -89,7 +83,7 @@ export class TaskController { @Post(':taskId/copy') @RequestTimeout(serverConfig().INCOMING_REQUEST_TIMEOUT_COPY_API) async copyTask( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() urlParams: TaskUrlParams, @Body() params: TaskCopyApiParams ): Promise { @@ -103,7 +97,7 @@ export class TaskController { } @Delete(':taskId') - async delete(@Param() urlParams: TaskUrlParams, @CurrentUser() currentUser: CurrentUserInterface): Promise { + async delete(@Param() urlParams: TaskUrlParams, @CurrentUser() currentUser: ICurrentUser): Promise { const result = await this.taskUc.delete(currentUser.userId, urlParams.taskId); return result; diff --git a/apps/server/src/modules/tool/context-external-tool/controller/tool-context.controller.ts b/apps/server/src/modules/tool/context-external-tool/controller/tool-context.controller.ts index 68a75a57a60..20d8b96f795 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/tool-context.controller.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/tool-context.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put } from '@nestjs/common'; import { ApiCreatedResponse, @@ -42,7 +42,7 @@ export class ToolContextController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiOperation({ summary: 'Creates a ContextExternalTool' }) async createContextExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() body: ContextExternalToolPostParams ): Promise { const contextExternalTool: ContextExternalToolDto = @@ -68,7 +68,7 @@ export class ToolContextController { @ApiOperation({ summary: 'Deletes a ContextExternalTool' }) @HttpCode(HttpStatus.NO_CONTENT) async deleteContextExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolIdParams ): Promise { await this.contextExternalToolUc.deleteContextExternalTool(currentUser.userId, params.contextExternalToolId); @@ -87,7 +87,7 @@ export class ToolContextController { }) @ApiOperation({ summary: 'Returns a list of ContextExternalTools for the given context' }) async getContextExternalToolsForContext( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolContextParams ): Promise { const contextExternalTools: ContextExternalTool[] = @@ -120,7 +120,7 @@ export class ToolContextController { }) @ApiOperation({ summary: 'Searches a ContextExternalTool for the given id' }) async getContextExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolIdParams ): Promise { const contextExternalTool: ContextExternalTool = await this.contextExternalToolUc.getContextExternalTool( @@ -144,7 +144,7 @@ export class ToolContextController { @ApiUnprocessableEntityResponse() @ApiOperation({ summary: 'Updates a ContextExternalTool' }) async updateContextExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolIdParams, @Body() body: ContextExternalToolPostParams ): Promise { diff --git a/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts b/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts index 6b53af1ebfc..4f7b7ed2703 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, Param } from '@nestjs/common'; import { ApiForbiddenResponse, ApiOkResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; import { ToolReference } from '../domain'; @@ -26,7 +26,7 @@ export class ToolReferenceController { @ApiForbiddenResponse({ description: 'User is not allowed to access this resource.' }) @ApiUnauthorizedResponse({ description: 'User is not logged in.' }) async getToolReference( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolIdParams ): Promise { const toolReference: ToolReference = await this.toolReferenceUc.getToolReference( @@ -49,7 +49,7 @@ export class ToolReferenceController { @ApiForbiddenResponse({ description: 'User is not allowed to access this resource.' }) @ApiUnauthorizedResponse({ description: 'User is not logged in.' }) async getToolReferencesForContext( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolContextParams ): Promise { const toolReferences: ToolReference[] = await this.toolReferenceUc.getToolReferencesForContext( diff --git a/apps/server/src/modules/tool/external-tool/controller/tool-configuration.controller.ts b/apps/server/src/modules/tool/external-tool/controller/tool-configuration.controller.ts index 570bf1282ff..5dbe2db8e9b 100644 --- a/apps/server/src/modules/tool/external-tool/controller/tool-configuration.controller.ts +++ b/apps/server/src/modules/tool/external-tool/controller/tool-configuration.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, Param } from '@nestjs/common'; import { ApiForbiddenResponse, @@ -36,7 +36,7 @@ export class ToolConfigurationController { type: SchoolExternalToolConfigurationTemplateListResponse, }) public async getAvailableToolsForSchool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: SchoolIdParams ): Promise { const availableTools: ExternalTool[] = await this.externalToolConfigurationUc.getAvailableToolsForSchool( @@ -58,7 +58,7 @@ export class ToolConfigurationController { type: ContextExternalToolConfigurationTemplateListResponse, }) public async getAvailableToolsForContext( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextRefParams ): Promise { const availableTools: ContextExternalToolTemplateInfo[] = @@ -84,7 +84,7 @@ export class ToolConfigurationController { type: SchoolExternalToolConfigurationTemplateResponse, }) public async getConfigurationTemplateForSchool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: SchoolExternalToolIdParams ): Promise { const tool: ExternalTool = await this.externalToolConfigurationUc.getTemplateForSchoolExternalTool( @@ -107,7 +107,7 @@ export class ToolConfigurationController { type: ContextExternalToolConfigurationTemplateResponse, }) public async getConfigurationTemplateForContext( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ContextExternalToolIdParams ): Promise { const tool: ContextExternalToolTemplateInfo = diff --git a/apps/server/src/modules/tool/external-tool/controller/tool.controller.ts b/apps/server/src/modules/tool/external-tool/controller/tool.controller.ts index ec102455d06..5977c67cfa6 100644 --- a/apps/server/src/modules/tool/external-tool/controller/tool.controller.ts +++ b/apps/server/src/modules/tool/external-tool/controller/tool.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Query, Res } from '@nestjs/common'; import { ApiCreatedResponse, @@ -51,7 +51,7 @@ export class ToolController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiOperation({ summary: 'Creates an ExternalTool' }) async createExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() externalToolParams: ExternalToolCreateParams ): Promise { const externalTool: ExternalToolCreate = this.externalToolDOMapper.mapCreateRequest(externalToolParams); @@ -71,7 +71,7 @@ export class ToolController { @ApiForbiddenResponse() @ApiOperation({ summary: 'Returns a list of ExternalTools' }) async findExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() filterQuery: ExternalToolSearchParams, @Query() pagination: PaginationParams, @Query() sortingQuery: SortExternalToolParams @@ -99,7 +99,7 @@ export class ToolController { @Get(':externalToolId') @ApiOperation({ summary: 'Returns an ExternalTool for the given id' }) async getExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ExternalToolIdParams ): Promise { const externalTool: ExternalTool = await this.externalToolUc.getExternalTool( @@ -118,7 +118,7 @@ export class ToolController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiOperation({ summary: 'Updates an ExternalTool' }) async updateExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ExternalToolIdParams, @Body() externalToolParams: ExternalToolUpdateParams ): Promise { @@ -140,7 +140,7 @@ export class ToolController { @ApiOperation({ summary: 'Deletes an ExternalTool' }) @HttpCode(HttpStatus.NO_CONTENT) async deleteExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ExternalToolIdParams ): Promise { const promise: Promise = this.externalToolUc.deleteExternalTool(currentUser.userId, params.externalToolId); diff --git a/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts b/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts index 56c0075ae97..1c0899bd183 100644 --- a/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts +++ b/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts @@ -1,5 +1,5 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AuthorizationService } from '@modules/authorization'; import { UnauthorizedException, UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -68,7 +68,7 @@ describe('ExternalToolUc', () => { const setupAuthorization = () => { const user: User = userFactory.buildWithId(); - const currentUser: CurrentUserInterface = { userId: user.id } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: user.id } as ICurrentUser; authorizationService.getUserWithPermissions.mockResolvedValue(user); @@ -190,7 +190,7 @@ describe('ExternalToolUc', () => { describe('when fetching logo', () => { const setupLogo = () => { const user: User = userFactory.buildWithId(); - const currentUser: CurrentUserInterface = { userId: user.id } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: user.id } as ICurrentUser; const externalTool: ExternalTool = externalToolFactory.buildWithId(); @@ -414,7 +414,7 @@ describe('ExternalToolUc', () => { describe('when fetching logo', () => { const setupLogo = () => { const user: User = userFactory.buildWithId(); - const currentUser: CurrentUserInterface = { userId: user.id } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: user.id } as ICurrentUser; const externalTool: ExternalTool = externalToolFactory.buildWithId(); @@ -439,7 +439,7 @@ describe('ExternalToolUc', () => { describe('deleteExternalTool', () => { const setupDelete = () => { const toolId = 'toolId'; - const currentUser: CurrentUserInterface = { userId: 'userId' } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: 'userId' } as ICurrentUser; const user: User = userFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValue(user); diff --git a/apps/server/src/modules/tool/school-external-tool/controller/tool-school.controller.ts b/apps/server/src/modules/tool/school-external-tool/controller/tool-school.controller.ts index 5ef5b4fd8d8..4361d452568 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/tool-school.controller.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/tool-school.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put, Query } from '@nestjs/common'; import { ApiBadRequestResponse, @@ -44,7 +44,7 @@ export class ToolSchoolController { @ApiUnauthorizedResponse() @ApiOperation({ summary: 'Returns a list of SchoolExternalTools for a given school' }) async getSchoolExternalTools( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() schoolExternalToolParams: SchoolExternalToolSearchParams ): Promise { const found: SchoolExternalTool[] = await this.schoolExternalToolUc.findSchoolExternalTools(currentUser.userId, { @@ -59,7 +59,7 @@ export class ToolSchoolController { @ApiUnauthorizedResponse() @ApiOperation({ summary: 'Returns a SchoolExternalTool for the given id' }) async getSchoolExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: SchoolExternalToolIdParams ): Promise { const schoolExternalTool: SchoolExternalTool = await this.schoolExternalToolUc.getSchoolExternalTool( @@ -77,7 +77,7 @@ export class ToolSchoolController { @ApiBadRequestResponse({ type: ValidationError, description: 'Request data has invalid format.' }) @ApiOperation({ summary: 'Updates a SchoolExternalTool' }) async updateSchoolExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: SchoolExternalToolIdParams, @Body() body: SchoolExternalToolPostParams ): Promise { @@ -99,7 +99,7 @@ export class ToolSchoolController { @ApiOperation({ summary: 'Deletes a SchoolExternalTool' }) @HttpCode(HttpStatus.NO_CONTENT) async deleteSchoolExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: SchoolExternalToolIdParams ): Promise { await this.schoolExternalToolUc.deleteSchoolExternalTool(currentUser.userId, params.schoolExternalToolId); @@ -119,7 +119,7 @@ export class ToolSchoolController { @ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' }) @ApiOperation({ summary: 'Creates a SchoolExternalTool' }) async createSchoolExternalTool( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() body: SchoolExternalToolPostParams ): Promise { const schoolExternalToolDto: SchoolExternalToolDto = this.requestMapper.mapSchoolExternalToolRequest(body); diff --git a/apps/server/src/modules/tool/tool-launch/controller/tool-launch.controller.ts b/apps/server/src/modules/tool/tool-launch/controller/tool-launch.controller.ts index a11a61468c0..3ac323b1000 100644 --- a/apps/server/src/modules/tool/tool-launch/controller/tool-launch.controller.ts +++ b/apps/server/src/modules/tool/tool-launch/controller/tool-launch.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Controller, Get, Param } from '@nestjs/common'; import { ApiBadRequestResponse, @@ -26,7 +26,7 @@ export class ToolLaunchController { @ApiForbiddenResponse({ description: 'Forbidden' }) @ApiBadRequestResponse({ description: 'Outdated tools cannot be launched' }) async getToolLaunchRequest( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() params: ToolLaunchParams ): Promise { const toolLaunchRequest: ToolLaunchRequest = await this.toolLaunchUc.getToolLaunchRequest( diff --git a/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts b/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts index 2b4e8fc25ee..51bea6b1224 100644 --- a/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts +++ b/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts @@ -1,6 +1,6 @@ import { Configuration } from '@hpi-schul-cloud/commons'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { @@ -48,7 +48,7 @@ import request from 'supertest'; describe('ImportUser Controller (API)', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; const authenticatedUser = async (permissions: Permission[] = [], features: SchoolFeatures[] = []) => { const system = systemFactory.buildWithId(); // TODO no id? diff --git a/apps/server/src/modules/user-import/controller/import-user.controller.ts b/apps/server/src/modules/user-import/controller/import-user.controller.ts index 6f49104c425..bc29f09d6c9 100644 --- a/apps/server/src/modules/user-import/controller/import-user.controller.ts +++ b/apps/server/src/modules/user-import/controller/import-user.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { PaginationParams } from '@shared/controller'; @@ -27,7 +27,7 @@ export class ImportUserController { @Get() async findAllImportUsers( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() scope: FilterImportUserParams, @Query() sortingQuery: SortImportUserParams, @Query() pagination: PaginationParams @@ -46,7 +46,7 @@ export class ImportUserController { @Patch(':importUserId/match') async setMatch( @Param() urlParams: ImportUserUrlParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() params: UpdateMatchParams ): Promise { const result = await this.userImportUc.setMatch(currentUser.userId, urlParams.importUserId, params.userId); @@ -58,7 +58,7 @@ export class ImportUserController { @Delete(':importUserId/match') async removeMatch( @Param() urlParams: ImportUserUrlParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const result = await this.userImportUc.removeMatch(currentUser.userId, urlParams.importUserId); const response = ImportUserMapper.mapToResponse(result); @@ -69,7 +69,7 @@ export class ImportUserController { @Patch(':importUserId/flag') async updateFlag( @Param() urlParams: ImportUserUrlParams, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() params: UpdateFlagParams ): Promise { const result = await this.userImportUc.updateFlag(currentUser.userId, urlParams.importUserId, params.flagged); @@ -80,7 +80,7 @@ export class ImportUserController { @Get('unassigned') async findAllUnmatchedUsers( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query() scope: FilterUserParams, @Query() pagination: PaginationParams ): Promise { @@ -96,20 +96,20 @@ export class ImportUserController { } @Post('migrate') - async saveAllUsersMatches(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async saveAllUsersMatches(@CurrentUser() currentUser: ICurrentUser): Promise { await this.userImportUc.saveAllUsersMatches(currentUser.userId); } @Post('startUserMigration') async startSchoolInUserMigration( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Query('useCentralLdap') useCentralLdap?: boolean ): Promise { await this.userImportUc.startSchoolInUserMigration(currentUser.userId, useCentralLdap); } @Post('startSync') - async endSchoolInMaintenance(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async endSchoolInMaintenance(@CurrentUser() currentUser: ICurrentUser): Promise { await this.userImportUc.endSchoolInMaintenance(currentUser.userId); } } diff --git a/apps/server/src/modules/user-login-migration/controller/user-login-migration.controller.ts b/apps/server/src/modules/user-login-migration/controller/user-login-migration.controller.ts index 3f218f2c7a2..5489e33e3a4 100644 --- a/apps/server/src/modules/user-login-migration/controller/user-login-migration.controller.ts +++ b/apps/server/src/modules/user-login-migration/controller/user-login-migration.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface, JWT } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser, JWT } from '@modules/authentication'; import { Body, Controller, Get, HttpCode, HttpStatus, Param, Post, Put, Query } from '@nestjs/common'; import { ApiForbiddenResponse, @@ -57,7 +57,7 @@ export class UserLoginMigrationController { @ApiOkResponse({ description: 'UserLoginMigrations has been found.', type: UserLoginMigrationSearchListResponse }) @ApiInternalServerErrorResponse({ description: 'Cannot find target system information.' }) async getMigrations( - @CurrentUser() user: CurrentUserInterface, + @CurrentUser() user: ICurrentUser, @Query() params: UserLoginMigrationSearchParams ): Promise { const userLoginMigrationQuery: UserLoginMigrationQuery = UserLoginMigrationMapper.mapSearchParamsToQuery(params); @@ -87,7 +87,7 @@ export class UserLoginMigrationController { @ApiOkResponse({ description: 'UserLoginMigrations has been found', type: UserLoginMigrationResponse }) @ApiNotFoundResponse({ description: 'Cannot find UserLoginMigration' }) async findUserLoginMigrationBySchool( - @CurrentUser() user: CurrentUserInterface, + @CurrentUser() user: ICurrentUser, @Param() params: SchoolIdParams ): Promise { const userLoginMigration: UserLoginMigrationDO = await this.userLoginMigrationUc.findUserLoginMigrationBySchool( @@ -112,7 +112,7 @@ export class UserLoginMigrationController { }) @ApiOkResponse({ description: 'User login migration started', type: UserLoginMigrationResponse }) @ApiForbiddenResponse() - async startMigration(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async startMigration(@CurrentUser() currentUser: ICurrentUser): Promise { const migrationDto: UserLoginMigrationDO = await this.startUserLoginMigrationUc.startMigration( currentUser.userId, currentUser.schoolId @@ -136,7 +136,7 @@ export class UserLoginMigrationController { @ApiOkResponse({ description: 'User login migration started', type: UserLoginMigrationResponse }) @ApiUnauthorizedResponse() @ApiForbiddenResponse() - async restartMigration(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async restartMigration(@CurrentUser() currentUser: ICurrentUser): Promise { const migrationDto: UserLoginMigrationDO = await this.restartUserLoginMigrationUc.restartMigration( currentUser.userId, currentUser.schoolId @@ -165,7 +165,7 @@ export class UserLoginMigrationController { @ApiUnauthorizedResponse() @ApiForbiddenResponse() async setMigrationMandatory( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() body: UserLoginMigrationMandatoryParams ): Promise { const migrationDto: UserLoginMigrationDO = await this.toggleUserLoginMigrationUc.setMigrationMandatory( @@ -198,9 +198,7 @@ export class UserLoginMigrationController { @ApiUnauthorizedResponse() @ApiForbiddenResponse() @ApiNoContentResponse({ description: 'User login migration was reverted' }) - async closeMigration( - @CurrentUser() currentUser: CurrentUserInterface - ): Promise { + async closeMigration(@CurrentUser() currentUser: ICurrentUser): Promise { const userLoginMigration: UserLoginMigrationDO | undefined = await this.closeUserLoginMigrationUc.closeMigration( currentUser.userId, currentUser.schoolId @@ -219,7 +217,7 @@ export class UserLoginMigrationController { @ApiInternalServerErrorResponse({ description: 'The migration of the User was not possible.' }) async migrateUserLogin( @JWT() jwt: string, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Body() body: Oauth2MigrationParams ): Promise { await this.userLoginMigrationUc.migrate(jwt, currentUser.userId, body.systemId, body.code, body.redirectUri); diff --git a/apps/server/src/modules/user/controller/api-test/user-language.api.spec.ts b/apps/server/src/modules/user/controller/api-test/user-language.api.spec.ts index c8f19e289fb..50b1c08f8d9 100644 --- a/apps/server/src/modules/user/controller/api-test/user-language.api.spec.ts +++ b/apps/server/src/modules/user/controller/api-test/user-language.api.spec.ts @@ -2,7 +2,7 @@ import { EntityManager } from '@mikro-orm/mongodb'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ApiValidationError } from '@shared/common'; @@ -85,7 +85,7 @@ describe(baseRouteName, () => { describe('with bad request data', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { @@ -139,7 +139,7 @@ describe(baseRouteName, () => { describe('without valid request data', () => { let app: INestApplication; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/user/controller/api-test/user-me.api.spec.ts b/apps/server/src/modules/user/controller/api-test/user-me.api.spec.ts index 3e89c362d0c..c77f23f2e59 100644 --- a/apps/server/src/modules/user/controller/api-test/user-me.api.spec.ts +++ b/apps/server/src/modules/user/controller/api-test/user-me.api.spec.ts @@ -5,7 +5,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { Request } from 'express'; import request from 'supertest'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ServerTestModule } from '@modules/server/server.module'; import { ResolvedUserResponse } from '@modules/user/controller/dto'; @@ -87,7 +87,7 @@ describe(baseRouteName, () => { let app: INestApplication; let orm: MikroORM; let em: EntityManager; - let currentUser: CurrentUserInterface; + let currentUser: ICurrentUser; let api: API; beforeAll(async () => { diff --git a/apps/server/src/modules/user/controller/user.controller.ts b/apps/server/src/modules/user/controller/user.controller.ts index 5261898b3fa..1d3739b3144 100644 --- a/apps/server/src/modules/user/controller/user.controller.ts +++ b/apps/server/src/modules/user/controller/user.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Get, Patch } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { ResolvedUserMapper } from '../mapper'; @@ -12,7 +12,7 @@ export class UserController { constructor(private readonly userUc: UserUc) {} @Get('me') - async me(@CurrentUser() currentUser: CurrentUserInterface): Promise { + async me(@CurrentUser() currentUser: ICurrentUser): Promise { const [user, permissions] = await this.userUc.me(currentUser.userId); // only the root roles of the user get published @@ -24,7 +24,7 @@ export class UserController { @Patch('/language') async changeLanguage( @Body() params: ChangeLanguageParams, - @CurrentUser() currentUser: CurrentUserInterface + @CurrentUser() currentUser: ICurrentUser ): Promise { const result = await this.userUc.patchLanguage(currentUser.userId, params); diff --git a/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.spec.ts b/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.spec.ts index a2411336426..01a62786582 100644 --- a/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.spec.ts +++ b/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.spec.ts @@ -1,6 +1,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { Test, TestingModule } from '@nestjs/testing'; import { VideoConferenceScope } from '@shared/domain/interface'; import { BBBBaseResponse, BBBCreateResponse } from '../bbb'; @@ -18,7 +18,7 @@ describe('VideoConferenceDeprecatedController', () => { let controller: VideoConferenceDeprecatedController; let videoConferenceUc: DeepMocked; - const currentUser: CurrentUserInterface = { userId: new ObjectId().toHexString() } as CurrentUserInterface; + const currentUser: ICurrentUser = { userId: new ObjectId().toHexString() } as ICurrentUser; beforeAll(async () => { module = await Test.createTestingModule({ diff --git a/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.ts b/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.ts index db130c87288..d32273b98f7 100644 --- a/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.ts +++ b/apps/server/src/modules/video-conference/controller/video-conference-deprecated.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { BadRequestException, Body, @@ -44,7 +44,7 @@ export class VideoConferenceDeprecatedController { }) @ApiResponse({ status: 500, type: InternalServerErrorException, description: 'Unable to fetch required data.' }) async createAndJoin( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param('scope') scope: VideoConferenceScope, @Param('scopeId') scopeId: string, @Body() params: VideoConferenceCreateParams @@ -84,7 +84,7 @@ export class VideoConferenceDeprecatedController { }) @ApiResponse({ status: 500, type: InternalServerErrorException, description: 'Unable to fetch required data.' }) async info( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param('scope') scope: VideoConferenceScope, @Param('scopeId') scopeId: string ): Promise { @@ -104,7 +104,7 @@ export class VideoConferenceDeprecatedController { }) @ApiResponse({ status: 500, type: InternalServerErrorException, description: 'Unable to fetch required data.' }) async end( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param('scope') scope: VideoConferenceScope, @Param('scopeId') scopeId: string ): Promise { diff --git a/apps/server/src/modules/video-conference/controller/video-conference.controller.ts b/apps/server/src/modules/video-conference/controller/video-conference.controller.ts index 062b4c27ec5..b55eac17f64 100644 --- a/apps/server/src/modules/video-conference/controller/video-conference.controller.ts +++ b/apps/server/src/modules/video-conference/controller/video-conference.controller.ts @@ -1,4 +1,4 @@ -import { Authenticate, CurrentUser, CurrentUserInterface } from '@modules/authentication'; +import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; import { Body, Controller, Get, HttpStatus, Param, Put, Req } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { Request } from 'express'; @@ -43,7 +43,7 @@ export class VideoConferenceController { @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Unable to fetch required data.' }) async start( @Req() req: Request, - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() scopeParams: VideoConferenceScopeParams, @Body() params: VideoConferenceCreateParams ): Promise { @@ -75,7 +75,7 @@ export class VideoConferenceController { }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Unable to fetch required data.' }) async join( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() scopeParams: VideoConferenceScopeParams ): Promise { const scopeRef = new ScopeRef(scopeParams.scopeId, scopeParams.scope); @@ -103,7 +103,7 @@ export class VideoConferenceController { }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Unable to fetch required data.' }) async info( - @CurrentUser() currentUser: CurrentUserInterface, + @CurrentUser() currentUser: ICurrentUser, @Param() scopeParams: VideoConferenceScopeParams ): Promise { const scopeRef = new ScopeRef(scopeParams.scopeId, scopeParams.scope); @@ -129,10 +129,7 @@ export class VideoConferenceController { description: 'User does not have the permission to end this conference.', }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Unable to fetch required data.' }) - async end( - @CurrentUser() currentUser: CurrentUserInterface, - @Param() scopeParams: VideoConferenceScopeParams - ): Promise { + async end(@CurrentUser() currentUser: ICurrentUser, @Param() scopeParams: VideoConferenceScopeParams): Promise { const scopeRef = new ScopeRef(scopeParams.scopeId, scopeParams.scope); await this.videoConferenceEndUc.end(currentUser.userId, scopeRef); diff --git a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts index 0b745dfd90c..a8caf8f2dc9 100644 --- a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts +++ b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts @@ -2,7 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { CalendarService } from '@infra/calendar'; import { CalendarEventDto } from '@infra/calendar/dto/calendar-event.dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { AuthorizationReferenceService } from '@modules/authorization/domain'; import { CourseService } from '@modules/learnroom/service'; import { LegacySchoolService } from '@modules/legacy-school'; @@ -81,7 +81,7 @@ describe('VideoConferenceUc', () => { teamId: 'teamId', }); let featureEnabled = false; - let defaultCurrentUser: CurrentUserInterface; + let defaultCurrentUser: ICurrentUser; let defaultOptions: VideoConferenceOptions; const userPermissions: Map> = new Map>(); diff --git a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts index e0de32b730f..14d8b594fb9 100644 --- a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts +++ b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts @@ -1,7 +1,7 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { CalendarService } from '@infra/calendar'; import { CalendarEventDto } from '@infra/calendar/dto/calendar-event.dto'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { Action, AuthorizationContextBuilder } from '@modules/authorization'; import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modules/authorization/domain'; import { CourseService } from '@modules/learnroom'; @@ -71,14 +71,14 @@ export class VideoConferenceDeprecatedUc { /** * Creates a new video conference. - * @param {CurrentUserInterface} currentUser + * @param {ICurrentUser} currentUser * @param {VideoConferenceScope} conferenceScope * @param {EntityId} refId eventId or courseId, depending on scope. * @param {VideoConferenceOptions} options * @returns {Promise>} */ async create( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, conferenceScope: VideoConferenceScope, refId: EntityId, options: VideoConferenceOptions @@ -136,13 +136,13 @@ export class VideoConferenceDeprecatedUc { /** * Generates a join link for a video conference. - * @param {CurrentUserInterface} currentUser + * @param {ICurrentUser} currentUser * @param {VideoConferenceScope} conferenceScope * @param {EntityId} refId eventId or courseId, depending on scope. * @returns {Promise} */ async join( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, conferenceScope: VideoConferenceScope, refId: EntityId ): Promise { @@ -191,13 +191,13 @@ export class VideoConferenceDeprecatedUc { /** * Retrieves information about a video conference. - * @param {CurrentUserInterface} currentUser + * @param {ICurrentUser} currentUser * @param {VideoConferenceScope} conferenceScope * @param {EntityId} refId eventId or courseId, depending on scope. * @returns {BBBResponse} */ async getMeetingInfo( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, conferenceScope: VideoConferenceScope, refId: EntityId ): Promise { @@ -268,13 +268,13 @@ export class VideoConferenceDeprecatedUc { /** * Ends a video conference. - * @param {CurrentUserInterface} currentUser + * @param {ICurrentUser} currentUser * @param {VideoConferenceScope} conferenceScope * @param {EntityId} refId eventId or courseId, depending on scope. * @returns {Promise>} */ async end( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, conferenceScope: VideoConferenceScope, refId: EntityId ): Promise> { @@ -304,7 +304,7 @@ export class VideoConferenceDeprecatedUc { } protected async isExpert( - currentUser: CurrentUserInterface, + currentUser: ICurrentUser, conferenceScope: VideoConferenceScope, scopeId: string ): Promise { diff --git a/apps/server/src/shared/common/interceptor/request-logging.interceptor.ts b/apps/server/src/shared/common/interceptor/request-logging.interceptor.ts index 29eae6c3567..4e3c256733f 100644 --- a/apps/server/src/shared/common/interceptor/request-logging.interceptor.ts +++ b/apps/server/src/shared/common/interceptor/request-logging.interceptor.ts @@ -1,4 +1,4 @@ -import { CurrentUserInterface } from '@modules/authentication/interface/user'; +import { ICurrentUser } from '@modules/authentication/interface/user'; import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; import { LegacyLogger, RequestLoggingBody } from '@src/core/logger'; import { Request } from 'express'; @@ -13,7 +13,7 @@ export class RequestLoggingInterceptor implements NestInterceptor { this.logger.setContext(`${context.getClass().name}::${context.getHandler().name}()`); const req: Request = context.switchToHttp().getRequest(); - const currentUser = req.user as CurrentUserInterface; + const currentUser = req.user as ICurrentUser; const logging: RequestLoggingBody = { userId: currentUser.userId, request: { diff --git a/apps/server/src/shared/testing/map-user-to-current-user.ts b/apps/server/src/shared/testing/map-user-to-current-user.ts index 7974894d1d2..3c6a1eadc27 100644 --- a/apps/server/src/shared/testing/map-user-to-current-user.ts +++ b/apps/server/src/shared/testing/map-user-to-current-user.ts @@ -1,5 +1,5 @@ import { ObjectId } from '@mikro-orm/mongodb'; -import { CurrentUserInterface } from '@modules/authentication'; +import { ICurrentUser } from '@modules/authentication'; import { Account, EntityId, User } from '@shared/domain'; export const mapUserToCurrentUser = ( @@ -7,8 +7,8 @@ export const mapUserToCurrentUser = ( account?: Account, systemId?: EntityId, impersonated?: boolean -): CurrentUserInterface => { - const currentUser: CurrentUserInterface = { +): ICurrentUser => { + const currentUser: ICurrentUser = { userId: user.id, roles: user.roles.getItems().map((r) => r.id), schoolId: user.school.id,