mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +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
|
if (!user) return false
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
const { id: resourceId } = args
|
const { id: resourceId } = args
|
||||||
|
try {
|
||||||
const result = await session.run(
|
const result = await session.run(
|
||||||
`
|
`
|
||||||
MATCH (resource {id: $resourceId})<-[:WROTE]-(author)
|
MATCH (resource {id: $resourceId})<-[:WROTE]-(author {id: $userId})
|
||||||
RETURN author
|
RETURN author
|
||||||
`,
|
`,
|
||||||
{
|
{ resourceId, userId: user.id },
|
||||||
resourceId,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
session.close()
|
|
||||||
const [author] = result.records.map(record => {
|
const [author] = result.records.map(record => {
|
||||||
return record.get('author')
|
return record.get('author')
|
||||||
})
|
})
|
||||||
const authorId = author && author.properties && author.properties.id
|
return !!author
|
||||||
return authorId === user.id
|
} finally {
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const isDeletingOwnAccount = rule({
|
const isDeletingOwnAccount = rule({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user