From 2d603a1467eca50263a0ad2eea427e59da88d263 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 9 Dec 2020 18:45:39 +0100 Subject: [PATCH 1/3] resolve groups + permissions ref #12 --- src/models/actions/CreateAuth.ts | 2 +- src/models/actions/RefreshAuth.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/actions/CreateAuth.ts b/src/models/actions/CreateAuth.ts index 2832e19..d36c17f 100644 --- a/src/models/actions/CreateAuth.ts +++ b/src/models/actions/CreateAuth.ts @@ -28,7 +28,7 @@ export class CreateAuth { if (!this.password) { throw new PasswordNeededError() } - const found_users = await getConnectionManager().get().getRepository(User).find({ where: [{ username: this.username }, { email: this.email }] }); + const found_users = await getConnectionManager().get().getRepository(User).find({ relations: ['groups', 'permissions'], where: [{ username: this.username }, { email: this.email }] }); if (found_users.length === 0) { throw new UserNotFoundError() } else { diff --git a/src/models/actions/RefreshAuth.ts b/src/models/actions/RefreshAuth.ts index 55c124f..77a2728 100644 --- a/src/models/actions/RefreshAuth.ts +++ b/src/models/actions/RefreshAuth.ts @@ -21,7 +21,7 @@ export class RefreshAuth { } catch (error) { throw new IllegalJWTError() } - const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] }); + const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] }, { relations: ['groups', 'permissions'] }); if (!found_user) { throw new UserNotFoundError() } From 02236caa413c3a374c62a30d9cfe0e77e1cb4c91 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 9 Dec 2020 18:46:09 +0100 Subject: [PATCH 2/3] send empty array for user permissions if null ref #12 --- src/models/actions/CreateAuth.ts | 1 + src/models/actions/RefreshAuth.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/models/actions/CreateAuth.ts b/src/models/actions/CreateAuth.ts index d36c17f..b31bee6 100644 --- a/src/models/actions/CreateAuth.ts +++ b/src/models/actions/CreateAuth.ts @@ -35,6 +35,7 @@ export class CreateAuth { const found_user = found_users[0] if (await argon2.verify(found_user.password, this.password + found_user.uuid)) { const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60 + found_user.permissions = found_user.permissions || [] delete found_user.password; newAuth.access_token = jsonwebtoken.sign({ userdetails: found_user, diff --git a/src/models/actions/RefreshAuth.ts b/src/models/actions/RefreshAuth.ts index 77a2728..dacca59 100644 --- a/src/models/actions/RefreshAuth.ts +++ b/src/models/actions/RefreshAuth.ts @@ -28,6 +28,7 @@ export class RefreshAuth { if (found_user.refreshTokenCount !== decoded["refreshtokencount"]) { throw new RefreshTokenCountInvalidError() } + found_user.permissions = found_user.permissions || [] delete found_user.password; const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60 delete found_user.password; From 77b769446ff443cf0538fcdb9bbeb1b56932e881 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 9 Dec 2020 18:59:01 +0100 Subject: [PATCH 3/3] Now throwing errors --- src/controllers/AuthController.ts | 2 +- src/controllers/RunnerController.ts | 2 +- src/controllers/RunnerOrganisationController.ts | 2 +- src/controllers/RunnerTeamController.ts | 2 +- src/controllers/UserController.ts | 2 +- src/controllers/UserGroupController.ts | 2 +- src/models/actions/CreateRunnerTeam.ts | 6 +----- 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/controllers/AuthController.ts b/src/controllers/AuthController.ts index 00380cb..c2002a3 100644 --- a/src/controllers/AuthController.ts +++ b/src/controllers/AuthController.ts @@ -26,7 +26,7 @@ export class AuthController { try { auth = await createAuth.toAuth(); } catch (error) { - return error; + throw error; } return auth } diff --git a/src/controllers/RunnerController.ts b/src/controllers/RunnerController.ts index 9d7a847..0a6ea34 100644 --- a/src/controllers/RunnerController.ts +++ b/src/controllers/RunnerController.ts @@ -54,7 +54,7 @@ export class RunnerController { try { runner = await createRunner.toRunner(); } catch (error) { - return error; + throw error; } runner = await this.runnerRepository.save(runner) diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts index 5636fa6..a0914e3 100644 --- a/src/controllers/RunnerOrganisationController.ts +++ b/src/controllers/RunnerOrganisationController.ts @@ -54,7 +54,7 @@ export class RunnerOrganisationController { try { runnerOrganisation = await createRunnerOrganisation.toRunnerOrganisation(); } catch (error) { - return error; + throw error; } runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation); diff --git a/src/controllers/RunnerTeamController.ts b/src/controllers/RunnerTeamController.ts index 148f16d..be44aac 100644 --- a/src/controllers/RunnerTeamController.ts +++ b/src/controllers/RunnerTeamController.ts @@ -53,7 +53,7 @@ export class RunnerTeamController { try { runnerTeam = await createRunnerTeam.toRunnerTeam(); } catch (error) { - return error; + throw error; } runnerTeam = await this.runnerTeamRepository.save(runnerTeam); diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index f833f54..b5550a2 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -44,7 +44,7 @@ export class UserController { try { user = await createUser.toUser(); } catch (error) { - return error; + throw error; } return this.userRepository.save(user); diff --git a/src/controllers/UserGroupController.ts b/src/controllers/UserGroupController.ts index 70e3c5a..89ef3b9 100644 --- a/src/controllers/UserGroupController.ts +++ b/src/controllers/UserGroupController.ts @@ -43,7 +43,7 @@ export class UserGroupController { try { userGroup = await createUserGroup.toUserGroup(); } catch (error) { - return error; + throw error; } return this.userGroupsRepository.save(userGroup); diff --git a/src/models/actions/CreateRunnerTeam.ts b/src/models/actions/CreateRunnerTeam.ts index 21a6af9..0a4941f 100644 --- a/src/models/actions/CreateRunnerTeam.ts +++ b/src/models/actions/CreateRunnerTeam.ts @@ -35,11 +35,7 @@ export class CreateRunnerTeam extends CreateRunnerGroup { let newRunnerTeam: RunnerTeam = new RunnerTeam(); newRunnerTeam.name = this.name; - try { - newRunnerTeam.parentGroup = await this.getParent(); - } catch (error) { - throw error; - } + newRunnerTeam.parentGroup = await this.getParent(); newRunnerTeam.contact = await this.getContact()