diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js b/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js index 44d64219e..1f359a1f7 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js @@ -72,7 +72,8 @@ class ModerationContainer extends Component { + activeTab={moderation.activeTab} + /> { return ; }) } diff --git a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js index eae2f60b2..7a7967aaf 100644 --- a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js +++ b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js @@ -1,4 +1,4 @@ -import React, {PropTypes} from 'react'; +import React from 'react'; import timeago from 'timeago.js'; import Linkify from 'react-linkify'; import Highlighter from 'react-highlight-words'; @@ -14,16 +14,16 @@ import I18n from 'coral-framework/modules/i18n/i18n'; import translations from 'coral-admin/src/translations.json'; const Comment = ({actions = [], ...props}) => { - const links = linkify.getMatches(props.body); + const links = linkify.getMatches(props.comment.body); return (
  • - {props.user.name} + {props.comment.user.name} - {timeago().format(props.created_at || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))} + {timeago().format(props.comment.created_at || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))} {props.flagged ?

    {lang.t('comment.flagged')}

    : null}
    @@ -33,14 +33,14 @@ const Comment = ({actions = [], ...props}) => { {actions.map((action, i) => props.acceptComment({commentId: props.id})} - rejectComment={() => props.rejectComment({commentId: props.id})} - showBanUserDialog={() => props.showBanUserDialog(props.user, props.id)} + user={props.comment.user} + acceptComment={() => props.acceptComment({commentId: props.comment.id})} + rejectComment={() => props.rejectComment({commentId: props.comment.id})} + showBanUserDialog={() => props.showBanUserDialog(props.comment.user, props.comment.id)} /> )}
    - {props.user.banned === 'banned' ? + {props.comment.user.banned === 'banned' ? {lang.t('comment.banned_user')} @@ -50,13 +50,13 @@ const Comment = ({actions = [], ...props}) => {
    - {props.asset.title} Moderate Article + {props.comment.asset.title} Moderate Article

    - +

    @@ -74,9 +74,4 @@ const linkStyles = { padding: '1px 2px' }; -Comment.propTypes = { - user: PropTypes.object.isRequired, - asset: PropTypes.object.isRequired -}; - export default Comment; diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 844b47d3c..98891953c 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -179,19 +179,20 @@ module.exports = (context) => { // TODO: refactor to something that'll return an error in the event an attempt // is made to mutate state while not logged in. There's got to be a better way // to do this. - if (context.user && context.user.can('mutation:createComment', 'mutation:setUserStatus')) { - return { - Comment: { - create: (comment) => createPublicComment(context, comment), - setCommentStatus: (action) => setCommentStatus(context, action) - } - }; - } - - return { + let mutators = { Comment: { create: () => Promise.reject(errors.ErrNotAuthorized), setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized) } }; + + if (context.user && context.user.can('mutation:createComment')) { + mutators.Comment.create = (comment) => createPublicComment(context, comment); + } + + if (context.user && context.user.can('mutation:setCommentStatus')) { + mutators.Comment.setCommentStatus = (action) => setCommentStatus(context, action); + } + + return mutators; }; diff --git a/graph/mutators/user.js b/graph/mutators/user.js index 7c48744d2..2c43f11be 100644 --- a/graph/mutators/user.js +++ b/graph/mutators/user.js @@ -1,3 +1,4 @@ +const errors = require('../../errors'); const UsersService = require('../../services/users'); const setUserStatus = ({user}, {id, status}) => { @@ -20,7 +21,7 @@ module.exports = (context) => { return { User: { - setUserStatus: () => {}, + setUserStatus: () => Promise.reject(errors.ErrNotAuthorized) } }; }; diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 1f10d51d9..4285f900d 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -28,10 +28,10 @@ const RootMutation = { return wrapResponse(null)(Action.delete({id})); }, setUserStatus(_, {id, status}, {mutators: {User}}) { - return User.setUserStatus({id, status}); + return wrapResponse(null)(User.setUserStatus({id, status})); }, setCommentStatus(_, {id, status}, {mutators: {Comment}}) { - return Comment.setCommentStatus({id, status}); + return wrapResponse(null)(Comment.setCommentStatus({id, status})); } }; diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 325fe3b5d..b5c8539ad 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -476,6 +476,22 @@ type DeleteActionResponse implements Response { errors: [UserError] } +# SetUserStatusResponse is the response returned with possibly some errors +# relating to the delete action attempt. +type SetUserStatusResponse implements Response { + + # An array of errors relating to the mutation that occured. + errors: [UserError] +} + +# SetCommentStatusResponse is the response returned with possibly some errors +# relating to the delete action attempt. +type SetCommentStatusResponse implements Response { + + # An array of errors relating to the mutation that occured. + errors: [UserError] +} + # All mutations for the application are defined on this object. type RootMutation { @@ -492,10 +508,10 @@ type RootMutation { deleteAction(id: ID!): DeleteActionResponse # Sets User status - setUserStatus(id: ID!, status: USER_STATUS!): Boolean + setUserStatus(id: ID!, status: USER_STATUS!): SetUserStatusResponse # Sets Comment status - setCommentStatus(id: ID!, status: COMMENT_STATUS!): Boolean + setCommentStatus(id: ID!, status: COMMENT_STATUS!): SetCommentStatusResponse } ################################################################################ diff --git a/models/user.js b/models/user.js index bd18aa4c5..7e04386cd 100644 --- a/models/user.js +++ b/models/user.js @@ -165,6 +165,10 @@ UserSchema.method('can', function(...actions) { return false; } + if (actions.some((action) => action === 'mutation:setUserStatus' || action === 'mutation:setCommentStatus') && !this.hasRoles('ADMIN')) { + return false; + } + return true; });