mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
I had to trick neo4j-graphql-js to return disabled and deleted fields by default on any neo4j node. If disabled is not queried, then we don't have it in our middleware and we're not able to filter it.
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const isModerator = ({ user }) => {
|
|
return user && (user.role === 'moderator' || user.role === 'admin')
|
|
}
|
|
|
|
const setDefaultFilters = (resolve, root, args, context, info) => {
|
|
if (typeof args.deleted !== 'boolean') {
|
|
args.deleted = false
|
|
}
|
|
|
|
if (!isModerator(context)) {
|
|
args.disabled = false
|
|
}
|
|
return resolve(root, args, context, info)
|
|
}
|
|
|
|
const hideDisabledComments = async (resolve, root, args, context, info) => {
|
|
const { comments } = root
|
|
if (!Array.isArray(comments)) return resolve(root, args, context, info)
|
|
if (!isModerator(context)) {
|
|
root.comments = comments.filter((comment) => {
|
|
return !comment.disabled
|
|
})
|
|
}
|
|
return resolve(root, args, context, info)
|
|
}
|
|
|
|
export default {
|
|
Query: {
|
|
Post: setDefaultFilters,
|
|
Comment: setDefaultFilters,
|
|
User: setDefaultFilters
|
|
},
|
|
Mutation: async (resolve, root, args, context, info) => {
|
|
args.disabled = false
|
|
// TODO: remove as soon as our factories don't need this anymore
|
|
if (typeof args.deleted !== 'boolean') {
|
|
args.deleted = false
|
|
}
|
|
return resolve(root, args, context, info)
|
|
},
|
|
Post: hideDisabledComments,
|
|
User: hideDisabledComments
|
|
}
|