From b00d76542e1fb3d329b116579feaea44992c27e5 Mon Sep 17 00:00:00 2001 From: Roy Scheeren Date: Fri, 2 Feb 2024 10:12:35 +0100 Subject: [PATCH 1/3] fix(envited.ascs.digital): profile guard Signed-off-by: Roy Scheeren --- apps/envited.ascs.digital/common/guards/guards.ts | 4 ++-- .../common/serverActions/profiles/update.ts | 2 +- .../modules/HeroHeader/HeroHeader.tsx | 9 +++++++-- apps/envited.ascs.digital/modules/Users/Users.tsx | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/envited.ascs.digital/common/guards/guards.ts b/apps/envited.ascs.digital/common/guards/guards.ts index f2e0a428..ea3736c9 100644 --- a/apps/envited.ascs.digital/common/guards/guards.ts +++ b/apps/envited.ascs.digital/common/guards/guards.ts @@ -1,4 +1,4 @@ -import { equals, pathOr, prop, propOr } from 'ramda' +import { equals, path, pathOr, prop, propOr } from 'ramda' import { Role, Session, User } from '../../common/types/types' @@ -13,6 +13,6 @@ export const userIsIssuedByLoggedInUser = (user: User) => (session: Session) => equals(prop('issuerId')(user))(pathOr('', ['user', 'pkh'])(session)) export const isOwnProfile = (user: User) => (profile: { name?: string }) => - equals(prop('name')(user))(propOr('', 'name')(profile)) + equals(path(['user', 'name'])(user))(propOr('', 'name')(profile)) export const isUsersCompanyProfile = isOwnProfile diff --git a/apps/envited.ascs.digital/common/serverActions/profiles/update.ts b/apps/envited.ascs.digital/common/serverActions/profiles/update.ts index 4d0f8a5d..fce01929 100644 --- a/apps/envited.ascs.digital/common/serverActions/profiles/update.ts +++ b/apps/envited.ascs.digital/common/serverActions/profiles/update.ts @@ -39,7 +39,7 @@ export const _update = userId: session.user.id, }) } - + if (!isOwnProfile(user)(profile)) { throw forbiddenError({ resource: 'profiles', diff --git a/apps/envited.ascs.digital/modules/HeroHeader/HeroHeader.tsx b/apps/envited.ascs.digital/modules/HeroHeader/HeroHeader.tsx index 03ec1221..42c99d5b 100644 --- a/apps/envited.ascs.digital/modules/HeroHeader/HeroHeader.tsx +++ b/apps/envited.ascs.digital/modules/HeroHeader/HeroHeader.tsx @@ -36,9 +36,11 @@ export const HeroHeader: FC = () => { const user = await insertUser(USER_CREDENTIAL) if (user) { setMessage(`Added ${user.id} as User`) + success('User added') } - } catch (error) { - console.log(error) + } catch (e) { + error('Something went wrong') + console.log(e) } } @@ -46,6 +48,7 @@ export const HeroHeader: FC = () => { try { await insertUser(INVALID_USER_CREDENTIAL) } catch (error: any) { + error('Something went wrong') setMessage(error.message) } } @@ -53,7 +56,9 @@ export const HeroHeader: FC = () => { const update = async () => { try { await updateProfile({ name: 'Testcompany GmbH', description: 'test description' }) + success('Profile updated') } catch (error: any) { + error('Something went wrong') setMessage(error.message) } } diff --git a/apps/envited.ascs.digital/modules/Users/Users.tsx b/apps/envited.ascs.digital/modules/Users/Users.tsx index dd343e33..572f7e01 100644 --- a/apps/envited.ascs.digital/modules/Users/Users.tsx +++ b/apps/envited.ascs.digital/modules/Users/Users.tsx @@ -2,7 +2,7 @@ import { Card, Heading, Table, TableBody, TableCell, TableHeader, TableRow } from '@envited-marketplace/design-system' import { TrashIcon } from '@heroicons/react/24/outline' -import { has, map } from 'ramda' +import { map } from 'ramda' import React, { FC } from 'react' import { useTranslation } from '../../common/i18n' From ea872100965b1e2a448cfe1363af21b489da878e Mon Sep 17 00:00:00 2001 From: Roy Scheeren Date: Fri, 2 Feb 2024 10:12:43 +0100 Subject: [PATCH 2/3] fix(envited.ascs.digital): profile guard Signed-off-by: Roy Scheeren --- .../common/serverActions/profiles/update.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/envited.ascs.digital/common/serverActions/profiles/update.ts b/apps/envited.ascs.digital/common/serverActions/profiles/update.ts index fce01929..4d0f8a5d 100644 --- a/apps/envited.ascs.digital/common/serverActions/profiles/update.ts +++ b/apps/envited.ascs.digital/common/serverActions/profiles/update.ts @@ -39,7 +39,7 @@ export const _update = userId: session.user.id, }) } - + if (!isOwnProfile(user)(profile)) { throw forbiddenError({ resource: 'profiles', From 29de98f0c2bb85a6e6f9671f848776acec789f2b Mon Sep 17 00:00:00 2001 From: Roy Scheeren Date: Fri, 2 Feb 2024 10:34:36 +0100 Subject: [PATCH 3/3] fix(envited.ascs.digital): profile guard Signed-off-by: Roy Scheeren --- apps/envited.ascs.digital/common/guards/guards.ts | 4 ++-- .../common/serverActions/profiles/update.test.ts | 8 ++++++-- .../common/serverActions/profiles/update.ts | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/envited.ascs.digital/common/guards/guards.ts b/apps/envited.ascs.digital/common/guards/guards.ts index ea3736c9..f2e0a428 100644 --- a/apps/envited.ascs.digital/common/guards/guards.ts +++ b/apps/envited.ascs.digital/common/guards/guards.ts @@ -1,4 +1,4 @@ -import { equals, path, pathOr, prop, propOr } from 'ramda' +import { equals, pathOr, prop, propOr } from 'ramda' import { Role, Session, User } from '../../common/types/types' @@ -13,6 +13,6 @@ export const userIsIssuedByLoggedInUser = (user: User) => (session: Session) => equals(prop('issuerId')(user))(pathOr('', ['user', 'pkh'])(session)) export const isOwnProfile = (user: User) => (profile: { name?: string }) => - equals(path(['user', 'name'])(user))(propOr('', 'name')(profile)) + equals(prop('name')(user))(propOr('', 'name')(profile)) export const isUsersCompanyProfile = isOwnProfile diff --git a/apps/envited.ascs.digital/common/serverActions/profiles/update.test.ts b/apps/envited.ascs.digital/common/serverActions/profiles/update.test.ts index ed87458c..34d8c09e 100644 --- a/apps/envited.ascs.digital/common/serverActions/profiles/update.test.ts +++ b/apps/envited.ascs.digital/common/serverActions/profiles/update.test.ts @@ -19,7 +19,9 @@ describe('serverActions/profiles/update', () => { } as any const user = { - name: 'USER_NAME', + user: { + name: 'USER_NAME', + }, profile: { name: 'USER_NAME', }, @@ -52,7 +54,9 @@ describe('serverActions/profiles/update', () => { } as any const user = { - name: 'USER_NAME', + user: { + name: 'USER_NAME', + }, profile: { name: 'USER_NAME', }, diff --git a/apps/envited.ascs.digital/common/serverActions/profiles/update.ts b/apps/envited.ascs.digital/common/serverActions/profiles/update.ts index 4d0f8a5d..fbeb42f7 100644 --- a/apps/envited.ascs.digital/common/serverActions/profiles/update.ts +++ b/apps/envited.ascs.digital/common/serverActions/profiles/update.ts @@ -40,7 +40,7 @@ export const _update = }) } - if (!isOwnProfile(user)(profile)) { + if (!isOwnProfile(user.user)(profile)) { throw forbiddenError({ resource: 'profiles', resourceId: profile.id,