Skip to content

Commit

Permalink
fix(envited.ascs.digital): profile guard
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Scheeren <[email protected]>
  • Loading branch information
royscheeren committed Feb 2, 2024
1 parent ab40275 commit b00d765
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/envited.ascs.digital/common/guards/guards.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const _update =
userId: session.user.id,
})
}

if (!isOwnProfile(user)(profile)) {
throw forbiddenError({
resource: 'profiles',
Expand Down
9 changes: 7 additions & 2 deletions apps/envited.ascs.digital/modules/HeroHeader/HeroHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,29 @@ 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)
}
}

const addInvalidUser = async () => {
try {
await insertUser(INVALID_USER_CREDENTIAL)
} catch (error: any) {
error('Something went wrong')
setMessage(error.message)
}
}

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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/envited.ascs.digital/modules/Users/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b00d765

Please sign in to comment.