diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index ddbcf9c5d..048e24fac 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -172,7 +172,7 @@ const createPublicComment = async (context, commentInput) => { * @param {String} status the new status of the comment */ -const setCommentStatus = async ({user, loaders: {Comments}}, {id, status}) => { +const setStatus = async ({user, loaders: {Comments}}, {id, status}) => { let comment = await CommentsService.pushStatus(id, status, user ? user.id : null); // If the loaders are present, clear the caches for these values because we @@ -215,7 +215,7 @@ const removeCommentTag = ({user, loaders: {Comments}}, {id, tag}) => { * @param {Object} edit describes how to edit the comment * @param {String} edit.body the new Comment body */ -const editComment = async (context, {id, asset_id, edit: {body}}) => { +const edit = async (context, {id, asset_id, edit: {body}}) => { // Get the wordlist and the settings object. const [wordlist, settings] = await filterNewComment(context, {asset_id, body}); @@ -232,10 +232,10 @@ module.exports = (context) => { let mutators = { Comment: { create: () => Promise.reject(errors.ErrNotAuthorized), - setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized), + setStatus: () => Promise.reject(errors.ErrNotAuthorized), addCommentTag: () => Promise.reject(errors.ErrNotAuthorized), removeCommentTag: () => Promise.reject(errors.ErrNotAuthorized), - editComment: () => Promise.reject(errors.ErrNotAuthorized), + edit: () => Promise.reject(errors.ErrNotAuthorized), } }; @@ -244,7 +244,7 @@ module.exports = (context) => { } if (context.user && context.user.can('mutation:setCommentStatus')) { - mutators.Comment.setCommentStatus = (action) => setCommentStatus(context, action); + mutators.Comment.setStatus = (action) => setStatus(context, action); } if (context.user && context.user.can('mutation:addCommentTag')) { @@ -255,8 +255,8 @@ module.exports = (context) => { mutators.Comment.removeCommentTag = (action) => removeCommentTag(context, action); } - if (context.user) { - mutators.Comment.editComment = (action) => editComment(context, action); + if (context.user && context.user.can('mutation:editComment')) { + mutators.Comment.edit = (action) => edit(context, action); } return mutators; diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index d3cee718c..3ad6fbfd8 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -6,7 +6,7 @@ const RootMutation = { return wrapResponse('comment')(Comment.create(comment)); }, editComment(_, args, {mutators: {Comment}}) { - return wrapResponse('comment')(Comment.editComment(args)); + return wrapResponse('comment')(Comment.edit(args)); }, createFlag(_, {flag: {item_id, item_type, reason, message}}, {mutators: {Action}}) { return wrapResponse('flag')(Action.create({item_id, item_type, action_type: 'FLAG', group_id: reason, metadata: {message}})); @@ -30,7 +30,7 @@ const RootMutation = { return wrapResponse(null)(User.stopIgnoringUser({id})); }, setCommentStatus(_, {id, status}, {mutators: {Comment}}) { - return wrapResponse(null)(Comment.setCommentStatus({id, status})); + return wrapResponse(null)(Comment.setStatus({id, status})); }, addCommentTag(_, {id, tag}, {mutators: {Comment}}) { return wrapResponse('comment')(Comment.addCommentTag({id, tag}).then(() => CommentsService.findById(id))); diff --git a/models/user.js b/models/user.js index 458ac68f0..3544dd309 100644 --- a/models/user.js +++ b/models/user.js @@ -199,7 +199,8 @@ const USER_GRAPH_OPERATIONS = [ 'mutation:suspendUser', 'mutation:setCommentStatus', 'mutation:addCommentTag', - 'mutation:removeCommentTag' + 'mutation:removeCommentTag', + 'mutation:editComment' ]; /**