diff --git a/.eslintignore b/.eslintignore
index 53c37a166..a4865e1f6 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1 +1,2 @@
-dist
\ No newline at end of file
+dist
+client/lib
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 000000000..9fa7985c0
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,95 @@
+# Contribution Guide
+
+We're very excited that you're interested in contributing to Talk! There is much to do. Before you begin, please review this document to get a sense of the practices and philosophies that hold this project together.
+
+
+## Doing the Work
+
+We are here to make it as seamless as possible to contribute to Talk. The following lists are meant to make it straightforward to perform the mechanics of working on the project so you can focus your energy toward writing and reviewing content.
+
+
+### Code Reviews
+
+One of the most valuable aspects of working in software. It is something that should challenge the reviewer and author alike. It is a way of focusing knowledge, experience and opinions for the benefit of the project and the participants.
+
+Code reviews are a collaboration to make _the work_ as good as it can be. Code reviews are not a good venue for providing direct instruction to _the author._ Focus on positive, incremental improvements that can be made on the work at hand.
+
+Please take your time when writing and reviewing code. Here are some fundamental questions to open up a reviewing headspace.
+
+**Is the code clear, efficient and a pleasure to read?**
+
+Somewhere at the intersection of good variable names, well laid out file structures, consistent formatting and appropriate comments lies beautiful code. Code is language spoken to at least two very distinct audiences, the computer that interprets it and the developer who encounters it. Both should be at the front of your mind when reviewing code.
+
+Thinking like a computer, you could ask:
+
+* Is the code using memory efficiently?
+* Is data being moved around unnecessarily?
+* Are multiple network requests being made where fewer would do?
+* Is there excess processing happening in a synchronous flow that may disrupt user experience?
+* Are there large libraries included for small gains?
+
+Then, returning to your human roots... Is the code readable?
+
+* Can I understand what is happening here (and maybe even why) by simply opening up the file, starting at the top and reading downward?
+* Do comments convey clear, full thoughts in a narrative language that provides background for the code choices?
+* Are the files separated logically such that each one contains a clear concept of code?
+
+
+**Is the API documentation up to date? Are all client calls written against the docs?**
+
+We use [swagger](https://github.com/coralproject/talk/blob/master/swagger.yaml) to track our API documentation.
+
+* If APIs are created or updated, is the swagger.yml file up to date? There's nothing more frustrating than trying to develop against docs that are out of date or wrong. We need to be meticulous here as it's the little differences that can cause the most frustration and tricky bugs.
+* If client code calls APIs, are they written against the swagger.yml file? Are all return codes handled?
+
+**Is there sufficient test coverage?**
+
+Our tests folder is set up to mirror the code folders: [https://github.com/coralproject/talk/tree/master/tests](https://github.com/coralproject/talk/tree/master/tests)
+
+* Can you a sense of the logic behind the code by reading the tests?
+* Can you see both what should happen and what should _never, ever_ be allowed to happen?
+* Are there future cases that are guarded against via the creation of unit tests (aka, making sure things are typed, specifically checking for all values that will be used, etc...)?
+
+
+### Forking, Branching and Merging
+
+Talk follows the _master as tip_ repo structure. `master` is the bleeding edge. It should be _as stable as possible_ but may suffer instabilities, generally during times that fundamental architectural elements are added.
+
+Releases are _tagged_ off the master branch.
+
+Contributions to Talk follow this process. There are a lot of steps, but mechanically following these steps will standardize communication, help stop errors and let you focus on your contribution.
+
+* At the outset of a piece of work, a branch or fork is made from master.
+* The work is done in that fork.
+* As soon as the work has taken shape, a PR is created for discussion. (If the PR is created for review before it's ready to merge, please make that clear in the description/title.)
+* At least one other contributor to the project must review all code (see Code Reviews below.)
+* If there are merge conflicts with master, merge master into the branch.
+* Ensure that [circleci](https://circleci.com/) passes all tests for your branch. (If you have forked and do not have circleci set up, you and the reviewer should independently ensure that all the of Continuous Integration steps pass before merging.)
+* If merge conflicts exist with `master`, merge `master` into your branch and re-run CI before merging into master.
+* Merge to master, but _you're not quite done yet!_
+* Deploy master to staging (or have a core member do so.)
+* Ensure that all your changes are working on staging.
+* Have your reviewer verify the same.
+* ... aaaand the work is delivered!
+
+
+## Continuous Integration
+
+We use circleci to run our ci: [https://circleci.com/gh/coralproject/talk](https://circleci.com/gh/coralproject/talk)
+
+Our pipeline will _test_, _lint_, and _build_ all pushes to the repo.
+
+Any branch not passing CI will not be merged into master.
+
+If you're working in a fork, please run each of the steps locally before submitting a PR.
+
+
+## Coding Style
+
+### API Design
+
+When building APIs, we follow these principles:
+
+* Follow [RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer) principles for basic operations.
+* Avoid routing yourself into a corner, for example, by putting a variable other than an object's id directly after an object.
+* Put non-required, flexible variables into query params, required/identity based values in request params.
diff --git a/client/coral-admin/src/actions/auth.js b/client/coral-admin/src/actions/auth.js
index 2f8f1041e..54763259d 100644
--- a/client/coral-admin/src/actions/auth.js
+++ b/client/coral-admin/src/actions/auth.js
@@ -1,5 +1,5 @@
import * as actions from '../constants/auth';
-import {base, handleResp, getInit} from '../../../coral-framework/helpers/response';
+import coralApi from '../../../coral-framework/helpers/response';
// Check Login
@@ -9,8 +9,7 @@ const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error});
export const checkLogin = () => dispatch => {
dispatch(checkLoginRequest());
- fetch(`${base}/auth`, getInit('GET'))
- .then(handleResp)
+ coralApi('/auth')
.then(user => {
const isAdmin = !!user.roles.filter(i => i === 'admin').length;
dispatch(checkLoginSuccess(user, isAdmin));
@@ -26,8 +25,7 @@ const logOutFailure = () => ({type: actions.LOGOUT_FAILURE});
export const logout = () => dispatch => {
dispatch(logOutRequest());
- fetch(`${base}/auth`, getInit('DELETE'))
- .then(handleResp)
+ coralApi('/auth', {method: 'DELETE'})
.then(() => dispatch(logOutSuccess()))
.catch(error => dispatch(logOutFailure(error)));
};
diff --git a/client/coral-admin/src/actions/community.js b/client/coral-admin/src/actions/community.js
index 5921573d1..8b8e883d8 100644
--- a/client/coral-admin/src/actions/community.js
+++ b/client/coral-admin/src/actions/community.js
@@ -9,12 +9,11 @@ import {
SET_ROLE
} from '../constants/community';
-import {base, getInit, handleResp} from '../../../coral-framework/helpers/response';
+import coralApi from '../../../coral-framework/helpers/response';
export const fetchCommenters = (query = {}) => dispatch => {
dispatch(requestFetchCommenters());
- fetch(`${base}/user?${qs.stringify(query)}`, getInit('GET'))
- .then(handleResp)
+ coralApi(`/user?${qs.stringify(query)}`)
.then(({result, page, count, limit, totalPages}) =>
dispatch({
type: FETCH_COMMENTERS_SUCCESS,
@@ -42,7 +41,7 @@ export const newPage = () => ({
});
export const setRole = (id, role) => dispatch => {
- return fetch(`${base}/user/${id}/role`, getInit('POST', {role}))
+ return coralApi(`/user/${id}/role`, {method: 'POST', body: {role}})
.then(() => {
return dispatch({type: SET_ROLE, id, role});
});
diff --git a/client/coral-admin/src/actions/settings.js b/client/coral-admin/src/actions/settings.js
index 6a133ddb5..71106e1f7 100644
--- a/client/coral-admin/src/actions/settings.js
+++ b/client/coral-admin/src/actions/settings.js
@@ -1,4 +1,4 @@
-import {base, handleResp, getInit} from '../../../coral-framework/helpers/response';
+import coralApi from '../../../coral-framework/helpers/response';
export const SETTINGS_LOADING = 'SETTINGS_LOADING';
export const SETTINGS_RECEIVED = 'SETTINGS_RECEIVED';
@@ -12,8 +12,7 @@ export const SAVE_SETTINGS_FAILED = 'SAVE_SETTINGS_FAILED';
export const fetchSettings = () => dispatch => {
dispatch({type: SETTINGS_LOADING});
- fetch(`${base}/settings`, getInit('GET'))
- .then(handleResp)
+ coralApi('/settings')
.then(settings => {
dispatch({type: SETTINGS_RECEIVED, settings});
})
@@ -29,8 +28,7 @@ export const updateSettings = settings => {
export const saveSettingsToServer = () => (dispatch, getState) => {
const settings = getState().settings.toJS().settings;
dispatch({type: SAVE_SETTINGS_LOADING});
- fetch(`${base}/settings`, getInit('PUT', settings))
- .then(handleResp)
+ coralApi('/settings', {method: 'PUT', body: settings})
.then(() => {
dispatch({type: SAVE_SETTINGS_SUCCESS, settings});
})
diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js
index 7cba85788..3481ad671 100644
--- a/client/coral-admin/src/components/Comment.js
+++ b/client/coral-admin/src/components/Comment.js
@@ -12,26 +12,27 @@ const linkify = new Linkify();
// Render a single comment for the list
export default props => {
- const links = linkify.getMatches(props.comment.get('body'));
+ const {comment, author} = props;
+ const links = linkify.getMatches(comment.get('body'));
return (
);
}
diff --git a/client/coral-admin/src/containers/CommentStream/CommentStream.js b/client/coral-admin/src/containers/CommentStream/CommentStream.js
index b1e002549..113a7bc86 100644
--- a/client/coral-admin/src/containers/CommentStream/CommentStream.js
+++ b/client/coral-admin/src/containers/CommentStream/CommentStream.js
@@ -40,7 +40,7 @@ class CommentStream extends React.Component {
}
// Render the comment box along with the CommentList
- render ({comments}, {snackbar, snackbarMsg}) {
+ render ({comments, users}, {snackbar, snackbarMsg}) {
return (
@@ -48,6 +48,7 @@ class CommentStream extends React.Component {
singleView={false}
commentIds={comments.get('ids')}
comments={comments.get('byId')}
+ users={users.get('byId')}
onClickAction={this.onClickAction}
actions={['flag']}
loading={comments.loading} />
@@ -57,4 +58,4 @@ class CommentStream extends React.Component {
}
}
-export default connect(({comments}) => ({comments}))(CommentStream);
+export default connect(({comments, users}) => ({comments, users}))(CommentStream);
diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js
index a4d82fddc..e5670d169 100644
--- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js
+++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js
@@ -61,7 +61,7 @@ class ModerationQueue extends React.Component {
// Render the tabbed lists moderation queues
render () {
- const {comments} = this.props;
+ const {comments, users} = this.props;
const {activeTab, singleView, modalOpen} = this.state;
return (
@@ -82,10 +82,11 @@ class ModerationQueue extends React.Component {
commentIds={
comments.get('ids')
.filter(id => !comments.get('byId')
- .get(id)
- .get('status'))
+ .get(id)
+ .get('status'))
}
comments={comments.get('byId')}
+ users={users.get('byId')}
onClickAction={(action, id) => this.onCommentAction(action, id)}
actions={['reject', 'approve']}
loading={comments.loading} />
@@ -104,6 +105,7 @@ class ModerationQueue extends React.Component {
.get('status') === 'rejected')
}
comments={comments.get('byId')}
+ users={users.get('byId')}
onClickAction={(action, id) => this.onCommentAction(action, id)}
actions={['approve']}
loading={comments.loading} />
@@ -117,6 +119,7 @@ class ModerationQueue extends React.Component {
return !data.get('status') && data.get('flagged') === true;
})}
comments={comments.get('byId')}
+ users={users.get('byId')}
onClickAction={(action, id) => this.onCommentAction(action, id)}
actions={['reject', 'approve']}
loading={comments.loading} />
@@ -129,6 +132,6 @@ class ModerationQueue extends React.Component {
}
}
-export default connect(({comments}) => ({comments}))(ModerationQueue);
+export default connect(({comments, users}) => ({comments, users}))(ModerationQueue);
const lang = new I18n(translations);
diff --git a/client/coral-admin/src/helpers/response.js b/client/coral-admin/src/helpers/response.js
deleted file mode 100644
index bccfc5a04..000000000
--- a/client/coral-admin/src/helpers/response.js
+++ /dev/null
@@ -1,30 +0,0 @@
-export const base = '/api/v1';
-
-export const getInit = (method, body) => {
- let init = {
- method,
- headers: new Headers({
- 'Content-Type': 'application/json',
- 'Accept': 'application/json'
- }),
- credentials: 'same-origin'
- };
-
- if (method.toLowerCase() !== 'get') {
- init.body = JSON.stringify(body);
- }
-
- return init;
-};
-
-export const handleResp = res => {
- if (res.status === 401) {
- throw new Error('Not Authorized to make this request');
- } else if (res.status > 399) {
- throw new Error('Error! Status ', res.status);
- } else if (res.status === 204) {
- return res.text();
- } else {
- return res.json();
- }
-};
diff --git a/client/coral-admin/src/reducers/auth.js b/client/coral-admin/src/reducers/auth.js
index f897c1bae..095ef7aac 100644
--- a/client/coral-admin/src/reducers/auth.js
+++ b/client/coral-admin/src/reducers/auth.js
@@ -24,10 +24,7 @@ export default function auth (state = initialState, action) {
.set('isAdmin', action.isAdmin)
.set('user', action.user);
case actions.LOGOUT_SUCCESS:
- return state
- .set('loggedIn', false)
- .set('user', null)
- .set('isAdmin', false);
+ return initialState;
default :
return state;
}
diff --git a/client/coral-admin/src/reducers/index.js b/client/coral-admin/src/reducers/index.js
index 61029539a..1f1b444fc 100644
--- a/client/coral-admin/src/reducers/index.js
+++ b/client/coral-admin/src/reducers/index.js
@@ -2,6 +2,7 @@ import {combineReducers} from 'redux';
import comments from 'reducers/comments';
import settings from 'reducers/settings';
import community from 'reducers/community';
+import users from 'reducers/users';
import auth from 'reducers/auth';
// Combine all reducers into a main one
@@ -9,6 +10,6 @@ export default combineReducers({
settings,
comments,
community,
- auth
+ auth,
+ users
});
-
diff --git a/client/coral-admin/src/reducers/users.js b/client/coral-admin/src/reducers/users.js
new file mode 100644
index 000000000..872ae904a
--- /dev/null
+++ b/client/coral-admin/src/reducers/users.js
@@ -0,0 +1,20 @@
+import {Map, List, fromJS} from 'immutable';
+
+const initialState = Map({
+ byId: Map(),
+ ids: List()
+});
+
+export default (state = initialState, action) => {
+ switch (action.type) {
+ case 'USERS_MODERATION_QUEUE_FETCH_SUCCESS': return replaceUsers(action, state);
+ default: return state;
+ }
+};
+
+// Replace the comment list with a new one
+const replaceUsers = (action, state) => {
+ const users = fromJS(action.users.reduce((prev, curr) => { prev[curr.id] = curr; return prev; }, {}));
+ return state.set('byId', users)
+ .set('ids', List(users.keys()));
+};
diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js
index 6b872d12d..5502df7ed 100644
--- a/client/coral-admin/src/services/talk-adapter.js
+++ b/client/coral-admin/src/services/talk-adapter.js
@@ -1,4 +1,4 @@
-import {base, handleResp, getInit} from '../../../coral-framework/helpers/response';
+import coralApi from '../../../coral-framework/helpers/response';
/**
* The adapter is a redux middleware that interecepts the actions that need
@@ -15,9 +15,6 @@ export default store => next => action => {
case 'COMMENTS_MODERATION_QUEUE_FETCH':
fetchModerationQueueComments(store);
break;
- // case 'COMMENT_STREAM_FETCH':
- // fetchCommentStream(store);
- // break;
case 'COMMENT_UPDATE':
updateComment(store, action.comment);
break;
@@ -33,24 +30,41 @@ export default store => next => action => {
const fetchModerationQueueComments = store =>
Promise.all([
- fetch(`${base}/queue/comments/pending`, getInit('GET')),
- fetch(`${base}/comments?status=rejected`, getInit('GET')),
- fetch(`${base}/comments?action_type=flag`, getInit('GET'))
+ coralApi('/queue/comments/pending'),
+ coralApi('/comments?status=rejected'),
+ coralApi('/comments?action_type=flag')
])
-.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), []);
+.then(([pending, rejected, flagged]) => {
+ /* Combine seperate calls into a single object */
+ let all = {};
+ all.comments = pending.comments
+ .concat(rejected.comments)
+ .concat(flagged.comments.map(comment => {
+ comment.flagged = true;
+ return comment;
+ }));
+ all.users = pending.users
+ .concat(rejected.users)
+ .concat(flagged.users);
+ all.actions = pending.actions
+ .concat(rejected.actions)
+ .concat(flagged.actions);
+ return all;
})
-.then(res => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS',
- comments: res}))
-.catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error}));
+.then(all => {
+ /* Post comments and users to redux store. Actions will be posted when they are needed. */
+ store.dispatch({type: 'USERS_MODERATION_QUEUE_FETCH_SUCCESS',
+ users: all.users});
+ store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS',
+ comments: all.comments});
+
+});
+// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error}));
// Update a comment. Now to update a comment we need to send back the whole object
const updateComment = (store, comment) => {
- fetch(`${base}/comments/${comment.get('id')}/status`, getInit('PUT', {status: comment.get('status')}))
- .then(handleResp)
+ coralApi(`/comments/${comment.get('id')}/status`, {method: 'PUT', body: {status: comment.get('status')}})
.then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res}))
.catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error}));
};
@@ -63,8 +77,7 @@ const createComment = (store, name, comment) => {
name: name,
createdAt: Date.now()
};
- return fetch(`${base}/comments`, getInit('POST', body))
- .then(handleResp)
+ return coralApi('/comments', {method: 'POST', body})
.then(res => store.dispatch({type: 'COMMENT_CREATE_SUCCESS', comment: res}))
.catch(error => store.dispatch({type: 'COMMENT_CREATE_FAILED', error}));
};
diff --git a/client/coral-embed-stream/public/samplearticle.html b/client/coral-embed-stream/public/samplearticle.html
index 64c3fd0f8..454cb249c 100644
--- a/client/coral-embed-stream/public/samplearticle.html
+++ b/client/coral-embed-stream/public/samplearticle.html
@@ -7,7 +7,7 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut lobortis sollicitudin eros a ornare. Curabitur dignissim vestibulum massa non rhoncus. Cras laoreet ante vel nunc hendrerit, ac imperdiet neque egestas. Suspendisse aliquet iaculis fermentum. Pellentesque interdum nec elit sed tincidunt. Donec volutpat, tellus posuere laoreet consequat, mi lacus laoreet massa, sed vehicula mauris velit non lectus. Integer non enim nec neque congue faucibus porttitor sit amet dui.
Nunc pharetra orci id diam feugiat, vitae rutrum magna efficitur. Morbi porttitor blandit lorem, et facilisis tellus luctus at. Morbi tincidunt eget nisl id placerat. Nullam consectetur quam vel mauris lacinia, non consectetur est faucibus. Duis cursus auctor nulla nec sagittis. Aenean sem erat, ultrices a hendrerit consectetur, accumsan non lorem. Integer ac neque sed magna sodales vulputate at quis neque. Praesent eget ornare lacus. Donec ultricies, dolor eget commodo faucibus, arcu velit ullamcorper tellus, in cursus tellus elit sed urna. Suspendisse in consequat magna. Duis vel ullamcorper tortor, vel cursus libero. Proin et nisi luctus ligula faucibus luctus. Morbi pulvinar, justo ac feugiat elementum, libero tellus congue justo, pharetra ultrices felis felis id leo. Integer mattis quam tempus libero porta, ac pretium ligula elementum.