further tests adapted

This commit is contained in:
Claus-Peter Huebner 2023-06-29 00:00:35 +02:00
parent ddee5707f5
commit 9830afb91c
3 changed files with 13 additions and 7 deletions

View File

@ -35,14 +35,20 @@ export const isAuthorized: AuthChecker<Context> = async ({ context }, rights) =>
where: { gradidoID: decoded.gradidoID },
relations: ['emailContact', 'userRoles'],
})
console.log('isAuthorized user=', user)
// console.log('isAuthorized user=', user)
context.user = user
context.role = user.userRoles
? user.userRoles[0].role === ROLE_NAMES.ROLE_NAME_ADMIN
? ROLE_ADMIN
: ROLE_MODERATOR
: ROLE_USER
if (user.userRoles && user.userRoles.length > 0) {
if (user.userRoles[0].role === ROLE_NAMES.ROLE_NAME_ADMIN) {
context.role = ROLE_ADMIN
} else if (user.userRoles[0].role === ROLE_NAMES.ROLE_NAME_MODERATOR) {
context.role = ROLE_MODERATOR
}
} else {
context.role = ROLE_USER
}
// console.log('context.role=', context.role)
} catch {
// console.log('401 Unauthorized for decoded', decoded)
// in case the database query fails (user deleted)
throw new LogError('401 Unauthorized')
}

View File

@ -20,7 +20,6 @@ export const contributionLinkFactory = async (
mutation: login,
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
})
console.log('contributionlinkfactory user=', user)
const variables = {
amount: contributionLink.amount,
memo: contributionLink.memo,

View File

@ -16,6 +16,7 @@ export class UserRepository extends Repository<DbUser> {
.select(select)
.withDeleted()
.leftJoinAndSelect('user.emailContact', 'emailContact')
.leftJoinAndSelect('user.userRoles', 'userRoles')
.where(
new Brackets((qb) => {
qb.where(