Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kgardnr authored May 8, 2018
2 parents 0404478 + 778064d commit 5911f3e
Show file tree
Hide file tree
Showing 134 changed files with 4,097 additions and 594 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ plugins/*
!plugins/talk-plugin-google-auth
!plugins/talk-plugin-ignore-user
!plugins/talk-plugin-like
!plugins/talk-plugin-local-auth
!plugins/talk-plugin-love
!plugins/talk-plugin-member-since
!plugins/talk-plugin-mod
Expand All @@ -53,6 +54,7 @@ plugins/*
!plugins/talk-plugin-profile-data
!plugins/talk-plugin-remember-sort
!plugins/talk-plugin-respect
!plugins/talk-plugin-rich-text
!plugins/talk-plugin-slack-notifications
!plugins/talk-plugin-sort-most-downvoted
!plugins/talk-plugin-sort-most-liked
Expand All @@ -66,7 +68,6 @@ plugins/*
!plugins/talk-plugin-toxic-comments
!plugins/talk-plugin-upvote
!plugins/talk-plugin-viewing-options
!plugins/talk-plugin-rich-text

**/node_modules/*
yarn-error.log
7 changes: 6 additions & 1 deletion .nsprc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"exceptions": [
"https://nodesecurity.io/advisories/531",
"https://nodesecurity.io/advisories/532",
"https://nodesecurity.io/advisories/566"
"https://nodesecurity.io/advisories/566",
"https://nodesecurity.io/advisories/577",
"https://nodesecurity.io/advisories/594",
"https://nodesecurity.io/advisories/603",
"https://nodesecurity.io/advisories/611",
"https://nodesecurity.io/advisories/612"
]
}
27 changes: 4 additions & 23 deletions bin/cli
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/
const program = require('commander');

// We're requiring this here so it'll setup some promise rejection hooks to log
// out.
require('./util');
const program = require('commander');
const { head, map } = require('lodash');
const Matcher = require('did-you-mean');

// Setup the program.
program
.command('serve', 'serve the application')
.command('db', 'run database commands')
Expand All @@ -24,20 +22,3 @@ program
'provides utilities for interacting with the plugin system'
)
.parse(process.argv);

// If the command wasn't found, output help.
const commands = map(program.commands, '_name');
const command = head(program.args);
if (!commands.includes(command)) {
const m = new Matcher(commands);
const similarCommands = m.list(command);

console.error(
`cli '${command}' is not a talk cli command. See 'cli --help'.`
);
if (similarCommands.length > 0) {
const sc = similarCommands.map(({ value }) => `\t${value}\n`).join('');
console.error(`\nThe most similar commands are\n${sc}`);
}
process.exit(1);
}
19 changes: 11 additions & 8 deletions bin/cli-settings
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const util = require('./util');
const program = require('commander');
const inquirer = require('inquirer');
const mongoose = require('../services/mongoose');
const SettingsService = require('../services/settings');
const Settings = require('../services/settings');
const cache = require('../services/cache');

// Register the shutdown criteria.
util.onshutdown([() => mongoose.disconnect()]);
Expand All @@ -14,9 +15,12 @@ util.onshutdown([() => mongoose.disconnect()]);
*/
async function changeOrgName() {
try {
let settings = await SettingsService.retrieve();
await cache.init();

let { organizationName } = await inquirer.prompt([
// Get the original settings.
const settings = await Settings.retrieve('organizationName');

const { organizationName } = await inquirer.prompt([
{
name: 'organizationName',
message: 'Organization Name',
Expand All @@ -25,9 +29,8 @@ async function changeOrgName() {
]);

if (settings.organizationName !== organizationName) {
settings.organizationName = organizationName;

await SettingsService.update(settings);
// Set the organization name if there was a mutation to it.
await Settings.update({ organizationName });

console.log('Settings were updated.');
} else {
Expand All @@ -36,9 +39,9 @@ async function changeOrgName() {
} catch (err) {
console.error(err);
util.shutdown(1);
} finally {
util.shutdown();
}

util.shutdown();
}

//==============================================================================
Expand Down
7 changes: 5 additions & 2 deletions bin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ require('../services/env');
const debug = require('debug')('talk:util');
const { uniq } = require('lodash');

const util = (module.exports = {});
// Setup the utilities.
const util = {};

/**
* Stores an array of functions that should be executed in the event that the
Expand All @@ -15,7 +16,7 @@ util.toshutdown = [];

/**
* Calls all the shutdown functions and then ends the process.
* @param {Number} [defaultCode=0] default return code upon sucesfull shutdown.
* @param {Number} [defaultCode=0] default return code upon successful shutdown.
*/
util.shutdown = (defaultCode = 0, signal = null) => {
if (signal) {
Expand Down Expand Up @@ -63,3 +64,5 @@ process.on('unhandledRejection', err => {
console.error(err);
process.exit(1);
});

module.exports = util;
2 changes: 0 additions & 2 deletions client/coral-admin/src/components/UserDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ class UserDetail extends React.Component {
bulkReject,
} = this.props;

console.log(rejectedComments, totalComments);

// if totalComments is 0, you're dividing by zero
let rejectedPercent = rejectedComments / totalComments * 100;

Expand Down
31 changes: 31 additions & 0 deletions client/coral-admin/src/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,36 @@ export default {
},
},
}),
SetCommentStatus: ({ variables: { status } }) => ({
updateQueries: {
CoralAdmin_UserDetail: prev => {
const increment = {
rejectedComments: {
$apply: count => (count < prev.totalComments ? count + 1 : count),
},
};

const decrement = {
rejectedComments: {
$apply: count => (count > 0 ? count - 1 : 0),
},
};

// If rejected then increment rejectedComments by one
if (status === 'REJECTED') {
const updated = update(prev, increment);
return updated;
}

// If approved then decrement rejectedComments by one
if (status === 'ACCEPTED') {
const updated = update(prev, decrement);
return updated;
}

return prev;
},
},
}),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class OrganizationSettings extends React.Component {
}

const updater = { organizationContactEmail: { $set: email } };
const errorUpdater = { organizationEmail: { $set: error } };
const errorUpdater = { organizationContactEmail: { $set: error } };

this.props.updatePending({ updater, errorUpdater });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ProfileContainer.propTypes = {
currentUser: PropTypes.object,
};

const slots = ['profileSections'];
const slots = ['profileSections', 'profileSettings', 'profileHeader'];

const withProfileQuery = withQuery(
gql`
Expand Down
11 changes: 9 additions & 2 deletions client/coral-embed-stream/src/tabs/stream/components/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getActionSummary,
iPerformedThisAction,
isCommentActive,
isCommentDeleted,
getShallowChanges,
} from 'coral-framework/utils';
import t from 'coral-framework/services/i18n';
Expand Down Expand Up @@ -744,8 +745,14 @@ export default class Comment extends React.Component {

return (
<div className={rootClassName} id={id}>
{this.renderComment()}
{activeReplyBox === comment.id && this.renderReplyBox()}
{isCommentDeleted(comment) ? (
<CommentTombstone action="deleted" />
) : (
<div>
{this.renderComment()}
{activeReplyBox === comment.id && this.renderReplyBox()}
</div>
)}
{this.renderRepliesContainer()}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CommentTombstone extends React.Component {
return t('framework.comment_is_ignored');
case 'reject':
return t('framework.comment_is_rejected');
case 'deleted':
return t('framework.comment_is_deleted');
default:
return t('framework.comment_is_hidden');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ const slots = [
'streamTabsPrepend',
'streamTabPanes',
'streamFilter',
'stream',
];

const fragments = {
Expand Down
4 changes: 3 additions & 1 deletion client/coral-framework/graphql/fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default {
'UpdateAssetSettingsResponse',
'UpdateAssetStatusResponse',
'UpdateSettingsResponse',
'ChangePasswordResponse'
'ChangePasswordResponse',
'UpdateEmailAddressResponse',
'AttachLocalAuthResponse'
),
};
31 changes: 0 additions & 31 deletions client/coral-framework/graphql/mutations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { gql } from 'react-apollo';
import withMutation from '../hocs/withMutation';
import update from 'immutability-helper';

function convertItemType(item_type) {
switch (item_type) {
Expand Down Expand Up @@ -168,36 +167,6 @@ export const withSetCommentStatus = withMutation(
errors: null,
},
},
updateQueries: {
CoralAdmin_UserDetail: prev => {
const increment = {
rejectedComments: {
$apply: count =>
count < prev.totalComments ? count + 1 : count,
},
};

const decrement = {
rejectedComments: {
$apply: count => (count > 0 ? count - 1 : 0),
},
};

// If rejected then increment rejectedComments by one
if (status === 'REJECTED') {
const updated = update(prev, increment);
return updated;
}

// If approved then decrement rejectedComments by one
if (status === 'ACCEPTED') {
const updated = update(prev, decrement);
return updated;
}

return prev;
},
},
update: proxy => {
const fragment = gql`
fragment Talk_SetCommentStatus_Comment on Comment {
Expand Down
8 changes: 8 additions & 0 deletions client/coral-framework/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql } from 'react-apollo';
import t from 'coral-framework/services/i18n';
import union from 'lodash/union';
import get from 'lodash/get';
import { capitalize } from 'coral-framework/helpers/strings';
import assignWith from 'lodash/assignWith';
import mapValues from 'lodash/mapValues';
Expand Down Expand Up @@ -221,6 +222,13 @@ export function isCommentActive(commentStatus) {
return ['NONE', 'ACCEPTED'].indexOf(commentStatus) >= 0;
}

export function isCommentDeleted(comment) {
return (
get(comment, 'body', null) === null ||
get(comment, 'deleted_at', null) !== null
);
}

export function getShallowChanges(a, b) {
return union(Object.keys(a), Object.keys(b)).filter(key => a[key] !== b[key]);
}
Expand Down
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ const CONFIG = {
RECAPTCHA_PUBLIC: process.env.TALK_RECAPTCHA_PUBLIC,
RECAPTCHA_SECRET: process.env.TALK_RECAPTCHA_SECRET,

// RECAPTCHA_WINDOW is the rate limit's time interval
RECAPTCHA_WINDOW: process.env.TALK_RECAPTCHA_WINDOW || '10m',

// After RECAPTCHA_INCORRECT_TRIGGER incorrect attempts, recaptcha will be required.
RECAPTCHA_INCORRECT_TRIGGER:
process.env.TALK_RECAPTCHA_INCORRECT_TRIGGER || 5,

// WEBSOCKET_LIVE_URI is the absolute url to the live endpoint.
WEBSOCKET_LIVE_URI: process.env.TALK_WEBSOCKET_LIVE_URI || null,

Expand Down
4 changes: 3 additions & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ relative_link: false
future: true
highlight:
enable: false

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
Expand Down Expand Up @@ -114,6 +114,8 @@ sidebar:
url: /integrating/styling-css/
- title: Translations and i18n
url: /integrating/translations-i18n/
- title: GDPR Compliance
url: /integrating/gdpr/
- title: Product Guide
children:
- title: How Talk Works
Expand Down
14 changes: 13 additions & 1 deletion docs/source/02-02-advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@ default to providing only a time based lockout. Refer to
[reCAPTCHA](https://www.google.com/recaptcha/intro/index.html) for information
on getting an account setup.

## TALK_RECAPTCHA_WINDOW

The rate limit time interval that there can be [TALK_RECAPTCHA_INCORRECT_TRIGGER](#talk_recaptcha_incorrect_trigger) incorrect attempts until the reCAPTCHA is
marked as required, parsed by
[ms](https://www.npmjs.com/package/ms). (Default `10m`)

## TALK_RECAPTCHA_INCORRECT_TRIGGER

The number of times that an incorrect login can be entered before within a time
perioud indicated by [TALK_RECAPTCHA_WINDOW](#talk_recaptcha_window) until the
reCAPTCHA is marked as required. (Default `5`)

## TALK_REDIS_CLIENT_CONFIGURATION

Configuration overrides for the redis client configuration in a JSON encoded
Expand Down Expand Up @@ -531,4 +543,4 @@ Sets the logging level for the context logger (from [Bunyan](https://github.com/
A JSON string representing the configuration passed to the
[fetch](https://www.npmjs.com/package/node-fetch) call for the scraper. It
can be used to set an authorization header, or change the user agent. (Default
`{}`)
`{}`)
Loading

0 comments on commit 5911f3e

Please sign in to comment.