Skip to content

Commit

Permalink
Merge pull request #2295 from Human-Connection/2294_fix_email_filter
Browse files Browse the repository at this point in the history
If an admin searches for a user by email, don't crash if no user can be found
  • Loading branch information
mattwr18 committed Nov 27, 2019
2 parents 2b1f0b1 + b0d20ed commit 62080a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 1 addition & 3 deletions backend/src/middleware/permissionsMiddleware.js
Expand Up @@ -100,7 +100,7 @@ const noEmailFilter = rule({
const publicRegistration = rule()(() => !!CONFIG.PUBLIC_REGISTRATION)

// Permissions
const permissions = shield(
export default shield(
{
Query: {
'*': deny,
Expand Down Expand Up @@ -176,5 +176,3 @@ const permissions = shield(
fallbackRule: allow,
},
)

export default permissions
20 changes: 16 additions & 4 deletions backend/src/schema/resolvers/users.js
Expand Up @@ -49,10 +49,22 @@ export default {
User: async (object, args, context, resolveInfo) => {
const { email } = args
if (email) {
const e = await instance.first('EmailAddress', { email })
let user = e.get('belongsTo')
user = await user.toJson()
return [user.node]
let session
try {
session = context.driver.session()
const readTxResult = await session.readTransaction(txc => {
const result = txc.run(
`
MATCH (user:User)-[:PRIMARY_EMAIL]->(e:EmailAddress {email: $args.email})
RETURN user`,
{ args },
)
return result
})
return readTxResult.records.map(r => r.get('user').properties)
} finally {
session.close()
}
}
return neo4jgraphql(object, args, context, resolveInfo)
},
Expand Down
15 changes: 15 additions & 0 deletions backend/src/schema/resolvers/users.spec.js
Expand Up @@ -70,6 +70,21 @@ describe('User', () => {
data: { User: [{ name: 'Johnny' }] },
})
})

it('non-existing email address, issue #2294', async () => {
// see: https://github.com/Human-Connection/Human-Connection/issues/2294
await expect(
query({
query: userQuery,
variables: {
email: 'this-email-does-not-exist@example.org',
},
}),
).resolves.toMatchObject({
data: { User: [] },
errors: undefined,
})
})
})
})
})
Expand Down

0 comments on commit 62080a0

Please sign in to comment.