diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js index 4f7aebd74..ba2c8b11d 100644 --- a/client/coral-admin/src/components/Comment.js +++ b/client/coral-admin/src/components/Comment.js @@ -1,4 +1,3 @@ - import React from 'react'; import timeago from 'timeago.js'; import styles from './CommentList.css'; @@ -6,6 +5,7 @@ import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations.json'; import Linkify from 'react-linkify'; import {FabButton} from 'coral-ui'; +import {Icon} from 'react-mdl'; const linkify = new Linkify(); diff --git a/client/coral-admin/src/containers/Community/Community.js b/client/coral-admin/src/containers/Community/Community.js index 0a15721aa..374b7dd6b 100644 --- a/client/coral-admin/src/containers/Community/Community.js +++ b/client/coral-admin/src/containers/Community/Community.js @@ -31,7 +31,6 @@ const tableHeaders = [ ]; const Community = ({isFetching, commenters, ...props}) => { - console.log(commenters); const hasResults = !isFetching && !!commenters.length; return ( diff --git a/models/comment.js b/models/comment.js index 62b18e6ba..526f14eef 100644 --- a/models/comment.js +++ b/models/comment.js @@ -1,7 +1,6 @@ const mongoose = require('../mongoose'); const uuid = require('uuid'); const Action = require('./action'); -const User = require('./user'); const Schema = mongoose.Schema; @@ -40,9 +39,6 @@ const CommentSchema = new Schema({ * @param {String} body content of comment */ CommentSchema.statics.new = function(body, author_id, asset_id, parent_id, status, username) { - if (username === null && author_id != null) { - username = User.findById(author_id)['displayName'] - }; let comment = new Comment({body, author_id, asset_id, parent_id, status, username}); return comment.save(); }; @@ -163,13 +159,16 @@ CommentSchema.statics.moderationQueue = function(moderation) { //============================================================================== /** - * Set the status of a comment. + * Changes the status of a comment. * @param {String} id identifier of the comment (uuid) * @param {String} status the new status of the comment - * @return {Promise} -*/ + * @return {Promise} + */ CommentSchema.statics.changeStatus = function(id, status) { - return Comment.findOneAndUpdate({'id': id}, {$set: {'status': status}}); + return Comment.findOneAndUpdate({'id': id}, {$set: {'status': status}}, {upsert: false, new: true}) + .then((comment) => { + return comment; + }); }; /** diff --git a/models/user.js b/models/user.js index 933556db6..5048cb805 100644 --- a/models/user.js +++ b/models/user.js @@ -425,15 +425,16 @@ UserService.setStatus = (id, status, comment_id) => { if (status === 'banned') { return UserService.disableUser(id) .then(() => { - return Comment.setStatus(comment_id, 'rejected').then(() => { - return UserModel.update({ - id: id - }, { - $set: { - status: status - } + return Comment.changeStatus(comment_id, 'rejected') + .then(() => { + return UserModel.update({ + id: id + }, { + $set: { + status: status + } + }); }); - }); }); } diff --git a/tests/models/user.js b/tests/models/user.js index 434cd1f58..d0886a2e8 100644 --- a/tests/models/user.js +++ b/tests/models/user.js @@ -140,7 +140,7 @@ describe('User: models', () => { }); }); - it('should not still disable and ban the user if there is no comment', () => { + it('should still disable and ban the user if there is no comment', () => { return User .setStatus(mockUsers[0].id, 'banned', '') .then(() => {