From 78448b85c180a67f0e64b234146b15630003f6b4 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 9 Dec 2016 15:11:13 -0500 Subject: [PATCH 1/4] Updating to reflect new comment api. --- client/coral-plugin-commentbox/CommentBox.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index 0167d517f..501d2ecc9 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -45,8 +45,7 @@ class CommentBox extends Component { postItem(comment, 'comments') .then((postedComment) => { const commentId = postedComment.id; - const status = postedComment.status; - if (status[0] && status[0].type === 'rejected') { + if (postedComment.status === 'rejected') { addNotification('error', lang.t('comment-post-banned-word')); } else if (premod === 'pre') { addNotification('success', lang.t('comment-post-notif-premod')); From a872128a5582f906af9263788fb9399856c62d34 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Sun, 11 Dec 2016 22:52:47 -0300 Subject: [PATCH 2/4] logOut Stae --- client/coral-embed-stream/src/CommentStream.js | 4 ++-- client/coral-framework/actions/auth.js | 12 +++++++----- client/coral-framework/reducers/auth.js | 7 ++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index 7ec042ea1..b53832ce5 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -91,7 +91,7 @@ class CommentStream extends Component { const rootItem = this.props.items.assets && this.props.items.assets[rootItemId]; const {actions, users, comments} = this.props.items; const {status, moderation, closedMessage} = this.props.config; - const {loggedIn, user, showSignInDialog, signInOffset} = this.props.auth; + const {loggedIn, isAdmin, user, showSignInDialog, signInOffset} = this.props.auth; const {activeTab} = this.state; const banned = (this.props.userData.status === 'banned'); @@ -105,7 +105,7 @@ class CommentStream extends Component { Settings - Configure Stream + Configure Stream {loggedIn && } diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index d027dcd9e..464ae0083 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -20,15 +20,16 @@ export const cleanState = () => ({type: actions.CLEAN_STATE}); // Sign In Actions const signInRequest = () => ({type: actions.FETCH_SIGNIN_REQUEST}); -const signInSuccess = user => ({type: actions.FETCH_SIGNIN_SUCCESS, user}); +const signInSuccess = (user, isAdmin) => ({type: actions.FETCH_SIGNIN_SUCCESS, user, isAdmin}); const signInFailure = error => ({type: actions.FETCH_SIGNIN_FAILURE, error}); export const fetchSignIn = (formData) => dispatch => { dispatch(signInRequest()); coralApi('/auth/local', {method: 'POST', body: formData}) .then(({user}) => { + const isAdmin = !!user.roles.filter(i => i === 'admin').length; + dispatch(signInSuccess(user, isAdmin)); dispatch(hideSignInDialog()); - dispatch(signInSuccess(user)); dispatch(addItem(user, 'users')); }) .catch(() => dispatch(signInFailure(lang.t('error.emailPasswordError')))); @@ -117,7 +118,7 @@ export const invalidForm = error => ({type: actions.INVALID_FORM, error}); // Check Login const checkLoginRequest = () => ({type: actions.CHECK_LOGIN_REQUEST}); -const checkLoginSuccess = user => ({type: actions.CHECK_LOGIN_SUCCESS, user}); +const checkLoginSuccess = (user, isAdmin) => ({type: actions.CHECK_LOGIN_SUCCESS, user, isAdmin}); const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error}); export const checkLogin = () => dispatch => { @@ -125,10 +126,11 @@ export const checkLogin = () => dispatch => { coralApi('/auth') .then(user => { if (!user) { - throw new Error('not logged in'); + throw new Error('Not logged in'); } - dispatch(checkLoginSuccess(user)); + const isAdmin = !!user.roles.filter(i => i === 'admin').length; + dispatch(checkLoginSuccess(user, isAdmin)); }) .catch(error => dispatch(checkLoginFailure(error))); }; diff --git a/client/coral-framework/reducers/auth.js b/client/coral-framework/reducers/auth.js index cf5b25921..d32956b84 100644 --- a/client/coral-framework/reducers/auth.js +++ b/client/coral-framework/reducers/auth.js @@ -4,6 +4,7 @@ import * as actions from '../constants/auth'; const initialState = Map({ isLoading: false, loggedIn: false, + isAdmin: false, user: null, showSignInDialog: false, view: 'SIGNIN', @@ -50,10 +51,12 @@ export default function auth (state = initialState, action) { case actions.CHECK_LOGIN_SUCCESS: return state .set('loggedIn', true) + .set('isAdmin', action.isAdmin) .set('user', purge(action.user)); case actions.FETCH_SIGNIN_SUCCESS: return state .set('loggedIn', true) + .set('isAdmin', action.isAdmin) .set('user', purge(action.user)); case actions.FETCH_SIGNIN_FAILURE: return state @@ -80,9 +83,7 @@ export default function auth (state = initialState, action) { .set('isLoading', false) .set('successSignUp', true); case actions.LOGOUT_SUCCESS: - return state - .set('loggedIn', false) - .set('user', null); + return initialState; case actions.INVALID_FORM: return state .set('error', action.error); From 42ff3ae4a2e55b9b032804cdc0e61a1d628d85d9 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Sun, 11 Dec 2016 23:10:25 -0300 Subject: [PATCH 3/4] filter restricted tabs --- client/coral-ui/components/TabBar.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/client/coral-ui/components/TabBar.js b/client/coral-ui/components/TabBar.js index 1ab7f47a6..2a673f78c 100644 --- a/client/coral-ui/components/TabBar.js +++ b/client/coral-ui/components/TabBar.js @@ -18,14 +18,16 @@ export class TabBar extends React.Component { return (
    - {React.Children.map(children, (child, tabId) => - React.cloneElement(child, { - tabId, - active: tabId === activeTab, - onTabClick: this.handleClickTab, - cStyle - }) - )} + {React.Children.toArray(children) + .filter(child => !child.props.restricted) + .map((child, tabId) => + React.cloneElement(child, { + tabId, + active: tabId === activeTab, + onTabClick: this.handleClickTab, + cStyle + }) + )}
); From cb576dca8f8355043f43fd42f62966014c2257ec Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 12 Dec 2016 15:52:34 -0500 Subject: [PATCH 4/4] Updating signup endpoint to reflect current api. --- client/coral-framework/actions/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index d027dcd9e..e64755435 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -73,7 +73,7 @@ const signUpFailure = error => ({type: actions.FETCH_SIGNUP_FAILURE, error}); export const fetchSignUp = formData => dispatch => { dispatch(signUpRequest()); - coralApi('/user', {method: 'POST', body: formData}) + coralApi('/users', {method: 'POST', body: formData}) .then(({user}) => { dispatch(signUpSuccess(user)); setTimeout(() =>{