From a252879964d1a715de8692e3b56d25ad75a910e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 13 Mar 2019 21:03:40 +0100 Subject: [PATCH] Implement obfuscation behaviour --- src/middleware/softDeleteMiddleware.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/middleware/softDeleteMiddleware.js b/src/middleware/softDeleteMiddleware.js index 042219916..24105c435 100644 --- a/src/middleware/softDeleteMiddleware.js +++ b/src/middleware/softDeleteMiddleware.js @@ -13,13 +13,14 @@ const setDefaultFilters = (resolve, root, args, context, info) => { 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 - }) +const obfuscateDisabled = async (resolve, root, args, context, info) => { + if (!isModerator(context) && root.disabled) { + root.content = 'DELETED' + root.contentExcerpt = 'DELETED' + root.title = 'DELETED' + root.image = 'DELETED' + root.avatar = 'DELETED' + root.about = 'DELETED' } return resolve(root, args, context, info) } @@ -38,6 +39,7 @@ export default { } return resolve(root, args, context, info) }, - Post: hideDisabledComments, - User: hideDisabledComments + Post: obfuscateDisabled, + User: obfuscateDisabled, + Comment: obfuscateDisabled }