Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If an admin searches for a user by email, don't crash if no user can be found #2295

Merged
merged 1 commit into from Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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