From 7d5b79c6a03414d172f238d3e8fc790396a2e016 Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 10 Nov 2016 14:59:56 -0800 Subject: [PATCH 1/9] Moved the moderation queue to its own folder and change the route to /queue/comments/pending --- routes/api/comments/index.js | 36 +++++----- routes/api/index.js | 1 + routes/api/queue/index.js | 30 +++++++++ tests/routes/api/comments/index.js | 25 ++----- tests/routes/api/queue/index.js | 105 +++++++++++++++++++++++++++++ transfer.py | 49 ++++++++++++++ 6 files changed, 206 insertions(+), 40 deletions(-) create mode 100644 routes/api/queue/index.js create mode 100644 tests/routes/api/queue/index.js create mode 100644 transfer.py diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index a2e77b417..ad8e0654d 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -1,8 +1,6 @@ const express = require('express'); const Comment = require('../../../models/comment'); -const Setting = require('../../../models/setting'); - const router = express.Router(); //============================================================================== @@ -25,11 +23,7 @@ router.get('/:comment_id', (req, res, next) => { }); }); -//============================================================================== -// Moderation Queues Routes -//============================================================================== - -// Get all the comments that have that action_type over them. +// Get all the comments that have an action_type over them. router.get('/action/:action_type', (req, res, next) => { Comment.findByActionType(req.params.action_type).then((comments) => { res.status(200).json(comments); @@ -47,19 +41,19 @@ router.get('/status/rejected', (req, res, next) => { }); }); -// Returns back all the comments that are in the moderation queue. The moderation queue is pre or post moderated, -// depending on the settings. The :moderation overwrites this settings. -// Pre-moderation: New comments are shown in the moderator queues immediately. -// Post-moderation: New comments do not appear in moderation queues unless they are flagged by other users. -router.get('/status/pending', (req, res, next) => { - Setting.getModerationSetting().then(function({moderation}){ - let moderationValue = req.query.moderation; - if (typeof moderationValue === 'undefined' || moderationValue === undefined) { - moderationValue = moderation; - } - Comment.moderationQueue(moderationValue).then((comments) => { - res.status(200).json(comments); - }); +// Get all the comments that were accepted. +router.get('/status/accepted', (req, res, next) => { + Comment.findByStatus('accepted').then((comments) => { + res.status(200).json(comments); + }).catch(error => { + next(error); + }); +}); + +// Get all the not moderated comments. +router.get('/status/new', (req, res, next) => { + Comment.findByStatus('').then((comments) => { + res.status(200).json(comments); }).catch(error => { next(error); }); @@ -94,7 +88,7 @@ router.post('/:comment_id', (req, res, next) => { }); router.post('/:comment_id/status', (req, res, next) => { - + Comment .changeStatus(req.params.comment_id, req.body.status) .then(comment => res.status(200).send(comment)) diff --git a/routes/api/index.js b/routes/api/index.js index d161cf622..acd007dae 100644 --- a/routes/api/index.js +++ b/routes/api/index.js @@ -4,6 +4,7 @@ const router = express.Router(); router.use('/asset', require('./asset')); router.use('/comments', require('./comments')); +router.use('/queue', require('./queue')); router.use('/settings', require('./settings')); router.use('/stream', require('./stream')); diff --git a/routes/api/queue/index.js b/routes/api/queue/index.js new file mode 100644 index 000000000..4c87d6593 --- /dev/null +++ b/routes/api/queue/index.js @@ -0,0 +1,30 @@ +const express = require('express'); +const Comment = require('../../../models/comment'); + +const Setting = require('../../../models/setting'); + +const router = express.Router(); + +//============================================================================== +// Get Routes +//============================================================================== + +// Returns back all the comments that are in the moderation queue. The moderation queue is pre or post moderated, +// depending on the settings. The :moderation overwrites this settings. +// Pre-moderation: New comments are shown in the moderator queues immediately. +// Post-moderation: New comments do not appear in moderation queues unless they are flagged by other users. +router.get('/comments/pending', (req, res, next) => { + Setting.getModerationSetting().then(function({moderation}){ + let moderationValue = req.query.moderation; + if (typeof moderationValue === 'undefined' || moderationValue === undefined) { + moderationValue = moderation; + } + Comment.moderationQueue(moderationValue).then((comments) => { + res.status(200).json(comments); + }); + }).catch(error => { + next(error); + }); +}); + +module.exports = router; diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index e635e988c..cde4b9efb 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -75,7 +75,7 @@ describe('Get /comments', () => { }); }); -describe('Get moderation queues rejected, pending, flags', () => { +describe('Get comments by status and action', () => { const comments = [{ id: 'abc', body: 'comment 10', @@ -133,21 +133,20 @@ describe('Get moderation queues rejected, pending, flags', () => { }); }); - it('should return all the pending comments', function(done){ + it('should return all the approved comments', function(done){ chai.request(app) - .get('/api/v1/comments/status/pending') + .get('/api/v1/comments/status/accepted') .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - expect(res.body[0]).to.have.property('id', 'def'); + expect(res.body[0]).to.have.property('id', 'hij'); done(); }); }); - it('should return all the pending comments as pre moderated', function(done){ + it('should return all the new comments', function(done){ chai.request(app) - .get('/api/v1/comments/status/pending') - .query({'moderation': 'pre'}) + .get('/api/v1/comments/status/new') .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); @@ -156,18 +155,6 @@ describe('Get moderation queues rejected, pending, flags', () => { }); }); - it('should return all the pending comments as post moderated', function(done){ - chai.request(app) - .get('/api/v1/comments/status/pending') - .query({'moderation': 'post'}) - .end(function(err, res){ - expect(err).to.be.null; - expect(res).to.have.status(200); - expect(res.body).to.have.lengthOf(0); - done(); - }); - }); - it('should return all the flagged comments', function(done){ chai.request(app) .get('/api/v1/comments/action/flag') diff --git a/tests/routes/api/queue/index.js b/tests/routes/api/queue/index.js new file mode 100644 index 000000000..e339926cd --- /dev/null +++ b/tests/routes/api/queue/index.js @@ -0,0 +1,105 @@ +process.env.NODE_ENV = 'test'; + +require('../../../utils/mongoose'); + +const app = require('../../../../app'); +const chai = require('chai'); +const expect = chai.expect; + +// Setup chai. +chai.should(); +chai.use(require('chai-http')); + +const Comment = require('../../../../models/comment'); +const Action = require('../../../../models/action'); +const User = require('../../../../models/user'); + +const Setting = require('../../../../models/setting'); +const settings = {id: '1', moderation: 'pre'}; + +beforeEach(() => { + return Setting.create(settings); +}); + +describe('Get moderation queues rejected, pending, flags', () => { + const comments = [{ + id: 'abc', + body: 'comment 10', + asset_id: 'asset', + author_id: '123', + status: 'rejected' + }, { + id: 'def', + body: 'comment 20', + asset_id: 'asset', + author_id: '456' + }, { + id: 'hij', + body: 'comment 30', + asset_id: '456', + status: 'accepted' + }]; + + const users = [{ + displayName: 'Ana', + email: 'ana@gmail.com', + password: '123' + }, { + displayName: 'Maria', + email: 'maria@gmail.com', + password: '123' + }]; + + const actions = [{ + action_type: 'flag', + item_id: 'abc', + item_type: 'comment' + }, { + action_type: 'like', + item_id: 'hij', + item_type: 'comment' + }]; + + beforeEach(() => { + return Promise.all([ + Comment.create(comments), + User.createLocalUsers(users), + Action.create(actions) + ]); + }); + + it('should return all the pending comments', function(done){ + chai.request(app) + .get('/api/v1/queue/comments/pending') + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body[0]).to.have.property('id', 'def'); + done(); + }); + }); + + it('should return all the pending comments as pre moderated', function(done){ + chai.request(app) + .get('/api/v1/queue/comments/pending') + .query({'moderation': 'pre'}) + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body[0]).to.have.property('id', 'def'); + done(); + }); + }); + + it('should return all the pending comments as post moderated', function(done){ + chai.request(app) + .get('/api/v1/queue/comments/pending') + .query({'moderation': 'post'}) + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body).to.have.lengthOf(0); + done(); + }); + }); +}); diff --git a/transfer.py b/transfer.py new file mode 100644 index 000000000..97a73a429 --- /dev/null +++ b/transfer.py @@ -0,0 +1,49 @@ +from pymongo import MongoClient +import requests + +url = 'http://localhost:3000/api/v1/' +url_asset = '%sasset' % url +url_comment = '%scomments' % url + +def main(): + client = MongoClient('localhost', 27017) + db_wapo = client.original_wapo + wcomments = db_wapo.comments + + for comment in wcomments.find(): + ncomment = {} + nasset = {} + status = comment['object']['status'] + if (status == 'Untouched'): + ncomment['status'] = '' + elif (status == 'CommunityFlagged'): + ncomment['status'] = '' + elif (status == 'ModeratorApproved'): + ncomment['status'] = 'accepted' + elif (status == 'ModeratorDeleted'): + ncomment['status'] = 'rejected' + ncomment['body'] = comment['object']['content'] + nasset['url'] = comment['targets'][0]['conversationID'] + ncomment['asset_id'] = post_asset(nasset) + ncomment['author_id'] = '1' + post_comment(ncomment) + +def post_asset(nasset): + print 'Posting %s into %s.' % (nasset, url_asset) + try: + r = requests.put(url_asset, json=nasset) + if 'id' in r.json(): + return r.json()['id'] + else: + ra = requests.get(url_asset, { url: nasset['url']}) + return ra.json()['id'] + except: + print('Error when getting asset.') + return 'asset' + +def post_comment(ncomment): + print 'Posting %s into %s.' % (ncomment, url_comment) + r = requests.post(url_comment, json=ncomment) + +if __name__ == '__main__': + main() From ad01bc813f309df256a6b2a5218b18e018b416a6 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 11 Nov 2016 08:38:51 -0800 Subject: [PATCH 2/9] Removes script and change according to suggestion. --- routes/api/queue/index.js | 2 +- transfer.py | 49 --------------------------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 transfer.py diff --git a/routes/api/queue/index.js b/routes/api/queue/index.js index 4c87d6593..82147853f 100644 --- a/routes/api/queue/index.js +++ b/routes/api/queue/index.js @@ -16,7 +16,7 @@ const router = express.Router(); router.get('/comments/pending', (req, res, next) => { Setting.getModerationSetting().then(function({moderation}){ let moderationValue = req.query.moderation; - if (typeof moderationValue === 'undefined' || moderationValue === undefined) { + if (typeof moderationValue === 'undefined' || !moderationValue) { moderationValue = moderation; } Comment.moderationQueue(moderationValue).then((comments) => { diff --git a/transfer.py b/transfer.py deleted file mode 100644 index 97a73a429..000000000 --- a/transfer.py +++ /dev/null @@ -1,49 +0,0 @@ -from pymongo import MongoClient -import requests - -url = 'http://localhost:3000/api/v1/' -url_asset = '%sasset' % url -url_comment = '%scomments' % url - -def main(): - client = MongoClient('localhost', 27017) - db_wapo = client.original_wapo - wcomments = db_wapo.comments - - for comment in wcomments.find(): - ncomment = {} - nasset = {} - status = comment['object']['status'] - if (status == 'Untouched'): - ncomment['status'] = '' - elif (status == 'CommunityFlagged'): - ncomment['status'] = '' - elif (status == 'ModeratorApproved'): - ncomment['status'] = 'accepted' - elif (status == 'ModeratorDeleted'): - ncomment['status'] = 'rejected' - ncomment['body'] = comment['object']['content'] - nasset['url'] = comment['targets'][0]['conversationID'] - ncomment['asset_id'] = post_asset(nasset) - ncomment['author_id'] = '1' - post_comment(ncomment) - -def post_asset(nasset): - print 'Posting %s into %s.' % (nasset, url_asset) - try: - r = requests.put(url_asset, json=nasset) - if 'id' in r.json(): - return r.json()['id'] - else: - ra = requests.get(url_asset, { url: nasset['url']}) - return ra.json()['id'] - except: - print('Error when getting asset.') - return 'asset' - -def post_comment(ncomment): - print 'Posting %s into %s.' % (ncomment, url_comment) - r = requests.post(url_comment, json=ncomment) - -if __name__ == '__main__': - main() From c6198b21bc4534636085ba7030b5bc685cd453e0 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 11 Nov 2016 12:59:24 -0800 Subject: [PATCH 3/9] It changes the endpoint for the moderation queue. --- client/coral-admin/src/services/talk-adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index 9f4dd4715..1457601ed 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -34,7 +34,7 @@ export default store => next => action => { // Get comments to fill each of the three lists on the mod queue const fetchModerationQueueComments = store => -Promise.all([fetch('/api/v1/comments/status/pending'), fetch('/api/v1/comments/status/rejected'), fetch('/api/v1/comments/action/flag')]) +Promise.all([fetch('/api/v1/queue/comments/pending'), fetch('/api/v1/comments/status/rejected'), fetch('/api/v1/comments/action/flag')]) .then(res => Promise.all(res.map(r => r.json()))) .then(res => { res[2] = res[2].map(comment => { comment.flagged = true; return comment; }); From 223887616d4983a31248256938b2f1c3e65c7ba3 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Mon, 14 Nov 2016 16:20:56 -0500 Subject: [PATCH 4/9] feature(coral-admin): Add users role change --- client/coral-admin/src/actions/community.js | 10 +- client/coral-admin/src/constants/community.js | 1 + .../src/containers/Community/Community.js | 4 + .../src/containers/Community/Table.js | 94 +++++++++++++------ client/coral-admin/src/reducers/community.js | 9 +- client/coral-admin/src/translations.js | 12 ++- package.json | 1 + routes/api/user/index.js | 14 ++- 8 files changed, 108 insertions(+), 37 deletions(-) diff --git a/client/coral-admin/src/actions/community.js b/client/coral-admin/src/actions/community.js index 06c8ab0f6..d35cf0614 100644 --- a/client/coral-admin/src/actions/community.js +++ b/client/coral-admin/src/actions/community.js @@ -5,7 +5,8 @@ import { FETCH_COMMENTERS_SUCCESS, FETCH_COMMENTERS_FAILURE, SORT_UPDATE, - COMMENTERS_NEW_PAGE + COMMENTERS_NEW_PAGE, + SET_ROLE } from '../constants/community'; import {base, getInit, handleResp} from '../helpers/response'; @@ -40,3 +41,10 @@ export const newPage = () => ({ type: COMMENTERS_NEW_PAGE }); +export const setRole = (id, role) => dispatch => { + return fetch(`${base}/user/${id}/role`, getInit('POST', { role })) + .then(() => { + return dispatch({ type: SET_ROLE, id, role }); + }) + +} diff --git a/client/coral-admin/src/constants/community.js b/client/coral-admin/src/constants/community.js index e628a14d6..2ea77ea77 100644 --- a/client/coral-admin/src/constants/community.js +++ b/client/coral-admin/src/constants/community.js @@ -3,3 +3,4 @@ export const FETCH_COMMENTERS_SUCCESS = 'FETCH_COMMENTERS_SUCCESS'; export const FETCH_COMMENTERS_FAILURE = 'FETCH_COMMENTERS_FAILURE'; export const SORT_UPDATE = 'SORT_UPDATE'; export const COMMENTERS_NEW_PAGE = 'COMMENTERS_NEW_PAGE'; +export const SET_ROLE = 'SET_ROLE'; diff --git a/client/coral-admin/src/containers/Community/Community.js b/client/coral-admin/src/containers/Community/Community.js index 8e0b955a4..fb6f5df8c 100644 --- a/client/coral-admin/src/containers/Community/Community.js +++ b/client/coral-admin/src/containers/Community/Community.js @@ -19,6 +19,10 @@ const tableHeaders = [ { title: lang.t('community.account_creation_date'), field: 'created_at' + }, + { + title: lang.t('community.newsroom_role'), + field: 'role' } ]; diff --git a/client/coral-admin/src/containers/Community/Table.js b/client/coral-admin/src/containers/Community/Table.js index a15a88723..66dbc894b 100644 --- a/client/coral-admin/src/containers/Community/Table.js +++ b/client/coral-admin/src/containers/Community/Table.js @@ -1,34 +1,66 @@ -import React from 'react'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { SelectField, Option } from 'react-mdl-selectfield'; import styles from './Community.css'; +import I18n from 'coral-framework/i18n/i18n'; +import translations from '../../translations'; +import { setRole } from '../../actions/community'; -const Table = ({headers, data, onHeaderClickHandler}) => ( - - - - {headers.map((header, i) =>( - - ))} - - - - {data.map((row, i)=> ( - - - - - ))} - -
onHeaderClickHandler({field: header.field})}> - {header.title} -
- {row.displayName} - {row.profiles.map(({id}) => id)} - - {row.created_at} -
-); +const lang = new I18n(translations); -export default Table; +class Table extends Component { + + constructor (props) { + super(props); + this.onRoleChange = this.onRoleChange.bind(this); + } + + onRoleChange (id, role) { + this.props.dispatch(setRole(id, role)); + } + + render () { + const { headers, commenters, onHeaderClickHandler } = this.props; + + return ( + + + + {headers.map((header, i) =>( + + ))} + + + + {commenters.map((row, i)=> ( + + + + + + ))} + +
onHeaderClickHandler({field: header.field})}> + {header.title} +
+ {row.displayName} + {row.profiles.map(({id}) => id)} + + {row.created_at} + + this.onRoleChange(row.id, role)}> + + + + +
+ ); + } +} + +export default connect(state => ({ commenters: state.community.get('commenters') }))(Table); diff --git a/client/coral-admin/src/reducers/community.js b/client/coral-admin/src/reducers/community.js index 8d5dfd2c3..3421a079c 100644 --- a/client/coral-admin/src/reducers/community.js +++ b/client/coral-admin/src/reducers/community.js @@ -4,7 +4,8 @@ import { FETCH_COMMENTERS_REQUEST, FETCH_COMMENTERS_FAILURE, FETCH_COMMENTERS_SUCCESS, - SORT_UPDATE + SORT_UPDATE, + SET_ROLE } from '../constants/community'; const initialState = Map({ @@ -37,6 +38,12 @@ export default function community (state = initialState, action) { }) .set('commenters', commenters); // Sets to normal array } + case SET_ROLE: + const commenters = state.get('commenters'); + const idx = commenters.findIndex(el => el.id === action.id); + + commenters[idx].roles[0] = action.role + return state.set('commenters', commenters); case SORT_UPDATE : return state .set('field', action.sort.field) diff --git a/client/coral-admin/src/translations.js b/client/coral-admin/src/translations.js index 67a8142fd..fa655294a 100644 --- a/client/coral-admin/src/translations.js +++ b/client/coral-admin/src/translations.js @@ -2,7 +2,11 @@ export default { en: { 'community': { username_and_email: 'Username and Email', - account_creation_date: 'Account Creation Date' + account_creation_date: 'Account Creation Date', + newsroom_role: 'Newsroom Role', + admin: 'Administrator', + moderator: 'Moderator', + role: 'Select role...' }, 'modqueue': { 'pending': 'pending', @@ -30,7 +34,11 @@ export default { es: { 'community': { username_and_email: 'Usuario y E-mail', - account_creation_date: 'Fecha de creación de la cuenta' + account_creation_date: 'Fecha de creación de la cuenta', + newsroom_role: 'Rol en la redacción', + admin: 'Administrador', + moderator: 'Moderador', + role: 'Select role...' }, 'modqueue': { 'pending': 'pendiente', diff --git a/package.json b/package.json index cbdaad174..a36fcbd3a 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "mongoose": "^4.6.5", "morgan": "^1.7.0", "prompt": "^1.0.0", + "react-mdl-selectfield": "^0.2.0", "uuid": "^2.0.3" }, "devDependencies": { diff --git a/routes/api/user/index.js b/routes/api/user/index.js index 18872eab7..4665f4e52 100644 --- a/routes/api/user/index.js +++ b/routes/api/user/index.js @@ -40,11 +40,13 @@ router.get('/', (req, res, next) => { ]) .then(([data, count]) => { const users = data.map((user) => { - const {displayName, created_at} = user; + const {id, displayName, created_at} = user; return { + id, displayName, created_at, - profiles: user.toObject().profiles + profiles: user.toObject().profiles, + roles: user.toObject().roles }; }); @@ -60,4 +62,12 @@ router.get('/', (req, res, next) => { .catch(next); }); +router.post('/:user_id/role', (req, res, next) => { + User.addRoleToUser(req.params.user_id, req.body.role) + .then(role => { + res.send(role); + }) + .catch(next); +}); + module.exports = router; From 9c41adf224f59cc3db1a175127758c3a82609442 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Mon, 14 Nov 2016 16:44:21 -0500 Subject: [PATCH 5/9] Added enum check for the user model --- models/user.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/models/user.js b/models/user.js index c0a846f1a..12f939e72 100644 --- a/models/user.js +++ b/models/user.js @@ -24,7 +24,10 @@ const UserSchema = new mongoose.Schema({ required: true } }], - roles: [String] + roles: { + type: [{ type: String, enum: ['admin', 'moderator'] }], + + } }, { timestamps: { createdAt: 'created_at', From e53ac55e6b242272e39350ba76c74dc6bad346d5 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Mon, 14 Nov 2016 17:03:31 -0500 Subject: [PATCH 6/9] Linting --- client/coral-admin/src/actions/community.js | 9 ++++----- client/coral-admin/src/containers/Community/Table.js | 12 ++++++------ client/coral-admin/src/reducers/community.js | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/client/coral-admin/src/actions/community.js b/client/coral-admin/src/actions/community.js index d35cf0614..7a4112f8b 100644 --- a/client/coral-admin/src/actions/community.js +++ b/client/coral-admin/src/actions/community.js @@ -42,9 +42,8 @@ export const newPage = () => ({ }); export const setRole = (id, role) => dispatch => { - return fetch(`${base}/user/${id}/role`, getInit('POST', { role })) + return fetch(`${base}/user/${id}/role`, getInit('POST', {role})) .then(() => { - return dispatch({ type: SET_ROLE, id, role }); - }) - -} + return dispatch({type: SET_ROLE, id, role}); + }); +}; diff --git a/client/coral-admin/src/containers/Community/Table.js b/client/coral-admin/src/containers/Community/Table.js index 66dbc894b..97848bc9a 100644 --- a/client/coral-admin/src/containers/Community/Table.js +++ b/client/coral-admin/src/containers/Community/Table.js @@ -1,10 +1,10 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import { SelectField, Option } from 'react-mdl-selectfield'; +import React, {Component} from 'react'; +import {connect} from 'react-redux'; +import {SelectField, Option} from 'react-mdl-selectfield'; import styles from './Community.css'; import I18n from 'coral-framework/i18n/i18n'; import translations from '../../translations'; -import { setRole } from '../../actions/community'; +import {setRole} from '../../actions/community'; const lang = new I18n(translations); @@ -20,7 +20,7 @@ class Table extends Component { } render () { - const { headers, commenters, onHeaderClickHandler } = this.props; + const {headers, commenters, onHeaderClickHandler} = this.props; return ( @@ -63,4 +63,4 @@ class Table extends Component { } } -export default connect(state => ({ commenters: state.community.get('commenters') }))(Table); +export default connect(state => ({commenters: state.community.get('commenters')}))(Table); diff --git a/client/coral-admin/src/reducers/community.js b/client/coral-admin/src/reducers/community.js index 3421a079c..d8fe88dbc 100644 --- a/client/coral-admin/src/reducers/community.js +++ b/client/coral-admin/src/reducers/community.js @@ -38,11 +38,11 @@ export default function community (state = initialState, action) { }) .set('commenters', commenters); // Sets to normal array } - case SET_ROLE: + case SET_ROLE : const commenters = state.get('commenters'); const idx = commenters.findIndex(el => el.id === action.id); - commenters[idx].roles[0] = action.role + commenters[idx].roles[0] = action.role; return state.set('commenters', commenters); case SORT_UPDATE : return state From 366e072280cdf89a1bd7fc103f500e485f0b6f5e Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 14 Nov 2016 23:35:33 -0300 Subject: [PATCH 7/9] Linting Issues --- client/coral-admin/src/reducers/community.js | 3 ++- models/user.js | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/coral-admin/src/reducers/community.js b/client/coral-admin/src/reducers/community.js index d8fe88dbc..a42252805 100644 --- a/client/coral-admin/src/reducers/community.js +++ b/client/coral-admin/src/reducers/community.js @@ -38,12 +38,13 @@ export default function community (state = initialState, action) { }) .set('commenters', commenters); // Sets to normal array } - case SET_ROLE : + case SET_ROLE : { const commenters = state.get('commenters'); const idx = commenters.findIndex(el => el.id === action.id); commenters[idx].roles[0] = action.role; return state.set('commenters', commenters); + } case SORT_UPDATE : return state .set('field', action.sort.field) diff --git a/models/user.js b/models/user.js index 12f939e72..c6197a220 100644 --- a/models/user.js +++ b/models/user.js @@ -24,10 +24,9 @@ const UserSchema = new mongoose.Schema({ required: true } }], - roles: { - type: [{ type: String, enum: ['admin', 'moderator'] }], - - } + roles: { + type: [{type: String, enum: ['admin', 'moderator']}] + } }, { timestamps: { createdAt: 'created_at', From 27261cc515942d8cacafcbcfc73ef0a6f970a700 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 15 Nov 2016 12:37:05 -0500 Subject: [PATCH 8/9] Added fix for returning a new array --- client/coral-admin/src/reducers/community.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-admin/src/reducers/community.js b/client/coral-admin/src/reducers/community.js index d8fe88dbc..215063f0f 100644 --- a/client/coral-admin/src/reducers/community.js +++ b/client/coral-admin/src/reducers/community.js @@ -43,7 +43,7 @@ export default function community (state = initialState, action) { const idx = commenters.findIndex(el => el.id === action.id); commenters[idx].roles[0] = action.role; - return state.set('commenters', commenters); + return state.set('commenters', commenters.map(id => id)); case SORT_UPDATE : return state .set('field', action.sort.field) From 2438161ad957a728d81d0b5c6ec8926203905845 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 15 Nov 2016 12:54:25 -0500 Subject: [PATCH 9/9] Removed extra return --- client/coral-admin/src/reducers/community.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/coral-admin/src/reducers/community.js b/client/coral-admin/src/reducers/community.js index 7ff8514fd..81a09a1cc 100644 --- a/client/coral-admin/src/reducers/community.js +++ b/client/coral-admin/src/reducers/community.js @@ -44,7 +44,6 @@ export default function community (state = initialState, action) { commenters[idx].roles[0] = action.role; return state.set('commenters', commenters.map(id => id)); - return state.set('commenters', commenters); } case SORT_UPDATE : return state