mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Merge pull request #2334 from Human-Connection/refactor_is_author_permission
refactor: Close session in isAuthor permission
This commit is contained in:
commit
6865709210
@ -68,21 +68,21 @@ const isAuthor = rule({
|
||||
if (!user) return false
|
||||
const session = driver.session()
|
||||
const { id: resourceId } = args
|
||||
const result = await session.run(
|
||||
`
|
||||
MATCH (resource {id: $resourceId})<-[:WROTE]-(author)
|
||||
RETURN author
|
||||
`,
|
||||
{
|
||||
resourceId,
|
||||
},
|
||||
)
|
||||
session.close()
|
||||
const [author] = result.records.map(record => {
|
||||
return record.get('author')
|
||||
})
|
||||
const authorId = author && author.properties && author.properties.id
|
||||
return authorId === user.id
|
||||
try {
|
||||
const result = await session.run(
|
||||
`
|
||||
MATCH (resource {id: $resourceId})<-[:WROTE]-(author {id: $userId})
|
||||
RETURN author
|
||||
`,
|
||||
{ resourceId, userId: user.id },
|
||||
)
|
||||
const [author] = result.records.map(record => {
|
||||
return record.get('author')
|
||||
})
|
||||
return !!author
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
})
|
||||
|
||||
const isDeletingOwnAccount = rule({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user