Move into setStatus and other actions when banned and unbanned.

This commit is contained in:
gaba
2016-11-21 17:01:36 -08:00
parent 8355f441e3
commit 0a8ab759b5
6 changed files with 89 additions and 31 deletions
+9 -1
View File
@@ -20,6 +20,7 @@ export default props => {
<i className={`material-icons ${styles.avatar}`}>person</i>
<span>{props.comment.get('name') || lang.t('comment.anon')}</span>
<span className={styles.created}>{timeago().format(props.comment.get('createdAt') || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))}</span>
{props.comment.get('banned') ? <p className={styles.banned}>{lang.t('comment.banned-user')}</p> : null}
{props.comment.get('flagged') ? <p className={styles.flagged}>{lang.t('comment.flagged')}</p> : null}
</div>
<div>
@@ -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;
}
@@ -97,6 +97,12 @@
padding-top: 15px;
padding-left: 10px;
}
.banned {
color: rgba(255, 0, 0, .5);
padding-top: 15px;
padding-left: 10px;
}
}
.empty {
+2
View File
@@ -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": {
+4
View File
@@ -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();
};
+30 -26
View File
@@ -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
}
});
});
}
};
/**
+38 -4
View File
@@ -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');
});
});
});
});
});