Merge branch 'master' into issue-191

This commit is contained in:
Gabriela Rodríguez Berón
2017-01-06 13:33:25 -03:00
committed by GitHub
56 changed files with 1045 additions and 663 deletions
-7
View File
@@ -11,19 +11,12 @@ export const checkLogin = () => dispatch => {
dispatch(checkLoginRequest());
coralApi('/auth')
.then(result => {
if (result.csrfToken !== null) {
dispatch(check_csrf(result.csrfToken));
}
const isAdmin = !!result.user.roles.filter(i => i === 'admin').length;
dispatch(checkLoginSuccess(result.user, isAdmin));
})
.catch(error => dispatch(checkLoginFailure(error)));
};
// Set CSRF Token
export const check_csrf = (_csrf) => ({type: actions.CHECK_CSRF_TOKEN, _csrf});
// LogOut Actions
const logOutRequest = () => ({type: actions.LOGOUT_REQUEST});
+2 -3
View File
@@ -34,9 +34,8 @@ export const fetchModerationQueueComments = () => {
// Create a new comment
export const createComment = (name, body) => {
return (dispatch, getState) => {
const _csrf = getState().auth.get('_csrf');
const formData = {body, name, _csrf};
return (dispatch) => {
const formData = {body, name};
return coralApi('/comments', {method: 'POST', body: formData})
.then(res => dispatch({type: commentTypes.COMMENT_CREATE_SUCCESS, comment: res}))
.catch(error => dispatch({type: commentTypes.COMMENT_CREATE_FAILED, error}));
+4 -6
View File
@@ -41,18 +41,16 @@ export const newPage = () => ({
type: COMMENTERS_NEW_PAGE
});
export const setRole = (id, role) => (dispatch, getState) => {
export const setRole = (id, role) => (dispatch) => {
const _csrf = getState().auth.get('_csrf');
return coralApi(`/users/${id}/role`, {method: 'POST', body: {role}, _csrf: _csrf})
return coralApi(`/users/${id}/role`, {method: 'POST', body: {role}})
.then(() => {
return dispatch({type: SET_ROLE, id, role});
});
};
export const setCommenterStatus = (id, status) => (dispatch, getState) => {
const _csrf = getState().auth.get('_csrf');
return coralApi(`/users/${id}/status`, {method: 'POST', body: {status}, _csrf: _csrf})
export const setCommenterStatus = (id, status) => (dispatch) => {
return coralApi(`/users/${id}/status`, {method: 'POST', body: {status}})
.then(() => {
return dispatch({type: SET_COMMENTER_STATUS, id, status});
});
+2 -3
View File
@@ -6,10 +6,9 @@ import * as actions from '../constants/user';
*/
// change status of a user
export const userStatusUpdate = (status, userId, commentId) => {
return (dispatch, getState) => {
return (dispatch) => {
dispatch({type: actions.UPDATE_STATUS_REQUEST});
const _csrf = getState().auth.get('_csrf');
return coralApi(`/users/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}, _csrf})
return coralApi(`/users/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}})
.then(res => dispatch({type: actions.UPDATE_STATUS_SUCCESS, res}))
.catch(error => dispatch({type: actions.UPDATE_STATUS_FAILURE, error}));
};
@@ -7,13 +7,13 @@ import {Button} from 'react-mdl';
export default class CommentBox extends React.Component {
constructor (props) {
super(props);
this.state = {name: '', body: '', _csrf: props._csrf};
this.state = {name: '', body: ''};
this.onSubmit = this.onSubmit.bind(this);
}
onSubmit () {
const {name, body, _csrf} = this.state;
this.props.onSubmit({name, body, _csrf});
const {name, body} = this.state;
this.props.onSubmit({name, body});
this.setState({body: '', name: ''});
}
+1 -5
View File
@@ -4,8 +4,7 @@ import * as actions from '../constants/auth';
const initialState = Map({
loggedIn: false,
user: null,
isAdmin: false,
_csrf: ''
isAdmin: false
});
export default function auth (state = initialState, action) {
@@ -26,9 +25,6 @@ export default function auth (state = initialState, action) {
.set('user', action.user);
case actions.LOGOUT_SUCCESS:
return initialState;
case actions.CHECK_CSRF_TOKEN:
return state
.set('_csrf', action._csrf);
default :
return state;
}