{children}
diff --git a/client/coral-admin/src/components/ui/Logo.css b/client/coral-admin/src/components/ui/Logo.css
index e764af627..f89bf3d5d 100644
--- a/client/coral-admin/src/components/ui/Logo.css
+++ b/client/coral-admin/src/components/ui/Logo.css
@@ -1,7 +1,9 @@
.logo h1 {
color: #272727;
font-size: 20px;
- padding: 0 30px;
+ margin: 0;
+ line-height: 60px;
+ padding: 0 20px;
}
.logo span {
@@ -13,6 +15,7 @@
.logo {
background: #E5E5E5;
+ height: 100%;
}
diff --git a/client/coral-admin/src/containers/LayoutContainer.js b/client/coral-admin/src/containers/LayoutContainer.js
index 5f3cb0cff..f263c33f5 100644
--- a/client/coral-admin/src/containers/LayoutContainer.js
+++ b/client/coral-admin/src/containers/LayoutContainer.js
@@ -1,37 +1,31 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {Layout} from '../components/ui/Layout';
-import {checkLogin} from '../actions/auth';
-import {NotFound} from '../components/NotFound';
+import {checkLogin, logout} from '../actions/auth';
+import {FullLoading} from '../components/FullLoading';
import {PermissionRequired} from '../components/PermissionRequired';
class LayoutContainer extends Component {
componentWillMount () {
- this.props.checkLogin();
+ const {checkLogin} = this.props;
+ checkLogin();
}
render () {
- const {isAdmin, loggedIn} = this.props.auth;
-
- if (!loggedIn) {
- return
;
- }
-
- if (!isAdmin && loggedIn) {
- return
;
- }
-
- return
;
+ const {isAdmin, loggedIn, loadingUser} = this.props.auth;
+ if (loadingUser) { return
; }
+ if (!isAdmin) { return
; }
+ if (isAdmin && loggedIn) { return
; }
+ return
;
}
}
-LayoutContainer.propTypes = {};
-
const mapStateToProps = state => ({
auth: state.auth.toJS()
});
const mapDispatchToProps = dispatch => ({
checkLogin: () => dispatch(checkLogin()),
+ handleLogout: () => dispatch(logout())
});
export default connect(
diff --git a/client/coral-admin/src/reducers/auth.js b/client/coral-admin/src/reducers/auth.js
index 59dccac5e..f897c1bae 100644
--- a/client/coral-admin/src/reducers/auth.js
+++ b/client/coral-admin/src/reducers/auth.js
@@ -9,19 +9,25 @@ const initialState = Map({
export default function auth (state = initialState, action) {
switch (action.type) {
+ case actions.CHECK_LOGIN_REQUEST:
+ return state
+ .set('loadingUser', true);
case actions.CHECK_LOGIN_FAILURE:
return state
.set('loggedIn', false)
+ .set('loadingUser', false)
.set('user', null);
case actions.CHECK_LOGIN_SUCCESS:
return state
.set('loggedIn', true)
+ .set('loadingUser', false)
.set('isAdmin', action.isAdmin)
.set('user', action.user);
case actions.LOGOUT_SUCCESS:
return state
.set('loggedIn', false)
- .set('user', null);
+ .set('user', null)
+ .set('isAdmin', false);
default :
return state;
}
diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js
index dfdcec342..d8385c0dd 100644
--- a/client/coral-admin/src/services/talk-adapter.js
+++ b/client/coral-admin/src/services/talk-adapter.js
@@ -1,3 +1,4 @@
+import {base, handleResp, getInit} from '../helpers/response';
/**
* The adapter is a redux middleware that interecepts the actions that need
@@ -7,9 +8,6 @@
* for the coral but also for wordpress comments, disqus and many more.
*/
-// Default headers for json payloads.
-const jsonHeader = new Headers({'Content-Type': 'application/json'});
-
// Intercept redux actions and act over the ones we are interested
export default store => next => action => {
@@ -35,11 +33,11 @@ export default store => next => action => {
const fetchModerationQueueComments = store =>
Promise.all([
- fetch('/api/v1/queue/comments/pending'),
- fetch('/api/v1/comments?status=rejected'),
- fetch('/api/v1/comments?action_type=flag')
+ fetch(`${base}/queue/comments/pending`, getInit('GET')),
+ fetch(`${base}/comments?status=rejected`, getInit('GET')),
+ fetch(`${base}/comments?action_type=flag`, getInit('GET'))
])
-.then(res => Promise.all(res.map(r => r.json())))
+.then(res => Promise.all(res.map(handleResp)))
.then(res => {
res[2] = res[2].map(comment => { comment.flagged = true; return comment; });
return res.reduce((prev, curr) => prev.concat(curr), []);
@@ -55,26 +53,22 @@ Promise.all([
// Update a comment. Now to update a comment we need to send back the whole object
const updateComment = (store, comment) => {
- fetch(`/api/v1/comments/${comment.get('id')}/status`, {
- method: 'PUT',
- headers: jsonHeader,
- body: JSON.stringify({status: comment.get('status')})
- })
- .then(res => res.json())
+ fetch(`${base}/comments/${comment.get('id')}/status`, getInit('PUT', {status: comment.get('status')}))
+ .then(handleResp)
.then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res}))
.catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error}));
};
// Create a new comment
-const createComment = (store, name, comment) =>
-fetch('/api/v1/comments', {
- method: 'POST',
- body: JSON.stringify({
+const createComment = (store, name, comment) => {
+ const body = {
status: 'Untouched',
body: comment,
name: name,
createdAt: Date.now()
- })
-}).then(res => res.json())
-.then(res => store.dispatch({type: 'COMMENT_CREATE_SUCCESS', comment: res}))
-.catch(error => store.dispatch({type: 'COMMENT_CREATE_FAILED', error}));
+ };
+ return fetch(`${base}/comments`, getInit('POST', body))
+ .then(handleResp)
+ .then(res => store.dispatch({type: 'COMMENT_CREATE_SUCCESS', comment: res}))
+ .catch(error => store.dispatch({type: 'COMMENT_CREATE_FAILED', error}));
+};
diff --git a/client/coral-framework/actions/items.js b/client/coral-framework/actions/items.js
index f922280c1..4af6dd1b1 100644
--- a/client/coral-framework/actions/items.js
+++ b/client/coral-framework/actions/items.js
@@ -104,20 +104,18 @@ export function getStream (assetUrl) {
.then((json) => {
/* Add items to the store */
- const itemTypes = Object.keys(json);
- for (let i = 0; i < itemTypes.length; i++ ) {
- if (itemTypes[i] === 'actions') {
- for (let j = 0; j < json[itemTypes[i]].length; j++ ) {
- let action = json[itemTypes[i]][j];
+ Object.keys(json).forEach(type => {
+ if (type === 'actions') {
+ json[type].forEach(action => {
action.id = `${action.action_type}_${action.item_id}`;
dispatch(addItem(action, 'actions'));
- }
+ });
} else {
- for (let j = 0; j < json[itemTypes[i]].length; j++ ) {
- dispatch(addItem(json[itemTypes[i]][j], itemTypes[i]));
- }
+ json[type].forEach(item => {
+ dispatch(addItem(item, type));
+ });
}
- }
+ });
const assetId = json.assets[0].id;
@@ -140,15 +138,14 @@ export function getStream (assetUrl) {
dispatch(updateItem(assetId, 'comments', rels.rootComments, 'assets'));
- const childKeys = Object.keys(rels.childComments);
- for (let i = 0; i < childKeys.length; i++ ) {
- dispatch(updateItem(childKeys[i], 'children', rels.childComments[childKeys[i]].reverse(), 'comments'));
- }
+ Object.keys(rels.childComments).forEach(key => {
+ dispatch(updateItem(key, 'children', rels.childComments[key].reverse(), 'comments'));
+ });
/* Hydrate actions on comments */
- for (let i = 0; i < json.actions.length; i++ ) {
- dispatch(updateItem(json.actions[i].item_id, json.actions[i].action_type, json.actions[i].id, 'comments'));
- }
+ json.actions.forEach(action => {
+ dispatch(updateItem(action.item_id, action.action_type, action.id, 'comments'));
+ });
return (json);
});
diff --git a/kue.js b/kue.js
new file mode 100644
index 000000000..e2229d424
--- /dev/null
+++ b/kue.js
@@ -0,0 +1,11 @@
+const kue = require('kue');
+const redis = require('./redis');
+
+module.exports = {
+ queue: kue.createQueue({
+ redis: {
+ createClientFactory: () => redis.createClient()
+ }
+ }),
+ kue
+};
diff --git a/redis.js b/redis.js
index c37fcc64e..9f67c34bb 100644
--- a/redis.js
+++ b/redis.js
@@ -2,38 +2,42 @@ const redis = require('redis');
const debug = require('debug')('talk:redis');
const url = process.env.TALK_REDIS_URL || 'redis://localhost';
-const client = redis.createClient(url, {
- retry_strategy: function(options) {
- if (options.error && options.error.code === 'ECONNREFUSED') {
+module.exports = {
+ createClient() {
+ let client = redis.createClient(url, {
+ retry_strategy: function(options) {
+ if (options.error && options.error.code === 'ECONNREFUSED') {
- // End reconnecting on a specific error and flush all commands with a individual error
- return new Error('The server refused the connection');
- }
- if (options.total_retry_time > 1000 * 60 * 60) {
+ // End reconnecting on a specific error and flush all commands with a individual error
+ return new Error('The server refused the connection');
+ }
+ if (options.total_retry_time > 1000 * 60 * 60) {
- // End reconnecting after a specific timeout and flush all commands with a individual error
- return new Error('Retry time exhausted');
- }
+ // End reconnecting after a specific timeout and flush all commands with a individual error
+ return new Error('Retry time exhausted');
+ }
- if (options.times_connected > 10) {
+ if (options.times_connected > 10) {
- // End reconnecting with built in error
- return undefined;
- }
+ // End reconnecting with built in error
+ return undefined;
+ }
- // reconnect after
- return Math.max(options.attempt * 100, 3000);
+ // reconnect after
+ return Math.max(options.attempt * 100, 3000);
+ }
+ });
+
+ client.ping((err) => {
+ if (err) {
+ console.error('Can\'t ping the redis server!');
+
+ throw err;
+ }
+
+ debug('connection established');
+ });
+
+ return client;
}
-});
-
-client.ping((err) => {
- if (err) {
- console.error('Can\'t ping the redis server!');
-
- throw err;
- }
-
- debug('connection established');
-});
-
-module.exports = client;
+};
diff --git a/routes/api/index.js b/routes/api/index.js
index 8da3f791b..9b4f0432b 100644
--- a/routes/api/index.js
+++ b/routes/api/index.js
@@ -15,6 +15,6 @@ router.use('/stream', require('./stream'));
router.use('/user', require('./user'));
// Bind the kue handler to the /kue path.
-router.use('/kue', authorization.needed('admin'), require('kue').app);
+router.use('/kue', authorization.needed('admin'), require('../../kue').kue.app);
module.exports = router;
diff --git a/services/scraper.js b/services/scraper.js
index 665d4fc66..922ef77bc 100644
--- a/services/scraper.js
+++ b/services/scraper.js
@@ -1,5 +1,4 @@
-const kue = require('kue');
-const queue = kue.createQueue();
+const kue = require('../kue');
const debug = require('debug')('talk:services:scraper');
const Asset = require('../models/asset');
const JOB_NAME = 'scraper';
@@ -19,7 +18,7 @@ const scraper = {
return new Promise((resolve, reject) => {
debug(`Creating job for Asset[${asset.id}]`);
- let job = queue
+ let job = kue.queue
.create(JOB_NAME, {
title: `Scrape for asset ${asset.id}`,
asset_id: asset.id
@@ -72,7 +71,7 @@ const scraper = {
debug(`Now processing ${JOB_NAME} jobs`);
// Process jobs with the processJob function.
- queue.process(JOB_NAME, (job, done) => {
+ kue.queue.process(JOB_NAME, (job, done) => {
debug(`Starting on Job[${job.id}] for Asset[${job.data.asset_id}]`);
@@ -123,7 +122,7 @@ const scraper = {
// Shutdown and give the queue 5 seconds to shutdown before we start
// killing jobs.
- queue.shutdown(5000, (err) => {
+ kue.queue.shutdown(5000, (err) => {
if (err) {
return reject(err);
}