diff --git a/bin/cli-users b/bin/cli-users index 723d84074..5eba4b691 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -286,6 +286,40 @@ function removeRole(userID, role) { }); } +/** + * Ban a user + * @param {String} userID id of the user to ban + */ +function ban(userID) { + User + .setStatus(userID, 'banned', '') + .then(() => { + console.log(`Banned the User ${userID}.`); + util.shutdown(); + }) + .catch((err) => { + console.error(err); + util.shutdown(1); + }); +} + +/** + * Unban a user + * @param {String} userUD id of the user to remove the role from + */ +function unban(userID) { + User + .setStatus(userID, 'active', '') + .then(() => { + console.log(`Unban the User ${userID}.`); + util.shutdown(); + }) + .catch((err) => { + console.error(err); + util.shutdown(1); + }); +} + /** * Disable a given user. * @param {String} userID the ID of a user to disable @@ -373,6 +407,16 @@ program .description('removes a role from a given user') .action(removeRole); +program + .command('ban ') + .description('ban a given user') + .action(ban); + +program + .command('uban ') + .description('unban a given user') + .action(unban); + program .command('disable ') .description('disable a given user from logging in') diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index a01ceecfd..cac2d1da9 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -1,5 +1,3 @@ -import actions from '../constants/users'; - /** * Action disptacher related to comments */ @@ -19,9 +17,21 @@ export const createComment = (name, body) => dispatch => { }; // Dialog Actions -export const showBanUserDialog = () => (dispatch) => { - dispatch({type: actions.SHOW_BANUSER_DIALOG}); +export const showBanUserDialog = (userId, userName, commentId) => { + return dispatch => { + dispatch({type: 'SHOW_BANUSER_DIALOG', userId, userName, commentId}); + }; }; -export const hideBanUserDialog = () => (dispatch) => { - dispatch({type: actions.HIDE_BANUSER_DIALOG}); + +export const hideBanUserDialog = (showDialog) => { + return dispatch => { + dispatch({type: 'HIDE_BANUSER_DIALOG', showDialog}); + }; +}; + +export const banUser = (status, userId, commentId) => { + return dispatch => { + dispatch({type: 'USER_BAN', status, userId, commentId}); + dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); + }; }; diff --git a/client/coral-admin/src/components/BanUserDialog.js b/client/coral-admin/src/components/BanUserDialog.js index 40813565a..aa9df7780 100644 --- a/client/coral-admin/src/components/BanUserDialog.js +++ b/client/coral-admin/src/components/BanUserDialog.js @@ -9,9 +9,14 @@ import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations'; const lang = new I18n(translations); -const BanUserDialog = ({open, handleClose, authorName}) => ( - - × +const BanUserDialog = ({open, handleClose, onClickBanUser, user}) => { + const userName = (typeof user === 'undefined') ? '' : user['userName']; + const userId = (typeof user === 'undefined') ? '' : user['userId']; + const commentId = (typeof user === 'undefined') ? '' : user['commentId']; + + return ( + handleClose()} onCancel={() => handleClose()} title={lang.t('bandialog.ban_user')}> + handleClose()}>×

@@ -20,21 +25,23 @@ const BanUserDialog = ({open, handleClose, authorName}) => (

- {lang.t('bandialog.are_you_sure', authorName)} + {lang.t('bandialog.are_you_sure', userName)}

{lang.t('bandialog.note')}
- -
-); + ); +}; + export default BanUserDialog; diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js index 0a950d402..a13372dbe 100644 --- a/client/coral-admin/src/components/Comment.js +++ b/client/coral-admin/src/components/Comment.js @@ -9,9 +9,6 @@ import translations from '../translations.json'; import {Icon} from 'react-mdl'; import {FabButton, Button} from 'coral-ui'; -import BanUserDialog from './BanUserDialog'; - -import {showBanUserDialog, hideBanUserDialog} from '../actions/comments'; const linkify = new Linkify(); @@ -53,35 +50,27 @@ export default props => { ); }; +//return props.author.get('status') === 'banned' ? 'disabled' : 'raised'; + // Get the button of the action performed over a comment if any const getActionButton = (action, i, props) => { const status = props.comment.get('status'); const flagged = props.comment.get('flagged'); + const banned = (props.author.get('status') === 'banned'); if (action === 'flag' && (status || flagged === true)) { return null; } if (action === 'ban') { return ( - // -
- - -
- ); + + ); } return ( this.onCommentAction(action, id, author_id)} + onClickAction={(action, commentId) => this.onCommentAction(action, commentId)} + onClickShowBanDialog={(userId, userName, commentId) => this.showBanUserDialog(userId, userName, commentId)} actions={['reject', 'approve', 'ban']} loading={comments.loading} /> - + this.hideBanUserDialog()} + onClickBanUser={(userId, commentId) => this.banUser(userId, commentId)} + user={comments.get('banUser')}/> +
{ case 'COMMENT_FLAG': return flag(state, action); case 'COMMENT_CREATE_SUCCESS': return addComment(state, action); case 'COMMENT_STREAM_FETCH_SUCCESS': return replaceComments(action, state); - case actions.SHOW_BANUSER_DIALOG: - return state - .set('showBanUserDialog', true); - case actions.HIDE_BANUSER_DIALOG: - return state - .set('showBanUserDialog', false); + case actions.SHOW_BANUSER_DIALOG: return setBanUser(state, true, action); + case actions.HIDE_BANUSER_DIALOG: return setBanUser(state, false, action); + case actions.USER_BAN_SUCESS: return setBanUser(state, false, action); default: return state; } }; +// hide or show the UI for the dialog confirming the ban +// set the user that is going to set and the comment that is the reason +const setBanUser = (state, showBanUser, action) => { + const banUser = {'userName': action.userName, 'userId': action.userId, 'commentId': action.commentId}; + return state.set('showBanUserDialog', showBanUser) + .set('banUser', banUser); +}; + // Update a comment status const updateStatus = (state, action) => { const byId = state.get('byId'); diff --git a/client/coral-admin/src/reducers/users.js b/client/coral-admin/src/reducers/users.js index 04375e143..09489ffef 100644 --- a/client/coral-admin/src/reducers/users.js +++ b/client/coral-admin/src/reducers/users.js @@ -3,7 +3,6 @@ import {Map, List, fromJS} from 'immutable'; const initialState = Map({ byId: Map(), ids: List(), - showBanUserDialog: false }); export default (state = initialState, action) => { diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index 0065ce99a..f734d1f72 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -21,8 +21,8 @@ export default store => next => action => { case 'COMMENT_CREATE': createComment(store, action.name, action.body); break; - case 'USER_STATUS_UPDATE': - userStatusUpdate(store, action.author_id, action.status); + case 'USER_BAN': + userStatusUpdate(store, action.status, action.userId, action.commentId); break; } @@ -86,8 +86,8 @@ const createComment = (store, name, comment) => { }; // Ban a user -const userStatusUpdate = (store, author_id, status) => { - coralApi(`/user/${author_id}/status`, {method: 'POST', body: {status: status, comment_id: ''}}) - .then(res => store.dispatch({type: 'USER_BAN_SUCESSS', res})) +const userStatusUpdate = (store, status, userId, commentId) => { + return coralApi(`/user/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}}) + .then(res => store.dispatch({type: 'USER_BAN_SUCESS', res})) .catch(error => store.dispatch({type: 'USER_BAN_FAILED', error})); };