From 1dec8bfaab20ad59edb90ab975d347044ae90b1d Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 16 Jun 2017 09:45:26 -0400 Subject: [PATCH 1/7] small fix --- bin/cli-users | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/cli-users b/bin/cli-users index fccb4b8bb..057c0a806 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -8,6 +8,7 @@ const program = require('./commander'); const inquirer = require('inquirer'); const UsersService = require('../services/users'); const UserModel = require('../models/user'); +const USER_ROLES = require('../models/enum/user_roles'); const mongoose = require('../services/mongoose'); const util = require('./util'); const Table = require('cli-table'); @@ -36,7 +37,7 @@ function getUserCreateAnswers(options) { roles: [] }; - if (options.role && UserModel.USER_ROLES.indexOf(options.role) > -1) { + if (options.role && USER_ROLES.indexOf(options.role) > -1) { user.roles = [options.role]; } @@ -89,7 +90,7 @@ function getUserCreateAnswers(options) { name: 'roles', message: 'User Role', type: 'checkbox', - choices: UserModel.USER_ROLES + choices: USER_ROLES } ]); } @@ -291,8 +292,8 @@ function mergeUsers(dstUserID, srcUserID) { */ function addRole(userID, role) { - if (UserModel.USER_ROLES.indexOf(role) === -1) { - console.error(`Role '${role}' is not supported. Supported roles are ${UserModel.USER_ROLES.join(', ')}.`); + if (USER_ROLES.indexOf(role) === -1) { + console.error(`Role '${role}' is not supported. Supported roles are ${USER_ROLES.join(', ')}.`); util.shutdown(1); return; } @@ -316,8 +317,8 @@ function addRole(userID, role) { */ function removeRole(userID, role) { - if (UserModel.USER_ROLES.indexOf(role) === -1) { - console.error(`Role '${role}' is not supported. Supported roles are ${UserModel.USER_ROLES.join(', ')}.`); + if (USER_ROLES.indexOf(role) === -1) { + console.error(`Role '${role}' is not supported. Supported roles are ${USER_ROLES.join(', ')}.`); util.shutdown(1); return; } From 613982884479bb53ff55f220973c36868f13cc88 Mon Sep 17 00:00:00 2001 From: Max Eddy Date: Tue, 6 Jun 2017 15:31:50 -0400 Subject: [PATCH 2/7] Send post message with auth state to parent window. --- client/coral-embed/src/index.js | 4 ++++ client/coral-framework/actions/auth.js | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index 65e77ad1d..47c761bd3 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,6 +54,10 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } + pymParent.onMessage('checkLogin', function(result) { + console.log(JSON.parse(result)); + }); + // Sends config to the child pymParent.onMessage('getConfig', function() { sendConfig(opts || {}); diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index eaaee3034..e4871a7e2 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -3,6 +3,7 @@ import bowser from 'bowser'; import * as actions from '../constants/auth'; import * as Storage from '../helpers/storage'; import coralApi, {base} from '../helpers/request'; +import pym from '../services/PymConnection'; import {resetWebsocket} from 'coral-framework/services/client'; import t from 'coral-framework/services/i18n'; @@ -300,7 +301,7 @@ const checkLoginSuccess = (user, isAdmin) => ({ isAdmin }); -export const checkLogin = () => (dispatch) => { +export const checkLogin = () => (dispatch, getState) => { dispatch(checkLoginRequest()); coralApi('/auth') .then((result) => { @@ -324,6 +325,9 @@ export const checkLogin = () => (dispatch) => { .catch((error) => { console.error(error); dispatch(checkLoginFailure(`${error.translation_key}`)); + }) + .then(() => { + pym.sendMessage('checkLogin', JSON.stringify(getState().auth)); }); }; From fd9b14a560fb306db7459f59d90ea15fd423bcc4 Mon Sep 17 00:00:00 2001 From: Max Eddy Date: Tue, 6 Jun 2017 15:54:28 -0400 Subject: [PATCH 3/7] cb option for auth change event --- client/coral-embed/src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index 47c761bd3..d90591f2f 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -55,7 +55,9 @@ function configurePymParent(pymParent, opts) { } pymParent.onMessage('checkLogin', function(result) { - console.log(JSON.parse(result)); + if (opts.onAuthChange) { + opts.onAuthChange(JSON.parse(result)); + } }); // Sends config to the child From 4982d8a9adbf9f20fb56547d35cc49de94bbf42b Mon Sep 17 00:00:00 2001 From: Max Eddy Date: Thu, 8 Jun 2017 11:22:07 -0400 Subject: [PATCH 4/7] Use REST API result for check login message. --- client/coral-embed/src/index.js | 6 +++--- client/coral-framework/actions/auth.js | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index d90591f2f..c6c29c30e 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,9 +54,9 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } - pymParent.onMessage('checkLogin', function(result) { - if (opts.onAuthChange) { - opts.onAuthChange(JSON.parse(result)); + pymParent.onMessage('coral-check-login', function(result) { + if (opts.onCheckLogin) { + opts.onCheckLogin(JSON.parse(result)); } }); diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index e4871a7e2..13a1bc24e 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -301,10 +301,12 @@ const checkLoginSuccess = (user, isAdmin) => ({ isAdmin }); -export const checkLogin = () => (dispatch, getState) => { +export const checkLogin = () => (dispatch) => { dispatch(checkLoginRequest()); coralApi('/auth') .then((result) => { + pym.sendMessage('coral-check-login', JSON.stringify(result)); + if (!result.user) { if (!bowser.safari && !bowser.ios) { Storage.removeItem('token'); @@ -325,9 +327,6 @@ export const checkLogin = () => (dispatch, getState) => { .catch((error) => { console.error(error); dispatch(checkLoginFailure(`${error.translation_key}`)); - }) - .then(() => { - pym.sendMessage('checkLogin', JSON.stringify(getState().auth)); }); }; From fe0c581ea926ee49dd5f2e91098965937a164c70 Mon Sep 17 00:00:00 2001 From: Max Eddy Date: Thu, 8 Jun 2017 13:05:34 -0400 Subject: [PATCH 5/7] Note logout action as well for onAuthChanged event. --- client/coral-embed/src/index.js | 12 ++++++++---- client/coral-framework/actions/auth.js | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index c6c29c30e..0a901c341 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,11 +54,15 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } - pymParent.onMessage('coral-check-login', function(result) { - if (opts.onCheckLogin) { - opts.onCheckLogin(JSON.parse(result)); + function onAuthChanged(message) { + if (opts.onAuthChanged) { + opts.onAuthChanged(message ? JSON.parse(message) : null); } - }); + } + + pymParent.onMessage('coral-login', onAuthChanged); + + pymParent.onMessage('coral-logout', onAuthChanged); // Sends config to the child pymParent.onMessage('getConfig', function() { diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 13a1bc24e..b7ec4ee4c 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -285,6 +285,7 @@ export const logout = () => (dispatch) => { resetWebsocket(); dispatch({type: actions.LOGOUT}); + pym.sendMessage('coral-logout'); }); }; @@ -305,7 +306,6 @@ export const checkLogin = () => (dispatch) => { dispatch(checkLoginRequest()); coralApi('/auth') .then((result) => { - pym.sendMessage('coral-check-login', JSON.stringify(result)); if (!result.user) { if (!bowser.safari && !bowser.ios) { @@ -318,6 +318,7 @@ export const checkLogin = () => (dispatch) => { resetWebsocket(); dispatch(checkLoginSuccess(result.user)); + pym.sendMessage('coral-login', JSON.stringify(result.user)); // Display create username dialog if necessary. if (result.user.canEditName && result.user.status !== 'BANNED') { From 64174b97aff710d10b61a945a6c6919be1078b5b Mon Sep 17 00:00:00 2001 From: Max Eddy Date: Thu, 8 Jun 2017 13:20:30 -0400 Subject: [PATCH 6/7] Cleanup --- client/coral-embed/src/index.js | 8 ++------ client/coral-framework/actions/auth.js | 5 ++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index 0a901c341..14de2756e 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,15 +54,11 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } - function onAuthChanged(message) { + pymParent.onMessage('coral-auth-changed', function(message) { if (opts.onAuthChanged) { opts.onAuthChanged(message ? JSON.parse(message) : null); } - } - - pymParent.onMessage('coral-login', onAuthChanged); - - pymParent.onMessage('coral-logout', onAuthChanged); + }); // Sends config to the child pymParent.onMessage('getConfig', function() { diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index b7ec4ee4c..614b87632 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -285,7 +285,7 @@ export const logout = () => (dispatch) => { resetWebsocket(); dispatch({type: actions.LOGOUT}); - pym.sendMessage('coral-logout'); + pym.sendMessage('coral-auth-changed'); }); }; @@ -306,7 +306,6 @@ export const checkLogin = () => (dispatch) => { dispatch(checkLoginRequest()); coralApi('/auth') .then((result) => { - if (!result.user) { if (!bowser.safari && !bowser.ios) { Storage.removeItem('token'); @@ -318,7 +317,7 @@ export const checkLogin = () => (dispatch) => { resetWebsocket(); dispatch(checkLoginSuccess(result.user)); - pym.sendMessage('coral-login', JSON.stringify(result.user)); + pym.sendMessage('coral-auth-changed', JSON.stringify(result.user)); // Display create username dialog if necessary. if (result.user.canEditName && result.user.status !== 'BANNED') { From dfccf962d4ea2b08dd7bbac75985b2349e6fcb3e Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Fri, 16 Jun 2017 17:30:09 -0400 Subject: [PATCH 7/7] Update version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4295f5c25..1109acf7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "talk", - "version": "2.0.0", + "version": "2.0.1", "description": "A better commenting experience from Mozilla, The New York Times, and the Washington Post. https://coralproject.net", "main": "app.js", "scripts": {