diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js
index 273419245..f43670923 100644
--- a/client/coral-admin/src/components/Comment.js
+++ b/client/coral-admin/src/components/Comment.js
@@ -20,6 +20,7 @@ export default props => {
person
{props.comment.get('name') || lang.t('comment.anon')}
{timeago().format(props.comment.get('createdAt') || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))}
+ {props.comment.get('banned') ?
{lang.t('comment.banned-user')}
: null}
{props.comment.get('flagged') ? {lang.t('comment.flagged')}
: null}
@@ -50,9 +51,16 @@ export default props => {
// Check if an action can be performed over a comment
const canShowAction = (action, comment) => {
- const status = comment.get('status');
+ const status = comment.get('status'); // accepted
const flagged = comment.get('flagged');
+ const banned = comment.get('banned');
+ // If the user that authored the comment is banned then do not ban it again.
+ if (action === 'ban' && !banned) {
+ return false;
+ }
+
+ // If it is flagged do not flag it .
if (action === 'flag' && (status || flagged === true)) {
return false;
}
diff --git a/client/coral-admin/src/components/CommentList.css b/client/coral-admin/src/components/CommentList.css
index 2c58c81cf..613238e27 100644
--- a/client/coral-admin/src/components/CommentList.css
+++ b/client/coral-admin/src/components/CommentList.css
@@ -97,6 +97,12 @@
padding-top: 15px;
padding-left: 10px;
}
+
+ .banned {
+ color: rgba(255, 0, 0, .5);
+ padding-top: 15px;
+ padding-left: 10px;
+ }
}
.empty {
diff --git a/client/coral-admin/src/translations.json b/client/coral-admin/src/translations.json
index f1e6fd680..ff500f0e8 100644
--- a/client/coral-admin/src/translations.json
+++ b/client/coral-admin/src/translations.json
@@ -12,6 +12,7 @@
"select-status": "Select status...",
"active": "Active",
"banned": "Banned",
+ "banned-user": "Banned User",
"loading": "Loading results"
},
"modqueue": {
@@ -63,6 +64,7 @@
"select-status": "Seleccionar estado...",
"active": "Activa",
"banned": "Suspendido",
+ "banned-user": "Usuario Suspendido",
"loading": "Cargando resultados"
},
"modqueue": {
diff --git a/models/comment.js b/models/comment.js
index bf13eff82..4c01c8b94 100644
--- a/models/comment.js
+++ b/models/comment.js
@@ -1,6 +1,7 @@
const mongoose = require('../mongoose');
const uuid = require('uuid');
const Action = require('./action');
+const User = require('./user');
const Schema = mongoose.Schema;
@@ -40,6 +41,9 @@ 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();
};
diff --git a/models/user.js b/models/user.js
index 652383302..45d338090 100644
--- a/models/user.js
+++ b/models/user.js
@@ -409,9 +409,10 @@ UserService.removeRoleFromUser = (id, role) => {
* Set status of a user.
* @param {String} id id of a user
* @param {String} status status to set
+ * @param {String} comment_id id of the comment that the user was ban for.
* @param {Function} done callback after the operation is complete
*/
-UserService.setStatus = (id, status) => {
+UserService.setStatus = (id, status, comment_id) => {
// Check to see if the user status is in the allowable set of roles.
if (USER_STATUS.indexOf(status) === -1) {
@@ -420,32 +421,35 @@ UserService.setStatus = (id, status) => {
return Promise.reject(new Error(`status ${status} is not supported`));
}
- return UserModel.update({
- id: id
- }, {
- $set: {
- status: status
- }
- });
-};
-
-/**
- * Ban a user.
- * @param {String} id id of a user
- * @param {String} comment_id id of the comment that the user was ban for.
- * @param {Function} done callback after the operation is complete
- */
-UserService.ban = (id, comment_id) => {
- // Disable their account
- return UserService.disableUser(id)
- .then(() => {
- // Set status of the user to banned
- return UserService.setStatus(id, 'banned').then(() => {
- // Only if it was rejected based on a specific comment.
- // Reject the comment that the user was ban for.
- return Comment.setStatus(comment_id, 'rejected');
+ // If ban then disable the account, reject the comment and update status
+ if (status === 'banned') {
+ return UserService.disableUser(id)
+ .then(() => {
+ return Comment.setStatus(comment_id, 'rejected').then(() => {
+ return UserModel.update({
+ id: id
+ }, {
+ $set: {
+ status: status
+ }
+ });
+ });
});
- });
+ }
+
+ // If active then unable the account and update status
+ if (status === 'active') {
+ return UserService.enableUser(id)
+ .then(() => {
+ return UserModel.update({
+ id: id
+ }, {
+ $set: {
+ status: status
+ }
+ });
+ });
+ }
};
/**
diff --git a/tests/models/user.js b/tests/models/user.js
index 76024fc67..be7fd2f53 100644
--- a/tests/models/user.js
+++ b/tests/models/user.js
@@ -90,7 +90,7 @@ describe('User: models', () => {
it('should disable the user', () => {
return User
- .ban(mockUsers[0].id, mockComment.id)
+ .setStatus(mockUsers[0].id, 'banned', mockComment.id)
.then(() => {
User.findById(mockUsers[0].id)
.then((user) => {
@@ -102,7 +102,7 @@ describe('User: models', () => {
it('should set the status to banned', () => {
return User
- .ban(mockUsers[0].id, mockComment.id)
+ .setStatus(mockUsers[0].id, 'banned', mockComment.id)
.then(() => {
User.findById(mockUsers[0].id)
.then((user) => {
@@ -114,7 +114,7 @@ describe('User: models', () => {
it('should set the comment to rejected', () => {
return User
- .ban(mockUsers[0].id, mockComment.id)
+ .setStatus(mockUsers[0].id, 'banned', mockComment.id)
.then(() => {
Comment.findById(mockComment.id)
.then((comment) => {
@@ -126,7 +126,7 @@ describe('User: models', () => {
it('should not still disable and ban the user if there is no comment', () => {
return User
- .ban(mockUsers[0].id, '')
+ .setStatus(mockUsers[0].id, 'banned', '')
.then(() => {
User.findById(mockUsers[0].id)
.then((user) => {
@@ -138,4 +138,38 @@ describe('User: models', () => {
});
});
});
+
+ describe('#unban', () => {
+ let mockComment;
+ beforeEach(() => {
+ return Comment.new('testing the comment for that user if it is rejected.', mockUsers[0].id)
+ .then((comment) => {
+ mockComment = comment;
+ });
+ });
+
+ it('should enable the user', () => {
+ return User
+ .setStatus(mockUsers[0].id, 'active', mockComment.id)
+ .then(() => {
+ User.findById(mockUsers[0].id)
+ .then((user) => {
+ expect(user).to.have.property('disabled')
+ .and.to.equal(false);
+ });
+ });
+ });
+
+ it('should set the status to active', () => {
+ return User
+ .setStatus(mockUsers[0].id, 'active', mockComment.id)
+ .then(() => {
+ User.findById(mockUsers[0].id)
+ .then((user) => {
+ expect(user).to.have.property('status')
+ .and.to.equal('active');
+ });
+ });
+ });
+ });
});