diff --git a/.eslintrc.json b/.eslintrc.json index 0c31cbb90..8b737cbd2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,8 @@ "no-eval": [2], "no-global-assign": [2], "no-implied-eval": [2], + "lines-around-comment": ["warn", {"beforeLineComment": true}], + "spaced-comment": ["warn", "always", { "line": { "exceptions": ["-", "="] } }], "no-script-url": [2], "no-throw-literal": [2], "yoda": [1], diff --git a/app.js b/app.js index 15a7a5442..79d09db65 100644 --- a/app.js +++ b/app.js @@ -22,6 +22,7 @@ if (app.get('env') !== 'test') { //============================================================================== app.set('trust proxy', 1); + // We disable frameward on helmet to allow crossdomain injection of the embed app.use(helmet({ frameguard: false diff --git a/bin/cli-serve b/bin/cli-serve index c22920eaa..5478b7c1e 100755 --- a/bin/cli-serve +++ b/bin/cli-serve @@ -60,11 +60,13 @@ function normalizePort(val) { let port = parseInt(val, 10); if (isNaN(port)) { + // named pipe return val; } if (port >= 0) { + // port number return port; } diff --git a/client/coral-admin/src/components/CommentList.js b/client/coral-admin/src/components/CommentList.js index 8c6655bb5..597ea62a6 100644 --- a/client/coral-admin/src/components/CommentList.js +++ b/client/coral-admin/src/components/CommentList.js @@ -31,6 +31,7 @@ export default class CommentList extends React.Component { // add key handlers and gestures componentDidMount () { this.bindKeyHandlers(); + // this.bindGestures() // need to check whether we're on a mobile device or this throws an Error } @@ -80,6 +81,7 @@ export default class CommentList extends React.Component { const {commentIds} = this.props; const {active} = this.state; + // check boundaries if (active === null || !commentIds.length) { this.setState({active: commentIds[0]}); @@ -102,6 +104,7 @@ export default class CommentList extends React.Component { // TODO: In the future this can be improved and look at the actual state to // resolve since the content of the list could change externally. For now it works as expected onClickAction (action, id, author_id) { + // activate the next comment if (id === this.state.active) { const {commentIds} = this.props; diff --git a/client/coral-admin/src/containers/Configure/CommentSettings.js b/client/coral-admin/src/containers/Configure/CommentSettings.js index 5819076c6..050432743 100644 --- a/client/coral-admin/src/containers/Configure/CommentSettings.js +++ b/client/coral-admin/src/containers/Configure/CommentSettings.js @@ -69,11 +69,17 @@ const updateClosedTimeout = (updateSettings, ts, isMeasure) => (event) => { } }; -const CommentSettings = ({updateSettings, settingsError, settings, errors}) => +const CommentSettings = ({fetchingSettings, updateSettings, settingsError, settings, errors}) => { + if (fetchingSettings) { + /* maybe a spinner here at some point */ + return

Loading settings...

; + } + + return @@ -86,7 +92,7 @@ const CommentSettings = ({updateSettings, settingsError, settings, errors}) => < @@ -113,7 +119,7 @@ const CommentSettings = ({updateSettings, settingsError, settings, errors}) => < @@ -144,7 +150,9 @@ const CommentSettings = ({updateSettings, settingsError, settings, errors}) => < value={getTimeoutAmount(settings.closedTimeout)} label={lang.t('configure.closed-comments-label')} />
- @@ -164,6 +172,7 @@ const CommentSettings = ({updateSettings, settingsError, settings, errors}) => < ; +}; export default CommentSettings; diff --git a/client/coral-admin/src/containers/Configure/Configure.js b/client/coral-admin/src/containers/Configure/Configure.js index 8dd106cd0..ed8ba9b26 100644 --- a/client/coral-admin/src/containers/Configure/Configure.js +++ b/client/coral-admin/src/containers/Configure/Configure.js @@ -78,6 +78,7 @@ class Configure extends React.Component { switch(section){ case 'comments': return {lang.t('modqueue.rejected')} this.onTabClick('flagged')} className={`mdl-tabs__tab ${styles.tab}`}>{lang.t('modqueue.flagged')} - {lang.t('modqueue.showshortcuts')} @@ -120,7 +122,7 @@ class ModerationQueue extends React.Component { handleClose={() => this.hideBanUserDialog()} onClickBanUser={(userId, commentId) => this.banUser(userId, commentId)} user={comments.banUser}/> -
+
- this.setState({modalOpen: false})} /> +
+ this.setState({modalOpen: false})} /> +
); + } } diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index ab542b4a0..7c9bc968f 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -38,6 +38,7 @@ Promise.all([ coralApi('/comments?action_type=flag') ]) .then(([pending, rejected, flagged]) => { + /* Combine seperate calls into a single object */ let all = {}; all.comments = pending.comments @@ -55,6 +56,7 @@ Promise.all([ return all; }) .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}); @@ -62,6 +64,7 @@ Promise.all([ 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 diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index e6cc8fbbc..7d1e6c612 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -58,6 +58,7 @@ class CommentStream extends Component { } componentDidMount () { + // Set up messaging between embedded Iframe an parent component this.pym = new Pym.Child({polling: 100}); diff --git a/client/coral-framework/actions/items.js b/client/coral-framework/actions/items.js index cd798c6b9..160dcb24c 100644 --- a/client/coral-framework/actions/items.js +++ b/client/coral-framework/actions/items.js @@ -118,6 +118,7 @@ export function getStream (assetUrl) { /* Sort comments by date*/ json.comments.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); const rels = json.comments.reduce((h, item) => { + /* Check for root and child comments. */ if ( item.asset_id === assetId && diff --git a/client/coral-framework/modules/i18n/i18n.js b/client/coral-framework/modules/i18n/i18n.js index 1d81e885c..d4ed36b09 100644 --- a/client/coral-framework/modules/i18n/i18n.js +++ b/client/coral-framework/modules/i18n/i18n.js @@ -9,6 +9,7 @@ import get from 'lodash/get'; class i18n { constructor (translations) { + /** * Register locales */ @@ -16,6 +17,7 @@ class i18n { this.locales = {'en': 'en', 'es': 'es'}; timeago.register('es_ES', esTA); this.timeagoInstance = new timeago(); + /** * Load translations */ @@ -55,6 +57,7 @@ class i18n { this.t = (key, ...replacements) => { if (has(this.translations, key)) { let translation = get(this.translations, key); + // replace any {n} with the arguments passed to this method replacements.forEach((str, i) => { translation = translation.replace(new RegExp(`\\{${i}\\}`, 'g'), str); diff --git a/client/coral-plugin-flags/FlagButton.js b/client/coral-plugin-flags/FlagButton.js index d0b9cb6b4..61c87ddcf 100644 --- a/client/coral-plugin-flags/FlagButton.js +++ b/client/coral-plugin-flags/FlagButton.js @@ -32,7 +32,7 @@ class FlagButton extends Component { const {postAction, addItem, updateItem, flag, id, author_id} = this.props; const {itemType, field, detail, step, otherText, posted} = this.state; - //Proceed to the next step or close the menu if we've reached the end + // Proceed to the next step or close the menu if we've reached the end if (step + 1 >= this.props.getPopupMenu.length) { this.setState({showMenu: false}); } else { @@ -41,6 +41,7 @@ class FlagButton extends Component { // If itemType and detail are both set, post the action if (itemType && detail && !posted) { + // Set the text from the "other" field if it exists. const updatedDetail = otherText || detail; let item_id; diff --git a/client/coral-settings/containers/SettingsContainer.js b/client/coral-settings/containers/SettingsContainer.js index 1036c0668..9c158cafb 100644 --- a/client/coral-settings/containers/SettingsContainer.js +++ b/client/coral-settings/containers/SettingsContainer.js @@ -21,6 +21,7 @@ class SignInContainer extends Component { } componentWillMount () { + // Fetch commentHistory this.props.fetchCommentsByUserId(this.props.userData.id); } @@ -38,6 +39,7 @@ class SignInContainer extends Component { const commentsMostRecentFirst = user .myComments.map(id => items.comments[id]) .sort(({created_at:a}, {created_at:b}) => { + // descending order, created_at // js date strings can be sorted lexigraphically. const aLessThanB = a < b ? 1 : 0; diff --git a/middleware/payload-filter.js b/middleware/payload-filter.js index 0cafd91fe..b4cf90021 100644 --- a/middleware/payload-filter.js +++ b/middleware/payload-filter.js @@ -7,6 +7,7 @@ const maxRecursion = 3; * payload response first based on user and role. */ module.exports = (req, res, next) => { + /** * Updates the original document based on filtering out for roles. * @param {Mixed} o original object to be modified diff --git a/models/user.js b/models/user.js index 287f57df2..13e1c0405 100644 --- a/models/user.js +++ b/models/user.js @@ -88,6 +88,7 @@ const UserSchema = new mongoose.Schema({ // Status provides a string that says in which state the account is. // When the account is banned, the user login is disabled. status: {type: String, enum: USER_STATUS, default: 'active'}, + // User's settings settings: { bio: { @@ -501,6 +502,7 @@ UserService.createPasswordResetToken = function (email) { .then(user => { if (user === null) { + // since we don't want to reveal that the email does/doesn't exist // just go ahead and resolve the Promise with null and check in the endpoint return Promise.resolve(null); @@ -528,6 +530,7 @@ UserService.verifyPasswordResetToken = token => { }); }) .then(decoded => { + /** * TODO: check the jti from this decoded token in redis * and make an entry if it does not exist. diff --git a/routes/admin/index.js b/routes/admin/index.js index 03852c375..6241dcedb 100644 --- a/routes/admin/index.js +++ b/routes/admin/index.js @@ -4,6 +4,7 @@ const router = express.Router(); // Get /password-reset expects a signed token (JWT) in the hash. // Links to this endpoint are generated by /views/password-reset-email.ejs. router.get('/password-reset', (req, res, next) => { + // TODO: store the redirect uri in the token or something fancy. // admins and regular users should probably be redirected to different places. res.render('password-reset', {redirectUri: process.env.TALK_ROOT_URL}); diff --git a/routes/api/assets/index.js b/routes/api/assets/index.js index 5aa9b8cc6..3be877e93 100644 --- a/routes/api/assets/index.js +++ b/routes/api/assets/index.js @@ -82,6 +82,7 @@ router.post('/:asset_id/scrape', (req, res, next) => { }); router.put('/:asset_id/settings', (req, res, next) => { + // Override the settings for the asset. Asset .overrideSettings(req.params.asset_id, req.body) diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 0c686cfa0..802af977d 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -107,6 +107,7 @@ router.post('/', wordlist.filter('body'), (req, res, next) => { // Check to see if the asset has closed commenting... if (asset.isClosed) { + // They have, ensure that we send back an error. return Promise.reject(new Error(`asset has commenting closed because: ${asset.closedMessage}`)); } @@ -117,6 +118,7 @@ router.post('/', wordlist.filter('body'), (req, res, next) => { // Return `premod` if pre-moderation is enabled and an empty "new" status // in the event that it is not in pre-moderation mode. .then(({moderation, charCountEnable, charCount}) => { + // Reject if the comment is too long if (charCountEnable && body.length > charCount) { return 'rejected'; diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index 8d70adbb4..6c1fb38ab 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -25,6 +25,7 @@ router.get('/', (req, res, next) => { // Get the asset_id for this url (or create it if it doesn't exist) Promise.all([ + // Find or create the asset by url. Asset.findOrCreateByUrl(asset_url) @@ -70,6 +71,7 @@ router.get('/', (req, res, next) => { settings ]); }) + // Get all the users and actions for those comments. .then(([comments, asset, settings]) => { diff --git a/routes/api/users/index.js b/routes/api/users/index.js index 5b0c48de8..0edfd9584 100644 --- a/routes/api/users/index.js +++ b/routes/api/users/index.js @@ -123,6 +123,7 @@ router.post('/request-password-reset', (req, res, next) => { to: email, html: resetEmailTemplate({ token, + // probably more clear to explicitly pass this rootURL: process.env.TALK_ROOT_URL }) diff --git a/routes/embed/index.js b/routes/embed/index.js index 519de9d2f..400d2eb4b 100644 --- a/routes/embed/index.js +++ b/routes/embed/index.js @@ -6,6 +6,7 @@ router.use('/:embed', (req, res, next) => { case 'stream': return res.render('embed/stream', {}); default: + // will return a 404. return next(); } diff --git a/services/mongoose.js b/services/mongoose.js index 0f728ef16..03c87b937 100644 --- a/services/mongoose.js +++ b/services/mongoose.js @@ -2,7 +2,7 @@ const mongoose = require('mongoose'); const debug = require('debug')('talk:db'); const enabled = require('debug').enabled; -//Append '-test' to the db if node_env === 'test' +// Append '-test' to the db if node_env === 'test' let url = process.env.TALK_MONGO_URL || 'mongodb://localhost/coral-talk'; if (process.env.NODE_ENV === 'test') { diff --git a/tests/client/coral-framework/store/itemActions.spec.js b/tests/client/coral-framework/store/itemActions.spec.js index fb7044b7b..7332052a4 100644 --- a/tests/client/coral-framework/store/itemActions.spec.js +++ b/tests/client/coral-framework/store/itemActions.spec.js @@ -74,7 +74,7 @@ describe('itemActions', () => { }); }); - //Disabling tests for this function until is is used again. + // Disabling tests for this function until is is used again. xdescribe('getItemsArray', () => { const response = {items: [{type: 'comment', id: '123'}, {type: 'comment', id: '456'}]}; const ids = [1, 2]; diff --git a/tests/e2e/tests/EmbedStreamTests.js b/tests/e2e/tests/EmbedStreamTests.js index 65ea9fa76..93b84b383 100644 --- a/tests/e2e/tests/EmbedStreamTests.js +++ b/tests/e2e/tests/EmbedStreamTests.js @@ -18,12 +18,13 @@ module.exports = { client.perform((client, done) => { mocks.settings({moderation: 'post'}) .then(() => { - //Load Page + + // Load Page client.resizeWindow(1200, 800) .url(client.globals.baseUrl) .frame('coralStreamIframe') - //Register and Log In + // Register and Log In .waitForElementVisible('#commentBox', 1000) .waitForElementVisible('#coralSignInButton', 2000) .click('#coralSignInButton') @@ -44,7 +45,7 @@ module.exports = { .click('.coral-plugin-commentbox-button') .waitForElementVisible('.comment', 1000) - //Verify that it appears + // Verify that it appears .assert.containsText('.comment', mockComment); done(); }) @@ -58,7 +59,8 @@ module.exports = { client.perform((client, done) => { mocks.settings({moderation: 'pre'}) .then(() => { - //Load Page + + // Load Page client.url(client.globals.baseUrl) .frame('coralStreamIframe'); @@ -68,7 +70,7 @@ module.exports = { .click('.coral-plugin-commentbox-button') .waitForElementVisible('#coral-notif', 1000) - //Verify that it appears + // Verify that it appears .assert.containsText('#coral-notif', 'moderation team'); done(); }) @@ -82,7 +84,8 @@ module.exports = { client.perform((client, done) => { mocks.settings({moderation: 'post'}) .then(() => { - //Load Page + + // Load Page client.resizeWindow(1200, 800) .url(client.globals.baseUrl) .frame('coralStreamIframe'); @@ -100,7 +103,7 @@ module.exports = { .click('.coral-plugin-replies-textarea button') .waitForElementVisible('.reply', 2000) - //Verify that it appears + // Verify that it appears .assert.containsText('.reply', mockReply); done(); }) @@ -132,7 +135,8 @@ module.exports = { }]); }) .then(() => { - //Load Page + + // Load Page client.resizeWindow(1200, 800) .url(client.globals.baseUrl) .frame('coralStreamIframe'); @@ -145,7 +149,7 @@ module.exports = { .click('.coral-plugin-replies-textarea button') .waitForElementVisible('#coral-notif', 1000) - //Verify that it appears + // Verify that it appears .assert.containsText('#coral-notif', 'moderation team'); done(); }) diff --git a/tests/utils/e2e-mongoose.js b/tests/utils/e2e-mongoose.js index 0b630c0e3..fd639864e 100644 --- a/tests/utils/e2e-mongoose.js +++ b/tests/utils/e2e-mongoose.js @@ -3,8 +3,10 @@ const mongoose = require('../../services/mongoose'); // Ensure the NODE_ENV is set to 'test', // this is helpful when you would like to change behavior when testing. function clearDB() { + // console.log('Clearing DB', mongoose.connection); for (let i in mongoose.connection.collections) { + // console.log('Clearing', i); mongoose.connection.collections[i].remove(function() {}); }