Merge branch 'graphql' of github.com:coralproject/talk into graphql

This commit is contained in:
David Jay
2017-01-24 16:23:27 -05:00
24 changed files with 59 additions and 87 deletions
-3
View File
@@ -1,3 +0,0 @@
language: node_js
node_js:
- 4
+7 -1
View File
@@ -22,7 +22,13 @@ program
.command('init') .command('init')
.description('initilizes the talk settings') .description('initilizes the talk settings')
.action(() => { .action(() => {
const defaults = {id: '1', moderation: 'PRE'}; const defaults = {
moderation: 'PRE',
wordlist: {
banned: [],
suspect: []
}
};
SettingsService SettingsService
.init(defaults) .init(defaults)
+4 -2
View File
@@ -3,12 +3,14 @@ machine:
version: 7 version: 7
services: services:
- docker - docker
- redis
test: test:
override: override:
- MOCHA_FILE=$CIRCLE_TEST_REPORTS/junit/test-results.xml ./node_modules/.bin/mocha tests --reporter mocha-junit-reporter
- npm run lint - npm run lint
- npm run build - ./bin/cli settings init
- sleep 5
- MOCHA_FILE=$CIRCLE_TEST_REPORTS/junit/test-results.xml NPM_PACKAGE_CONFIG_MOCHA_REPORTER=mocha-junit-reporter npm run test
deployment: deployment:
release: release:
@@ -55,8 +55,8 @@ class Table extends Component {
className={styles.selectField} className={styles.selectField}
label={lang.t('community.status')} label={lang.t('community.status')}
onChange={status => this.onCommenterStatusChange(row.id, status)}> onChange={status => this.onCommenterStatusChange(row.id, status)}>
<Option value={'active'}>{lang.t('community.active')}</Option> <Option value={'ACTIVE'}>{lang.t('community.active')}</Option>
<Option value={'banned'}>{lang.t('community.banned')}</Option> <Option value={'BANNED'}>{lang.t('community.banned')}</Option>
</SelectField> </SelectField>
</td> </td>
<td className="mdl-data-table__cell--non-numeric"> <td className="mdl-data-table__cell--non-numeric">
@@ -65,8 +65,8 @@ class Table extends Component {
label={lang.t('community.role')} label={lang.t('community.role')}
onChange={role => this.onRoleChange(row.id, role)}> onChange={role => this.onRoleChange(row.id, role)}>
<Option value={''}>.</Option> <Option value={''}>.</Option>
<Option value={'moderator'}>{lang.t('community.moderator')}</Option> <Option value={'MODERATOR'}>{lang.t('community.moderator')}</Option>
<Option value={'admin'}>{lang.t('community.admin')}</Option> <Option value={'ADMIN'}>{lang.t('community.admin')}</Option>
</SelectField> </SelectField>
</td> </td>
</tr> </tr>
@@ -75,12 +75,12 @@ class ModerationContainer extends React.Component {
render () { render () {
const {comments} = this.props; const {comments} = this.props;
const premodIds = comments.ids.filter(id => comments.byId[id].status === 'premod'); const premodIds = comments.ids.filter(id => comments.byId[id].status === 'PREMOD');
const rejectedIds = comments.ids.filter(id => comments.byId[id].status === 'rejected'); const rejectedIds = comments.ids.filter(id => comments.byId[id].status === 'REJECTED');
const flaggedIds = comments.ids.filter(id => const flaggedIds = comments.ids.filter(id =>
comments.byId[id].flagged === true && comments.byId[id].flagged === true &&
comments.byId[id].status !== 'rejected' && comments.byId[id].status !== 'REJECTED' &&
comments.byId[id].status !== 'accepted' comments.byId[id].status !== 'ACCEPTED'
); );
return ( return (
@@ -112,7 +112,7 @@ const mapDispatchToProps = dispatch => {
fetchFlaggedQueue: () => dispatch(fetchFlaggedQueue()), fetchFlaggedQueue: () => dispatch(fetchFlaggedQueue()),
showBanUserDialog: (userId, userName, commentId) => dispatch(showBanUserDialog(userId, userName, commentId)), showBanUserDialog: (userId, userName, commentId) => dispatch(showBanUserDialog(userId, userName, commentId)),
hideBanUserDialog: () => dispatch(hideBanUserDialog(false)), hideBanUserDialog: () => dispatch(hideBanUserDialog(false)),
banUser: (userId, commentId) => dispatch(userStatusUpdate('banned', userId, commentId)).then(() => { banUser: (userId, commentId) => dispatch(userStatusUpdate('BANNED', userId, commentId)).then(() => {
dispatch(fetchModerationQueueComments()); dispatch(fetchModerationQueueComments());
}), }),
updateStatus: (action, comment) => dispatch(updateStatus(action, comment)) updateStatus: (action, comment) => dispatch(updateStatus(action, comment))
@@ -6,8 +6,9 @@ export default ({userData}) => (
<h1>{userData.displayName}</h1> <h1>{userData.displayName}</h1>
{ {
// Hiding display of users ID unless there's a use case for it. // Hiding display of users ID unless there's a use case for it.
//<h2>{userData.profiles.map(profile => profile.id)}</h2> // <h2>{userData.profiles.map(profile => profile.id)}</h2>
} }
</div> </div>
); );
+1 -1
View File
@@ -916,7 +916,7 @@ definitions:
type: array type: array
items: items:
type: string type: string
description: Roles occupied by the user (e.g. 'admin', 'moderator', etc.) description: Roles occupied by the user (e.g. 'ADMIN', 'MODERATOR', etc.)
status: status:
type: string type: string
description: The current status of the user in the system. description: The current status of the user in the system.
-8
View File
@@ -44,16 +44,8 @@ const getCommentsByStatusAndAssetID = (context, {status = null, asset_id = null}
}; };
const getCommentsByActionTypeAndAssetID = (context, {action_type, asset_id = null}) => { const getCommentsByActionTypeAndAssetID = (context, {action_type, asset_id = null}) => {
// TODO: remove when we move the enum over to the uppercase.
if (action_type) {
action_type = action_type.toLowerCase();
}
return ActionModel.find({ return ActionModel.find({
action_type, action_type,
// TODO: remove when we move the enum over to the uppercase.
item_type: 'COMMENTS' item_type: 'COMMENTS'
}).then((actions) => { }).then((actions) => {
let comments = CommentModel.find({ let comments = CommentModel.find({
+1 -3
View File
@@ -4,11 +4,9 @@ const util = require('./util');
const UsersService = require('../../services/users'); const UsersService = require('../../services/users');
const genUserByIDs = (context, ids) => { const genUserByIDs = (context, ids) => UsersService
return UsersService
.findByIdArray(ids) .findByIdArray(ids)
.then(util.singleJoinBy(ids, 'id')); .then(util.singleJoinBy(ids, 'id'));
};
/** /**
* Creates a set of loaders based on a GraphQL context. * Creates a set of loaders based on a GraphQL context.
+1 -13
View File
@@ -1,21 +1,9 @@
const Action = { const Action = {
action_type({action_type}) {
// FIXME: remove once we cast the data model to have uppercase action
// types.
return action_type.toUpperCase();
},
item_type({item_type}) {
// FIXME: remove once we cast the data model to have uppercase item
// types.
return item_type.toUpperCase();
},
// This will load the user for the specific action. We'll limit this to the // This will load the user for the specific action. We'll limit this to the
// admin users only. // admin users only.
user({user_id}, _, {loaders, user}) { user({user_id}, _, {loaders, user}) {
if (user.hasRole('admin')) { if (user.hasRole('ADMIN')) {
return loaders.Users.getByID.load(user_id); return loaders.Users.getByID.load(user_id);
} }
} }
+1 -14
View File
@@ -1,16 +1,3 @@
const ActionSummary = { const ActionSummary = {};
action_type({action_type}) {
// FIXME: remove once we cast the data model to have uppercase action
// types.
return action_type.toUpperCase();
},
item_type({item_type}) {
// FIXME: remove once we cast the data model to have uppercase item
// types.
return item_type.toUpperCase();
}
};
module.exports = ActionSummary; module.exports = ActionSummary;
-7
View File
@@ -8,13 +8,6 @@ const Comment = {
actions({id}, _, {loaders}) { actions({id}, _, {loaders}) {
return loaders.Actions.getByItemID.load(id); return loaders.Actions.getByItemID.load(id);
}, },
status({status}) {
// Because the status can be `null`, we do this check.
if (status) {
return status.toUpperCase();
}
},
asset({asset_id}, _, {loaders}) { asset({asset_id}, _, {loaders}) {
return loaders.Assets.getByID.load(asset_id); return loaders.Assets.getByID.load(asset_id);
} }
+2 -2
View File
@@ -1,6 +1,6 @@
const RootQuery = { const RootQuery = {
assets(_, args, {loaders, user}) { assets(_, args, {loaders, user}) {
if (user == null || !user.hasRoles('admin')) { if (user == null || !user.hasRoles('ADMIN')) {
return null; return null;
} }
@@ -25,7 +25,7 @@ const RootQuery = {
// This endpoint is used for loading moderation queues, so hide it in the // This endpoint is used for loading moderation queues, so hide it in the
// event that we aren't an admin. // event that we aren't an admin.
comments(_, {query}, {loaders, user}) { comments(_, {query}, {loaders, user}) {
if (user == null || !user.hasRoles('admin')) { if (user == null || !user.hasRoles('ADMIN')) {
return null; return null;
} }
+1 -1
View File
@@ -6,7 +6,7 @@ const User = {
// If the user is not an admin, only return comment list for the owner of // If the user is not an admin, only return comment list for the owner of
// the comments. // the comments.
if (!user.hasRoles('admin') || user.id !== id) { if (!user.hasRoles('ADMIN') || user.id !== id) {
return null; return null;
} }
-1
View File
@@ -4,7 +4,6 @@ module.exports = () => Promise.all([
// Upsert the settings object. // Upsert the settings object.
SettingsService.init({ SettingsService.init({
id: '1',
moderation: 'PRE', moderation: 'PRE',
wordlist: { wordlist: {
banned: [], banned: [],
+1 -1
View File
@@ -10,7 +10,7 @@
"build-watch": "NODE_ENV=development webpack --config webpack.config.dev.js --watch", "build-watch": "NODE_ENV=development webpack --config webpack.config.dev.js --watch",
"lint": "eslint bin/* .", "lint": "eslint bin/* .",
"lint-fix": "eslint bin/* . --fix", "lint-fix": "eslint bin/* . --fix",
"test": "TEST_MODE=unit NODE_ENV=test mocha", "test": "TEST_MODE=unit NODE_ENV=test mocha -R ${NPM_PACKAGE_CONFIG_MOCHA_REPORTER:-spec}",
"test-cover": "TEST_MODE=unit NODE_ENV=test istanbul cover _mocha --report text --check-coverage -- -R spec", "test-cover": "TEST_MODE=unit NODE_ENV=test istanbul cover _mocha --report text --check-coverage -- -R spec",
"pree2e": "NODE_ENV=test scripts/pree2e.sh", "pree2e": "NODE_ENV=test scripts/pree2e.sh",
"e2e": "NODE_ENV=test nightwatch", "e2e": "NODE_ENV=test nightwatch",
+1 -1
View File
@@ -15,7 +15,7 @@ router.get('/login', (req, res, next) => {
}); });
router.get('*', (req, res) => { router.get('*', (req, res) => {
res.render('admin', {basePath: '/client/coral-admin'}); res.render('ADMIN', {basePath: '/client/coral-admin'});
}); });
module.exports = router; module.exports = router;
+6 -6
View File
@@ -22,13 +22,13 @@ router.get('/', (req, res, next) => {
} = req.query; } = req.query;
// everything on this route requires admin privileges besides listing comments for owner of said comments // everything on this route requires admin privileges besides listing comments for owner of said comments
if (!authorization.has(req.user, 'admin') && !user_id) { if (!authorization.has(req.user, 'ADMIN') && !user_id) {
next(errors.ErrNotAuthorized); next(errors.ErrNotAuthorized);
return; return;
} }
// if the user is not an admin, only return comment list for the owner of the comments // if the user is not an admin, only return comment list for the owner of the comments
if (req.user.id !== user_id && !authorization.has(req.user, 'admin')) { if (req.user.id !== user_id && !authorization.has(req.user, 'ADMIN')) {
next(errors.ErrNotAuthorized); next(errors.ErrNotAuthorized);
return; return;
} }
@@ -50,7 +50,7 @@ router.get('/', (req, res, next) => {
// otherwise this will be a vulnerability if you pass user_id and something else, // otherwise this will be a vulnerability if you pass user_id and something else,
// the app will return admin-level data without the proper checks // the app will return admin-level data without the proper checks
if (user_id) { if (user_id) {
query = CommentsService.findByUserId(user_id, authorization.has(req.user, 'admin')); query = CommentsService.findByUserId(user_id, authorization.has(req.user, 'ADMIN'));
} else if (status) { } else if (status) {
query = assetIDWrap(CommentsService.findByStatus(status === 'NEW' ? null : status)); query = assetIDWrap(CommentsService.findByStatus(status === 'NEW' ? null : status));
} else if (action_type) { } else if (action_type) {
@@ -85,7 +85,7 @@ router.get('/', (req, res, next) => {
}); });
}); });
router.get('/:comment_id', authorization.needed('admin'), (req, res, next) => { router.get('/:comment_id', authorization.needed('ADMIN'), (req, res, next) => {
CommentsService CommentsService
.findById(req.params.comment_id) .findById(req.params.comment_id)
.then(comment => { .then(comment => {
@@ -101,7 +101,7 @@ router.get('/:comment_id', authorization.needed('admin'), (req, res, next) => {
}); });
}); });
router.delete('/:comment_id', authorization.needed('admin'), (req, res, next) => { router.delete('/:comment_id', authorization.needed('ADMIN'), (req, res, next) => {
CommentsService CommentsService
.removeById(req.params.comment_id) .removeById(req.params.comment_id)
.then(() => { .then(() => {
@@ -112,7 +112,7 @@ router.delete('/:comment_id', authorization.needed('admin'), (req, res, next) =>
}); });
}); });
router.put('/:comment_id/status', authorization.needed('admin'), (req, res, next) => { router.put('/:comment_id/status', authorization.needed('ADMIN'), (req, res, next) => {
const { const {
status status
} = req.body; } = req.body;
+4 -4
View File
@@ -3,9 +3,9 @@ const authorization = require('../../middleware/authorization');
const router = express.Router(); const router = express.Router();
router.use('/assets', authorization.needed('admin'), require('./assets')); router.use('/assets', authorization.needed('ADMIN'), require('./assets'));
router.use('/settings', authorization.needed('admin'), require('./settings')); router.use('/settings', authorization.needed('ADMIN'), require('./settings'));
router.use('/queue', authorization.needed('admin'), require('./queue')); router.use('/queue', authorization.needed('ADMIN'), require('./queue'));
router.use('/comments', authorization.needed(), require('./comments')); router.use('/comments', authorization.needed(), require('./comments'));
router.use('/actions', authorization.needed(), require('./actions')); router.use('/actions', authorization.needed(), require('./actions'));
@@ -15,6 +15,6 @@ router.use('/users', require('./users'));
router.use('/account', require('./account')); router.use('/account', require('./account'));
// Bind the kue handler to the /kue path. // Bind the kue handler to the /kue path.
router.use('/kue', authorization.needed('admin'), require('../../services/kue').kue.app); router.use('/kue', authorization.needed('ADMIN'), require('../../services/kue').kue.app);
module.exports = router; module.exports = router;
+3 -3
View File
@@ -27,7 +27,7 @@ function gatherActionsAndUsers (comments) {
// depending on the settings. The :moderation overwrites this settings. // depending on the settings. The :moderation overwrites this settings.
// Pre-moderation: New comments are shown in the moderator queues immediately. // 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. // Post-moderation: New comments do not appear in moderation queues unless they are flagged by other users.
router.get('/comments/pending', authorization.needed('admin'), (req, res, next) => { router.get('/comments/pending', authorization.needed('ADMIN'), (req, res, next) => {
const {asset_id} = req.query; const {asset_id} = req.query;
@@ -41,7 +41,7 @@ router.get('/comments/pending', authorization.needed('admin'), (req, res, next)
}); });
}); });
router.get('/comments/rejected', authorization.needed('admin'), (req, res, next) => { router.get('/comments/rejected', authorization.needed('ADMIN'), (req, res, next) => {
const {asset_id} = req.query; const {asset_id} = req.query;
CommentsService.moderationQueue('REJECTED', asset_id) CommentsService.moderationQueue('REJECTED', asset_id)
@@ -54,7 +54,7 @@ router.get('/comments/rejected', authorization.needed('admin'), (req, res, next)
}); });
}); });
router.get('/comments/flagged', authorization.needed('admin'), (req, res, next) => { router.get('/comments/flagged', authorization.needed('ADMIN'), (req, res, next) => {
const {asset_id} = req.query; const {asset_id} = req.query;
const assetIDWrap = (query) => { const assetIDWrap = (query) => {
+4 -4
View File
@@ -6,7 +6,7 @@ const CommentsService = require('../../../services/comments');
const mailer = require('../../../services/mailer'); const mailer = require('../../../services/mailer');
const authorization = require('../../../middleware/authorization'); const authorization = require('../../../middleware/authorization');
router.get('/', authorization.needed('admin'), (req, res, next) => { router.get('/', authorization.needed('ADMIN'), (req, res, next) => {
const { const {
value = '', value = '',
field = 'created_at', field = 'created_at',
@@ -35,7 +35,7 @@ router.get('/', authorization.needed('admin'), (req, res, next) => {
.catch(next); .catch(next);
}); });
router.post('/:user_id/role', authorization.needed('admin'), (req, res, next) => { router.post('/:user_id/role', authorization.needed('ADMIN'), (req, res, next) => {
UsersService UsersService
.addRoleToUser(req.params.user_id, req.body.role) .addRoleToUser(req.params.user_id, req.body.role)
.then(() => { .then(() => {
@@ -44,7 +44,7 @@ router.post('/:user_id/role', authorization.needed('admin'), (req, res, next) =>
.catch(next); .catch(next);
}); });
router.post('/:user_id/status', authorization.needed('admin'), (req, res, next) => { router.post('/:user_id/status', authorization.needed('ADMIN'), (req, res, next) => {
UsersService UsersService
.setStatus(req.params.user_id, req.body.status) .setStatus(req.params.user_id, req.body.status)
.then((status) => { .then((status) => {
@@ -138,7 +138,7 @@ router.post('/:user_id/actions', authorization.needed(), (req, res, next) => {
}); });
}); });
router.post('/:user_id/email/confirm', authorization.needed('admin'), (req, res, next) => { router.post('/:user_id/email/confirm', authorization.needed('ADMIN'), (req, res, next) => {
const { const {
user_id user_id
} = req.params; } = req.params;
+9
View File
@@ -57,3 +57,12 @@ mongoose.connect(url, (err) => {
}); });
module.exports = mongoose; module.exports = mongoose;
// Here we include all the models that mongoose is used for, this ensures that
// when we import mongoose that we also start up all the indexing opreations
// here.
require('../models/action');
require('../models/asset');
require('../models/comment');
require('../models/setting');
require('../models/user');
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = { module.exports = {
'@tags': ['login', 'admin'], '@tags': ['login', 'ADMIN'],
before(client) { before(client) {
const embedStreamPage = client.page.embedStreamPage(); const embedStreamPage = client.page.embedStreamPage();
const {launchUrl} = client; const {launchUrl} = client;
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = { module.exports = {
'@tags': ['login', 'moderator'], '@tags': ['login', 'MODERATOR'],
before: client => { before: client => {
const embedStreamPage = client.page.embedStreamPage(); const embedStreamPage = client.page.embedStreamPage();
const {launchUrl} = client; const {launchUrl} = client;