From 4be9e74ed9309028af4845edd74ef57fb4794b11 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 26 Jan 2018 12:58:16 -0700 Subject: [PATCH 01/18] removed unused code --- bin/verifications/database/action_counts.js | 194 ------------------ bin/verifications/database/comment_replies.js | 140 ------------- bin/verifications/database/index.js | 10 - 3 files changed, 344 deletions(-) delete mode 100644 bin/verifications/database/action_counts.js delete mode 100644 bin/verifications/database/comment_replies.js delete mode 100644 bin/verifications/database/index.js diff --git a/bin/verifications/database/action_counts.js b/bin/verifications/database/action_counts.js deleted file mode 100644 index 684c17bca..000000000 --- a/bin/verifications/database/action_counts.js +++ /dev/null @@ -1,194 +0,0 @@ -const UserModel = require('../../../models/user'); -const CommentModel = require('../../../models/comment'); -const ActionsService = require('../../../services/actions'); -const { arrayJoinBy } = require('../../../graph/loaders/util'); -const { get } = require('lodash'); -const debug = require('debug')('talk:cli:verify'); - -const MODELS = [UserModel, CommentModel]; - -async function processBatch(Model, documents) { - // Get an array of all the document id's. - const documentIDs = documents.map(({ id }) => id); - - // Store all the operations on this batch in this array that we'll return - // later. - const operations = []; - - // Get the action summaries for this batch. - const totalActionSummaries = await ActionsService.getActionSummaries( - documentIDs - ).then(arrayJoinBy(documentIDs, 'item_id')); - - // Iterate over the documents. - for (let i = 0; i < documents.length; i++) { - const document = documents[i]; - const actionSummaries = totalActionSummaries[i]; - - let ops = []; - - for (const actionSummary of actionSummaries) { - if (actionSummary.group_id === null) { - continue; - } - - // And we generate the group id. - const ACTION_TYPE = actionSummary.action_type.toLowerCase(); - const GROUP_ID = actionSummary.group_id.toLowerCase(); - - if (GROUP_ID.length <= 0) { - continue; - } - - // And we add a new batch operation if the action summary is associated - // with a group. - const ACTION_COUNT_FIELD = `${ACTION_TYPE}_${GROUP_ID}`; - - // Check that the action summaries match the cached counts. - if ( - get(document, ['action_counts', ACTION_COUNT_FIELD]) !== - actionSummary.count - ) { - // Batch updates for those changes. - ops.push({ - [`action_counts.${ACTION_COUNT_FIELD}`]: actionSummary.count, - }); - } - } - - // Group all the action summaries together from all the different group - // ids. - const groupedActionSummaries = actionSummaries.reduce( - (acc, actionSummary) => { - // action_type is already snake cased (as it would have had to be when it - // was inserted in the database). - const ACTION_TYPE = actionSummary.action_type.toLowerCase(); - - if (!(ACTION_TYPE in acc)) { - acc[ACTION_TYPE] = 0; - } - - acc[ACTION_TYPE] += actionSummary.count; - - return acc; - }, - {} - ); - - for (const ACTION_COUNT_FIELD of Object.keys(groupedActionSummaries)) { - const count = groupedActionSummaries[ACTION_COUNT_FIELD]; - - // Check that the action summaries match the cached counts. - if (get(document, ['action_counts', ACTION_COUNT_FIELD]) !== count) { - // Batch updates for those changes. - ops.push({ - [`action_counts.${ACTION_COUNT_FIELD}`]: count, - }); - } - } - - // If this comment has action summaries that should be updated, then - // perform an update! - if (ops.length > 0) { - operations.push({ - updateOne: { - filter: { - id: document.id, - }, - update: { - $set: Object.assign({}, ...ops), - }, - }, - }); - } - } - - return operations; -} - -module.exports = async ({ fix, batch }) => { - for (const Model of MODELS) { - const cursor = Model.collection - .find({}) - .project({ - id: 1, - action_counts: 1, - }) - .sort({ created_at: 1 }); - - let operations = []; - let documents = []; - - // While there are documents to process. - while (await cursor.hasNext()) { - // Load the document. - const document = await cursor.next(); - - // Push the document into the documents array. - documents.push(document); - - // Check to see if the length of the documents array requires us to - // process it. - if (documents.length > batch) { - // Process this batch. - let batchOperations = await processBatch(Model, documents); - - // Push the batch operations into the model operations. - operations.push(...batchOperations); - - // Clear this batch contents. - documents = []; - } - } - - // Check to see if there are any documents left over. - if (documents.length > 0) { - // Process this batch. - let batchOperations = await processBatch(Model, documents); - - // Push the batch operations into the model operations. - operations.push(...batchOperations); - } - - const OPERATIONS_LENGTH = operations.length; - - console.log( - `action_counts.js: ${OPERATIONS_LENGTH} ${ - Model.collection.name - } need their action counts fixed.` - ); - - // If fix was enabled, execute the batch writes. - if (OPERATIONS_LENGTH > 0) { - if (fix) { - debug( - `action_counts.js: fixing ${OPERATIONS_LENGTH} ${ - Model.collection.name - }...` - ); - - while (operations.length) { - let result = await Model.collection.bulkWrite( - operations.splice(0, batch) - ); - - debug( - `action_counts.js: fixed batch of ${result.modifiedCount} ${ - Model.collection.name - }.` - ); - } - - console.log( - `action_counts.js: applied all ${OPERATIONS_LENGTH} fixes to ${ - Model.collection.name - }.` - ); - } else { - console.warn( - 'Skipping fixing, --fix was not enabled, pass --fix to fix these errors' - ); - } - } - } -}; diff --git a/bin/verifications/database/comment_replies.js b/bin/verifications/database/comment_replies.js deleted file mode 100644 index 309023c75..000000000 --- a/bin/verifications/database/comment_replies.js +++ /dev/null @@ -1,140 +0,0 @@ -const CommentModel = require('../../../models/comment'); -const { singleJoinBy } = require('../../../graph/loaders/util'); -const debug = require('debug')('talk:cli:verify'); - -const getBatch = async (limit, offset) => - CommentModel.find({}) - .select({ id: 1, action_counts: 1, reply_count: 1 }) - .limit(limit) - .skip(offset) - .sort('created_at'); - -module.exports = async ({ fix, limit, batch }) => { - let operations = []; - - // Count how many comments there are to process. - const totalCount = await CommentModel.count(); - - let offset = 0; - let comments = []; - let commentIDs = []; - - console.log(`Processing ${totalCount} comments in batches of ${limit}...`); - - // Keep processing documents until there are is none left. - while (offset < totalCount) { - // Get a batch of comments. - comments = await getBatch(batch, offset); - commentIDs = comments.map(({ id }) => id); - - // Get their reply counts. - let allReplyCounts = await CommentModel.aggregate([ - { - $match: { - parent_id: { - $in: commentIDs, - }, - status: { - $in: ['NONE', 'ACCEPTED'], - }, - }, - }, - { - $group: { - _id: '$parent_id', - count: { - $sum: 1, - }, - }, - }, - ]) - .then(singleJoinBy(commentIDs, '_id')) - .then(results => results.map(result => (result ? result.count : 0))); - - // Loop over the comments, with their action summaries. - for (let i = 0; i < comments.length; i++) { - let comment = comments[i]; - let replyCount = allReplyCounts[i]; - - // And check to see if the action summaries we just computed match what is - // currently set for the comments. - let commentOperations = []; - - // If the reply count needs to be updated, then update it! - if (comment.reply_count !== replyCount) { - commentOperations.push({ - reply_count: replyCount, - }); - } - - // If this comment has action summaries that should be updated, then - // perform an update! - if (commentOperations.length > 0) { - operations.push({ - updateOne: { - filter: { - id: comment.id, - }, - update: { - $set: Object.assign({}, ...commentOperations), - }, - }, - }); - } - } - - debug(`Processed batch of ${comments.length} comments.`); - - if (operations.length >= limit) { - debug( - `Queued operations are ${ - operations.length - }, reached limit of ${limit}, not processing any more.` - ); - - if (operations.length > limit) { - debug( - `${operations.length - - limit} operations have been truncated to enforce the limit` - ); - } - - break; - } - - offset += batch; - } - - const OPERATIONS_LENGTH = operations.length; - - if (limit < Infinity && offset + comments.length < totalCount) { - console.log( - `Processed ${offset + - comments.length}/${totalCount} comments because we reached the update limit of ${limit}.` - ); - } else { - console.log(`Processed all ${totalCount} comments.`); - } - - console.log(`${OPERATIONS_LENGTH} documents need fixing.`); - - // If fix was enabled, execute the batch writes. - if (OPERATIONS_LENGTH > 0) { - if (fix) { - debug(`Fixing ${OPERATIONS_LENGTH} documents...`); - - while (operations.length) { - let batchOperations = operations.splice(0, batch); - let result = await CommentModel.collection.bulkWrite(batchOperations); - - debug(`Fixed batch of ${result.modifiedCount} documents.`); - } - - console.log(`Applied all ${OPERATIONS_LENGTH} fixes.`); - } else { - console.warn( - 'Skipping fixing, --fix was not enabled, pass --fix to fix these errors' - ); - } - } -}; diff --git a/bin/verifications/database/index.js b/bin/verifications/database/index.js deleted file mode 100644 index 58a46bd85..000000000 --- a/bin/verifications/database/index.js +++ /dev/null @@ -1,10 +0,0 @@ -// This will import all the verifications that should be run by the: -// -// cli verify database -// -// command. They exist in the form: -// -// async ({fix = false, batch = 1000}) => {} -// -// where their options are derived. -module.exports = [require('./comment_replies'), require('./action_counts')]; From bc42539fc452edd869c95d8f130684da348c6db8 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 29 Jan 2018 10:02:38 -0700 Subject: [PATCH 02/18] cleanup --- bin/cli-users | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bin/cli-users b/bin/cli-users index 6e901f529..cb87445c5 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -28,7 +28,6 @@ const CommentModel = require('../models/comment'); const ActionModel = require('../models/action'); const USER_ROLES = require('../models/enum/user_roles'); const mongoose = require('../services/mongoose'); -const databaseVerifications = require('./verifications/database'); // Register the shutdown criteria. util.onshutdown([() => mongoose.disconnect()]); @@ -65,6 +64,8 @@ async function deleteUser(userID) { console.warn("Removing user's actions"); + // FIXME: fix the counts. + // Remove all the user's actions. await ActionModel.where({ user_id: user.id }) .setOptions({ multi: true }) @@ -77,13 +78,6 @@ async function deleteUser(userID) { .setOptions({ multi: true }) .remove(); - console.warn('Updating the database indexes'); - - // Update the counts that might have changed. - for (const verification of databaseVerifications) { - await verification({ fix: true, limit: Infinity, batch: 1000 }); - } - console.warn('Removing the user'); // Remove the user. From c355e10453e3fe6203847505f18017715cdcc9b8 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 29 Jan 2018 19:21:42 +0100 Subject: [PATCH 03/18] Refactor --- client/coral-embed-stream/src/AppRouter.js | 2 +- .../src}/containers/LoginContainer.js | 0 .../coral-embed-stream/src/tabs/stream/components/Comment.js | 2 +- .../src/tabs/stream/components}/InfoBox.js | 0 .../src/tabs/stream/components/ModerationLink.css} | 0 .../src/tabs/stream/components}/ModerationLink.js | 2 +- .../coral-embed-stream/src/tabs/stream/components/Stream.js | 4 ++-- .../src/tabs/stream/components}/TagLabel.js | 0 .../src/tabs/stream/components}/__tests__/InfoBox.spec.js | 0 .../components}/__tests__/__snapshots__/InfoBox.spec.js.snap | 0 client/talk-plugin-moderation/index.js | 1 - 11 files changed, 5 insertions(+), 6 deletions(-) rename client/{coral-sign-in => coral-embed-stream/src}/containers/LoginContainer.js (100%) rename client/{talk-plugin-infobox => coral-embed-stream/src/tabs/stream/components}/InfoBox.js (100%) rename client/{talk-plugin-moderation/styles.css => coral-embed-stream/src/tabs/stream/components/ModerationLink.css} (100%) rename client/{talk-plugin-moderation => coral-embed-stream/src/tabs/stream/components}/ModerationLink.js (94%) rename client/{talk-plugin-tag-label => coral-embed-stream/src/tabs/stream/components}/TagLabel.js (100%) rename client/{talk-plugin-infobox => coral-embed-stream/src/tabs/stream/components}/__tests__/InfoBox.spec.js (100%) rename client/{talk-plugin-infobox => coral-embed-stream/src/tabs/stream/components}/__tests__/__snapshots__/InfoBox.spec.js.snap (100%) delete mode 100644 client/talk-plugin-moderation/index.js diff --git a/client/coral-embed-stream/src/AppRouter.js b/client/coral-embed-stream/src/AppRouter.js index 4b101fb61..ec7b6300a 100644 --- a/client/coral-embed-stream/src/AppRouter.js +++ b/client/coral-embed-stream/src/AppRouter.js @@ -3,7 +3,7 @@ import { Router, Route } from 'react-router'; import PropTypes from 'prop-types'; import Embed from './containers/Embed'; -import { LoginContainer } from 'coral-sign-in/containers/LoginContainer'; +import { LoginContainer } from './containers/LoginContainer'; const routes = (
diff --git a/client/coral-sign-in/containers/LoginContainer.js b/client/coral-embed-stream/src/containers/LoginContainer.js similarity index 100% rename from client/coral-sign-in/containers/LoginContainer.js rename to client/coral-embed-stream/src/containers/LoginContainer.js diff --git a/client/coral-embed-stream/src/tabs/stream/components/Comment.js b/client/coral-embed-stream/src/tabs/stream/components/Comment.js index cd0fab9e9..d285f9d83 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Comment.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Comment.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import TagLabel from 'talk-plugin-tag-label/TagLabel'; +import TagLabel from './TagLabel'; import CommentTimestamp from 'coral-framework/components/CommentTimestamp'; import { ReplyBox, ReplyButton } from 'talk-plugin-replies'; import { FlagComment } from 'talk-plugin-flags'; diff --git a/client/talk-plugin-infobox/InfoBox.js b/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js similarity index 100% rename from client/talk-plugin-infobox/InfoBox.js rename to client/coral-embed-stream/src/tabs/stream/components/InfoBox.js diff --git a/client/talk-plugin-moderation/styles.css b/client/coral-embed-stream/src/tabs/stream/components/ModerationLink.css similarity index 100% rename from client/talk-plugin-moderation/styles.css rename to client/coral-embed-stream/src/tabs/stream/components/ModerationLink.css diff --git a/client/talk-plugin-moderation/ModerationLink.js b/client/coral-embed-stream/src/tabs/stream/components/ModerationLink.js similarity index 94% rename from client/talk-plugin-moderation/ModerationLink.js rename to client/coral-embed-stream/src/tabs/stream/components/ModerationLink.js index c40c50b82..d33f18a5e 100644 --- a/client/talk-plugin-moderation/ModerationLink.js +++ b/client/coral-embed-stream/src/tabs/stream/components/ModerationLink.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import styles from './styles.css'; +import styles from './ModerationLink.css'; import cn from 'classnames'; import t from 'coral-framework/services/i18n'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/Stream.js b/client/coral-embed-stream/src/tabs/stream/components/Stream.js index 6288a2b6b..4a6edbfe0 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Stream.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Stream.js @@ -5,9 +5,9 @@ import Comment from '../containers/Comment'; import BannedAccount from '../../../components/BannedAccount'; import ChangeUsername from '../containers/ChangeUsername'; import Slot from 'coral-framework/components/Slot'; -import InfoBox from 'talk-plugin-infobox/InfoBox'; +import InfoBox from './InfoBox'; import { can } from 'coral-framework/services/perms'; -import { ModerationLink } from 'talk-plugin-moderation'; +import ModerationLink from './ModerationLink'; import RestrictedMessageBox from 'coral-framework/components/RestrictedMessageBox'; import t, { timeago } from 'coral-framework/services/i18n'; import CommentBox from 'talk-plugin-commentbox/CommentBox'; diff --git a/client/talk-plugin-tag-label/TagLabel.js b/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js similarity index 100% rename from client/talk-plugin-tag-label/TagLabel.js rename to client/coral-embed-stream/src/tabs/stream/components/TagLabel.js diff --git a/client/talk-plugin-infobox/__tests__/InfoBox.spec.js b/client/coral-embed-stream/src/tabs/stream/components/__tests__/InfoBox.spec.js similarity index 100% rename from client/talk-plugin-infobox/__tests__/InfoBox.spec.js rename to client/coral-embed-stream/src/tabs/stream/components/__tests__/InfoBox.spec.js diff --git a/client/talk-plugin-infobox/__tests__/__snapshots__/InfoBox.spec.js.snap b/client/coral-embed-stream/src/tabs/stream/components/__tests__/__snapshots__/InfoBox.spec.js.snap similarity index 100% rename from client/talk-plugin-infobox/__tests__/__snapshots__/InfoBox.spec.js.snap rename to client/coral-embed-stream/src/tabs/stream/components/__tests__/__snapshots__/InfoBox.spec.js.snap diff --git a/client/talk-plugin-moderation/index.js b/client/talk-plugin-moderation/index.js deleted file mode 100644 index 38426167a..000000000 --- a/client/talk-plugin-moderation/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as ModerationLink } from './ModerationLink'; From 0799e9d8ee86b4c2374175ae29990116ceb6d8c5 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 29 Jan 2018 20:52:44 +0100 Subject: [PATCH 04/18] More refactor --- client/coral-embed-stream/src/components/Embed.js | 2 +- .../src/tabs/profile/components}/Comment.css | 0 .../src/tabs/profile/components}/Comment.js | 2 +- .../src/tabs/profile/components}/CommentHistory.js | 0 .../src/tabs/profile/components}/LoadMore.js | 0 .../src/tabs/profile}/components/NotLoggedIn.css | 0 .../src/tabs/profile}/components/NotLoggedIn.js | 0 .../src/tabs/profile}/containers/ProfileContainer.js | 2 +- services/comments.js | 2 ++ 9 files changed, 5 insertions(+), 3 deletions(-) rename client/{talk-plugin-history => coral-embed-stream/src/tabs/profile/components}/Comment.css (100%) rename client/{talk-plugin-history => coral-embed-stream/src/tabs/profile/components}/Comment.js (99%) rename client/{talk-plugin-history => coral-embed-stream/src/tabs/profile/components}/CommentHistory.js (100%) rename client/{talk-plugin-history => coral-embed-stream/src/tabs/profile/components}/LoadMore.js (100%) rename client/{coral-settings => coral-embed-stream/src/tabs/profile}/components/NotLoggedIn.css (100%) rename client/{coral-settings => coral-embed-stream/src/tabs/profile}/components/NotLoggedIn.js (100%) rename client/{coral-settings => coral-embed-stream/src/tabs/profile}/containers/ProfileContainer.js (98%) diff --git a/client/coral-embed-stream/src/components/Embed.js b/client/coral-embed-stream/src/components/Embed.js index e64a54caa..980e5745e 100644 --- a/client/coral-embed-stream/src/components/Embed.js +++ b/client/coral-embed-stream/src/components/Embed.js @@ -9,7 +9,7 @@ import AutomaticAssetClosure from '../containers/AutomaticAssetClosure'; import ExtendableTabPanel from '../containers/ExtendableTabPanel'; import { Tab, TabPane } from 'coral-ui'; -import ProfileContainer from 'coral-settings/containers/ProfileContainer'; +import ProfileContainer from '../tabs/profile/containers/ProfileContainer'; import Popup from 'coral-framework/components/Popup'; import IfSlotIsNotEmpty from 'coral-framework/components/IfSlotIsNotEmpty'; import cn from 'classnames'; diff --git a/client/talk-plugin-history/Comment.css b/client/coral-embed-stream/src/tabs/profile/components/Comment.css similarity index 100% rename from client/talk-plugin-history/Comment.css rename to client/coral-embed-stream/src/tabs/profile/components/Comment.css diff --git a/client/talk-plugin-history/Comment.js b/client/coral-embed-stream/src/tabs/profile/components/Comment.js similarity index 99% rename from client/talk-plugin-history/Comment.js rename to client/coral-embed-stream/src/tabs/profile/components/Comment.js index 015044b37..fec5863a2 100644 --- a/client/talk-plugin-history/Comment.js +++ b/client/coral-embed-stream/src/tabs/profile/components/Comment.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Icon } from '../coral-ui'; +import { Icon } from 'coral-ui'; import styles from './Comment.css'; import Slot from 'coral-framework/components/Slot'; import CommentTimestamp from 'coral-framework/components/CommentTimestamp'; diff --git a/client/talk-plugin-history/CommentHistory.js b/client/coral-embed-stream/src/tabs/profile/components/CommentHistory.js similarity index 100% rename from client/talk-plugin-history/CommentHistory.js rename to client/coral-embed-stream/src/tabs/profile/components/CommentHistory.js diff --git a/client/talk-plugin-history/LoadMore.js b/client/coral-embed-stream/src/tabs/profile/components/LoadMore.js similarity index 100% rename from client/talk-plugin-history/LoadMore.js rename to client/coral-embed-stream/src/tabs/profile/components/LoadMore.js diff --git a/client/coral-settings/components/NotLoggedIn.css b/client/coral-embed-stream/src/tabs/profile/components/NotLoggedIn.css similarity index 100% rename from client/coral-settings/components/NotLoggedIn.css rename to client/coral-embed-stream/src/tabs/profile/components/NotLoggedIn.css diff --git a/client/coral-settings/components/NotLoggedIn.js b/client/coral-embed-stream/src/tabs/profile/components/NotLoggedIn.js similarity index 100% rename from client/coral-settings/components/NotLoggedIn.js rename to client/coral-embed-stream/src/tabs/profile/components/NotLoggedIn.js diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-embed-stream/src/tabs/profile/containers/ProfileContainer.js similarity index 98% rename from client/coral-settings/containers/ProfileContainer.js rename to client/coral-embed-stream/src/tabs/profile/containers/ProfileContainer.js index e1bcf7f13..a818ebec4 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-embed-stream/src/tabs/profile/containers/ProfileContainer.js @@ -8,7 +8,7 @@ import cn from 'classnames'; import { link } from 'coral-framework/services/pym'; import NotLoggedIn from '../components/NotLoggedIn'; import { Spinner } from 'coral-ui'; -import CommentHistory from 'talk-plugin-history/CommentHistory'; +import CommentHistory from '../components/CommentHistory'; // TODO: Auth logic needs refactoring. import { diff --git a/services/comments.js b/services/comments.js index e18e04970..ea8f3bd96 100644 --- a/services/comments.js +++ b/services/comments.js @@ -84,6 +84,7 @@ module.exports = class CommentsService { * @param {String} status the new Comment status */ static async edit({ id, author_id, body, status }) { + console.log(status); const EDITABLE_STATUSES = ['NONE', 'PREMOD', 'ACCEPTED']; const query = { @@ -209,6 +210,7 @@ module.exports = class CommentsService { await events.emitAsync(COMMENTS_EDIT, originalComment, editedComment); + console.log(editedComment); return editedComment; } From 0a889fd1b3aa2637a1214c2f75c121624757dd37 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 29 Jan 2018 21:26:44 +0100 Subject: [PATCH 05/18] More Refactoring --- .../src/actions/commentBox.js} | 0 client/coral-embed-stream/src/constants/commentBox.js | 5 +++++ .../src/reducers/commentBox.js} | 2 +- client/coral-embed-stream/src/reducers/index.js | 2 +- .../src/tabs/stream/components/Comment.js | 3 ++- .../src/tabs/stream/components/CommentForm.css} | 0 .../src/tabs/stream/components}/CommentForm.js | 5 +++-- .../src/tabs/stream/components/EditableCommentContent.js | 6 ++++-- .../src/tabs/stream/components/InfoBox.js | 1 + .../src/tabs/stream/components}/ReplyBox.js | 3 ++- .../coral-embed-stream/src/tabs/stream/components/Stream.js | 2 +- .../src/tabs/stream/components/TagLabel.js | 2 ++ .../src/tabs/stream/containers}/CommentBox.js | 3 ++- client/talk-plugin-commentbox/constants.js | 3 --- client/talk-plugin-commentbox/index.js | 1 - client/talk-plugin-replies/index.js | 5 +---- plugin-api/alpha/client/actions/index.js | 2 +- services/comments.js | 2 -- 18 files changed, 26 insertions(+), 21 deletions(-) rename client/{talk-plugin-commentbox/actions.js => coral-embed-stream/src/actions/commentBox.js} (100%) create mode 100644 client/coral-embed-stream/src/constants/commentBox.js rename client/{talk-plugin-commentbox/reducer.js => coral-embed-stream/src/reducers/commentBox.js} (87%) rename client/{talk-plugin-commentbox/styles.css => coral-embed-stream/src/tabs/stream/components/CommentForm.css} (100%) rename client/{talk-plugin-commentbox => coral-embed-stream/src/tabs/stream/components}/CommentForm.js (97%) rename client/{talk-plugin-replies => coral-embed-stream/src/tabs/stream/components}/ReplyBox.js (94%) rename client/{talk-plugin-commentbox => coral-embed-stream/src/tabs/stream/containers}/CommentBox.js (98%) delete mode 100644 client/talk-plugin-commentbox/constants.js delete mode 100644 client/talk-plugin-commentbox/index.js diff --git a/client/talk-plugin-commentbox/actions.js b/client/coral-embed-stream/src/actions/commentBox.js similarity index 100% rename from client/talk-plugin-commentbox/actions.js rename to client/coral-embed-stream/src/actions/commentBox.js diff --git a/client/coral-embed-stream/src/constants/commentBox.js b/client/coral-embed-stream/src/constants/commentBox.js new file mode 100644 index 000000000..51130d6c0 --- /dev/null +++ b/client/coral-embed-stream/src/constants/commentBox.js @@ -0,0 +1,5 @@ +const prefix = 'TALK_EMBED_STREAM_COMMENT_BOX'; + +export const ADD_TAG = `${prefix}_ADD_TAG`; +export const REMOVE_TAG = `${prefix}_REMOVE_TAG`; +export const CLEAR_TAGS = `${prefix}_CLEAR_TAGS`; diff --git a/client/talk-plugin-commentbox/reducer.js b/client/coral-embed-stream/src/reducers/commentBox.js similarity index 87% rename from client/talk-plugin-commentbox/reducer.js rename to client/coral-embed-stream/src/reducers/commentBox.js index 4c6e496ed..9621f1447 100644 --- a/client/talk-plugin-commentbox/reducer.js +++ b/client/coral-embed-stream/src/reducers/commentBox.js @@ -1,4 +1,4 @@ -import { ADD_TAG, REMOVE_TAG, CLEAR_TAGS } from './constants'; +import { ADD_TAG, REMOVE_TAG, CLEAR_TAGS } from '../constants/commentBox'; const initialState = { tags: [], diff --git a/client/coral-embed-stream/src/reducers/index.js b/client/coral-embed-stream/src/reducers/index.js index e895a70df..0152c837d 100644 --- a/client/coral-embed-stream/src/reducers/index.js +++ b/client/coral-embed-stream/src/reducers/index.js @@ -4,7 +4,7 @@ import embed from './embed'; import config from './config'; import configure from './configure'; import stream from './stream'; -import { reducer as commentBox } from '../../../talk-plugin-commentbox'; +import commentBox from './commentBox'; export default { auth, diff --git a/client/coral-embed-stream/src/tabs/stream/components/Comment.js b/client/coral-embed-stream/src/tabs/stream/components/Comment.js index d285f9d83..68cba9bc9 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Comment.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Comment.js @@ -3,7 +3,8 @@ import PropTypes from 'prop-types'; import TagLabel from './TagLabel'; import CommentTimestamp from 'coral-framework/components/CommentTimestamp'; -import { ReplyBox, ReplyButton } from 'talk-plugin-replies'; +import { ReplyButton } from 'talk-plugin-replies'; +import ReplyBox from './ReplyBox'; import { FlagComment } from 'talk-plugin-flags'; import { can } from 'coral-framework/services/perms'; import { TransitionGroup } from 'react-transition-group'; diff --git a/client/talk-plugin-commentbox/styles.css b/client/coral-embed-stream/src/tabs/stream/components/CommentForm.css similarity index 100% rename from client/talk-plugin-commentbox/styles.css rename to client/coral-embed-stream/src/tabs/stream/components/CommentForm.css diff --git a/client/talk-plugin-commentbox/CommentForm.js b/client/coral-embed-stream/src/tabs/stream/components/CommentForm.js similarity index 97% rename from client/talk-plugin-commentbox/CommentForm.js rename to client/coral-embed-stream/src/tabs/stream/components/CommentForm.js index 62604d88f..ac9abc446 100644 --- a/client/talk-plugin-commentbox/CommentForm.js +++ b/client/coral-embed-stream/src/tabs/stream/components/CommentForm.js @@ -4,8 +4,9 @@ import { Button } from 'coral-ui'; import cn from 'classnames'; import Slot from 'coral-framework/components/Slot'; -import { name } from './CommentBox'; -import styles from './styles.css'; +// TODO: need to change this. +import { name } from '../containers/CommentBox'; +import styles from './CommentForm.css'; import t from 'coral-framework/services/i18n'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js b/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js index f4cfc42e8..7d3ae6600 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js +++ b/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js @@ -1,7 +1,9 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { notifyForNewCommentStatus } from 'talk-plugin-commentbox/CommentBox'; -import { CommentForm } from 'talk-plugin-commentbox/CommentForm'; + +// TODO: move this function. +import { notifyForNewCommentStatus } from '../containers/CommentBox'; +import { CommentForm } from './CommentForm'; import styles from './Comment.css'; import { CountdownSeconds } from './CountdownSeconds'; import { getEditableUntilDate } from './util'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js b/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js index 8577dbc9b..5e76c9911 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js +++ b/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js @@ -1,6 +1,7 @@ import React from 'react'; import Markdown from 'coral-framework/components/Markdown'; +// TODO: remove this. const packagename = 'talk-plugin-infobox'; const InfoBox = ({ enable, content }) => ( diff --git a/client/talk-plugin-replies/ReplyBox.js b/client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js similarity index 94% rename from client/talk-plugin-replies/ReplyBox.js rename to client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js index 2a6bd017b..03b56d990 100644 --- a/client/talk-plugin-replies/ReplyBox.js +++ b/client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js @@ -1,7 +1,8 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import CommentBox from '../talk-plugin-commentbox/CommentBox'; +import CommentBox from '../containers/CommentBox'; +// TODO: remove this.. const name = 'talk-plugin-replies'; class ReplyBox extends Component { diff --git a/client/coral-embed-stream/src/tabs/stream/components/Stream.js b/client/coral-embed-stream/src/tabs/stream/components/Stream.js index 4a6edbfe0..4492e7b53 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Stream.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Stream.js @@ -10,7 +10,7 @@ import { can } from 'coral-framework/services/perms'; import ModerationLink from './ModerationLink'; import RestrictedMessageBox from 'coral-framework/components/RestrictedMessageBox'; import t, { timeago } from 'coral-framework/services/i18n'; -import CommentBox from 'talk-plugin-commentbox/CommentBox'; +import CommentBox from '../containers/CommentBox'; import QuestionBox from '../../../components/QuestionBox'; import { isCommentActive } from 'coral-framework/utils'; import { Tab, TabCount, TabPane } from 'coral-ui'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js b/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js index 27d6bdde4..bbb324c22 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js +++ b/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js @@ -1,5 +1,7 @@ import React from 'react'; +// TODO: change className. + const TagLabel = ({ children }) => (
{children}
); diff --git a/client/talk-plugin-commentbox/CommentBox.js b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js similarity index 98% rename from client/talk-plugin-commentbox/CommentBox.js rename to client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js index 8eac1ff2f..9c04801c6 100644 --- a/client/talk-plugin-commentbox/CommentBox.js +++ b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js @@ -6,8 +6,9 @@ import { can } from 'coral-framework/services/perms'; import Slot from 'coral-framework/components/Slot'; import { connect } from 'react-redux'; -import { CommentForm } from './CommentForm'; +import { CommentForm } from '../components/CommentForm'; +// TODO: change this... export const name = 'talk-plugin-commentbox'; const notifyReasons = ['LINKS', 'TRUST']; diff --git a/client/talk-plugin-commentbox/constants.js b/client/talk-plugin-commentbox/constants.js deleted file mode 100644 index 4a80bfe4f..000000000 --- a/client/talk-plugin-commentbox/constants.js +++ /dev/null @@ -1,3 +0,0 @@ -export const ADD_TAG = 'ADD_TAG'; -export const REMOVE_TAG = 'REMOVE_TAG'; -export const CLEAR_TAGS = 'CLEAR_TAGS'; diff --git a/client/talk-plugin-commentbox/index.js b/client/talk-plugin-commentbox/index.js deleted file mode 100644 index cbc56ade5..000000000 --- a/client/talk-plugin-commentbox/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as reducer } from './reducer'; diff --git a/client/talk-plugin-replies/index.js b/client/talk-plugin-replies/index.js index 813d96672..f099e742b 100644 --- a/client/talk-plugin-replies/index.js +++ b/client/talk-plugin-replies/index.js @@ -1,4 +1 @@ -import ReplyBox from './ReplyBox'; -import ReplyButton from './ReplyButton'; - -export { ReplyBox, ReplyButton }; +export { default as ReplyButton } from './ReplyButton'; diff --git a/plugin-api/alpha/client/actions/index.js b/plugin-api/alpha/client/actions/index.js index 20bd2b9e3..9de7b5de3 100644 --- a/plugin-api/alpha/client/actions/index.js +++ b/plugin-api/alpha/client/actions/index.js @@ -1,4 +1,4 @@ -export { addTag, removeTag } from 'talk-plugin-commentbox/actions'; +export { addTag, removeTag } from 'coral-embed-stream/src/actions/commentBox'; export { addCommentClassName, removeCommentClassName, diff --git a/services/comments.js b/services/comments.js index ea8f3bd96..e18e04970 100644 --- a/services/comments.js +++ b/services/comments.js @@ -84,7 +84,6 @@ module.exports = class CommentsService { * @param {String} status the new Comment status */ static async edit({ id, author_id, body, status }) { - console.log(status); const EDITABLE_STATUSES = ['NONE', 'PREMOD', 'ACCEPTED']; const query = { @@ -210,7 +209,6 @@ module.exports = class CommentsService { await events.emitAsync(COMMENTS_EDIT, originalComment, editedComment); - console.log(editedComment); return editedComment; } From 8d656b51a0455f91c4e8532c633ee3f8a3949242 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 29 Jan 2018 13:56:09 -0700 Subject: [PATCH 06/18] introduced count adjusters for deleting a user --- bin/cli-users | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/bin/cli-users b/bin/cli-users index cb87445c5..ea308ae44 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -8,6 +8,7 @@ const util = require('./util'); const program = require('commander'); const inquirer = require('inquirer'); const { graphql } = require('graphql'); +const helpers = require('../services/migration/helpers'); const { stripIndent } = require('common-tags'); const Table = require('cli-table'); @@ -32,6 +33,19 @@ const mongoose = require('../services/mongoose'); // Register the shutdown criteria. util.onshutdown([() => mongoose.disconnect()]); +/** + * transforms a specific action to a removal action on the target model. + */ +const actionDecrTransformer = ({ item_id, action_type, group_id }) => ({ + query: { id: item_id }, + update: { + $inc: { + [`action_counts.${action_type.toLowerCase()}`]: -1, + [`action_counts.${action_type.toLowerCase()}_${group_id.toLowerCase()}`]: -1, + }, + }, +}); + /** * Deletes a user and cleans up their associated verifications. */ @@ -62,9 +76,26 @@ async function deleteUser(userID) { return util.shutdown(); } + const { transformSingleWithCursor } = helpers({ + queryBatchSize: 10000, + updateBatchSize: 10000, + }); + console.warn("Removing user's actions"); - // FIXME: fix the counts. + // Remove all actions against comments. + await transformSingleWithCursor( + ActionModel.collection.find({ user_id: user.id, item_type: 'COMMENTS' }), + actionDecrTransformer, + CommentModel + ); + + // Remove all actions against users. + await transformSingleWithCursor( + ActionModel.collection.find({ user_id: user.id, item_type: 'USERS' }), + actionDecrTransformer, + UserModel + ); // Remove all the user's actions. await ActionModel.where({ user_id: user.id }) @@ -73,6 +104,29 @@ async function deleteUser(userID) { console.warn("Removing user's comments"); + // Removes all the user's reply counts on each of the comments that they + // have commented on. + await transformSingleWithCursor( + CommentModel.collection.aggregate([ + { $match: { author_id: user.id } }, + { + $group: { + _id: '$parent_id', + count: { $sum: 1 }, + }, + }, + ]), + ({ _id: parent_id, count }) => ({ + query: { id: parent_id }, + update: { + $inc: { + reply_count: -1 * count, + }, + }, + }), + CommentModel + ); + // Remove all the user's comments. await CommentModel.where({ author_id: user.id }) .setOptions({ multi: true }) From 985fc05a47f73521af3f89750c85e0d23f5996c9 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 29 Jan 2018 15:29:55 -0700 Subject: [PATCH 07/18] only users that have approved usernames may comment --- perms/reducers/mutation.js | 4 ++- test/server/graph/mutations/createComment.js | 38 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/perms/reducers/mutation.js b/perms/reducers/mutation.js index 3e73afbc9..73ee7ef28 100644 --- a/perms/reducers/mutation.js +++ b/perms/reducers/mutation.js @@ -15,7 +15,9 @@ module.exports = (user, perm) => { case types.EDIT_COMMENT: // Anyone can do these things if they aren't suspended, banned, or blocked // as they're editing their username. - return !['UNSET', 'REJECTED'].includes(user.status.username.status); + return !['UNSET', 'REJECTED', 'CHANGED'].includes( + user.status.username.status + ); case types.ADD_COMMENT_TAG: case types.REMOVE_COMMENT_TAG: diff --git a/test/server/graph/mutations/createComment.js b/test/server/graph/mutations/createComment.js index 720297e12..bd89b31a6 100644 --- a/test/server/graph/mutations/createComment.js +++ b/test/server/graph/mutations/createComment.js @@ -270,6 +270,44 @@ describe('graph.mutations.createComment', () => { }); }); + describe('user with different username statuses', () => { + beforeEach(() => AssetModel.create({ id: '123' })); + + [ + { status: 'UNSET', error: true }, + { status: 'SET', error: false }, + { status: 'APPROVED', error: false }, + { status: 'REJECTED', error: true }, + { status: 'CHANGED', error: true }, + ].forEach(({ status, error }) => { + describe(`user.status.username.status=${status}`, () => { + it(`${error ? 'can not' : 'can'} create a comment`, async () => { + const context = new Context({ + user: new UserModel({ status: { username: { status } } }), + }); + + const { data, errors } = await graphql(schema, query, {}, context); + + if (errors) { + console.error(errors); + } + expect(errors).to.be.undefined; + + if (error) { + expect(data.createComment).to.have.property('errors').not.null; + expect(data.createComment).to.have.property('comment').null; + } else { + if (data.createComment.errors) { + console.error(data.createComment.errors); + } + expect(data.createComment).to.have.property('errors').null; + expect(data.createComment).to.have.property('comment').not.null; + } + }); + }); + }); + }); + describe('users with different roles', () => { beforeEach(() => AssetModel.create({ id: '123' })); From d25ca0ef6f0689c51cf979dc7d4073dfe3a80f5c Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 29 Jan 2018 15:36:59 -0700 Subject: [PATCH 08/18] more test criteria --- test/server/graph/mutations/createComment.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/server/graph/mutations/createComment.js b/test/server/graph/mutations/createComment.js index bd89b31a6..058b19a41 100644 --- a/test/server/graph/mutations/createComment.js +++ b/test/server/graph/mutations/createComment.js @@ -296,6 +296,11 @@ describe('graph.mutations.createComment', () => { if (error) { expect(data.createComment).to.have.property('errors').not.null; expect(data.createComment).to.have.property('comment').null; + expect(data.createComment.errors).to.have.length(1); + expect(data.createComment.errors[0]).to.have.property( + 'translation_key', + 'NOT_AUTHORIZED' + ); } else { if (data.createComment.errors) { console.error(data.createComment.errors); From 335349963cb1c94f46395a51a56204fcb344a2d1 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 29 Jan 2018 17:35:09 -0700 Subject: [PATCH 09/18] adjusted flow for changed usernames, e2e --- .../tabs/stream/components/ChangedUsername.js | 17 ++++++ .../src/tabs/stream/components/Stream.js | 4 ++ locales/en.yml | 2 + test/e2e/specs/04_userStatus.js | 54 ++++++++++++++++--- 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 client/coral-embed-stream/src/tabs/stream/components/ChangedUsername.js diff --git a/client/coral-embed-stream/src/tabs/stream/components/ChangedUsername.js b/client/coral-embed-stream/src/tabs/stream/components/ChangedUsername.js new file mode 100644 index 000000000..3a0ba5790 --- /dev/null +++ b/client/coral-embed-stream/src/tabs/stream/components/ChangedUsername.js @@ -0,0 +1,17 @@ +import React, { Component } from 'react'; +import t from 'coral-framework/services/i18n'; +import RestrictedMessageBox from 'coral-framework/components/RestrictedMessageBox'; + +class ChangeUsername extends Component { + render() { + return ( + +
+ {t('framework.changed_name.msg')} +
+
+ ); + } +} + +export default ChangeUsername; diff --git a/client/coral-embed-stream/src/tabs/stream/components/Stream.js b/client/coral-embed-stream/src/tabs/stream/components/Stream.js index 6288a2b6b..65020cb08 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Stream.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Stream.js @@ -25,6 +25,7 @@ import AllCommentsPane from './AllCommentsPane'; import ExtendableTabPanel from '../../../containers/ExtendableTabPanel'; import styles from './Stream.css'; +import ChangedUsername from './ChangedUsername'; class Stream extends React.Component { constructor(props) { @@ -237,6 +238,7 @@ class Stream extends React.Component { const banned = get(user, 'status.banned.status'); const suspensionUntil = get(user, 'status.suspension.until'); const rejectedUsername = get(user, 'status.username.status') === 'REJECTED'; + const changedUsername = get(user, 'status.username.status') === 'CHANGED'; const temporarilySuspended = user && suspensionUntil && new Date(suspensionUntil) > new Date(); @@ -246,6 +248,7 @@ class Stream extends React.Component { ((!banned && !temporarilySuspended && !rejectedUsername && + !changedUsername && !highlightedComment) || keepCommentBox); const slotProps = { data }; @@ -285,6 +288,7 @@ class Stream extends React.Component { )} )} + {changedUsername && } {!banned && rejectedUsername && } {banned && } {showCommentBox && ( diff --git a/locales/en.yml b/locales/en.yml index efcd7a1d9..eb472b373 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -254,6 +254,8 @@ en: error: "Usernames can contain letters numbers and _ only" label: "New Username" msg: "Your account is currently suspended because your username has been deemed inappropriate. To restore your account please enter a new username. Please contact us if you have any questions." + changed_name: + msg: "Your username change is under review by our moderation team." my_comments: "My Comments" my_profile: "My profile" new_count: "View {0} more {1}" diff --git a/test/e2e/specs/04_userStatus.js b/test/e2e/specs/04_userStatus.js index b63b051bb..8d659221d 100644 --- a/test/e2e/specs/04_userStatus.js +++ b/test/e2e/specs/04_userStatus.js @@ -15,13 +15,13 @@ module.exports = { client.end(); }, - 'admin logs in': client => { + 'Admin logs in': client => { const adminPage = client.page.admin(); const { testData: { admin } } = client.globals; adminPage.navigateAndLogin(admin); }, - 'admin flags users username as offensive': client => { + 'Admin flags users username as offensive': client => { const embedStream = client.page.embedStream(); const comments = embedStream.navigate().ready(); @@ -42,7 +42,7 @@ module.exports = { .waitForElementVisible('@popUpText') .click('@continueButton'); }, - 'admin goes to Reported Usernames': client => { + 'Admin goes to Reported Usernames': client => { const adminPage = client.page.admin(); const community = adminPage @@ -54,14 +54,14 @@ module.exports = { .waitForElementVisible('@flaggedAccountsContainer') .waitForElementVisible('@flaggedUser'); }, - 'admin rejects the user flag': client => { + 'Admin rejects the user flag': client => { const community = client.page.admin().section.community; community .waitForElementVisible('@flaggedUserRejectButton') .click('@flaggedUserRejectButton'); }, - 'admin suspends the user': client => { + 'Admin suspends the user': client => { const community = client.page.admin().section.community; const usernameDialog = client.page.admin().section.usernameDialog; @@ -76,7 +76,7 @@ module.exports = { community.waitForElementNotPresent('@flaggedUser'); }, - 'admin logs out': client => { + 'Admin logs out': client => { client.page.admin().logout(); }, 'user logs in': client => { @@ -114,6 +114,48 @@ module.exports = { .click('@changeUsernameSubmitButton') .waitForElementNotPresent('@changeUsernameInput'); }, + 'user should not be able to comment still': client => { + const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; + + comments + .waitForElementNotPresent('@commentBoxTextarea') + .waitForElementNotPresent('@commentBoxPostButton'); + }, + 'user logs out': client => { + const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; + + comments.logout(); + }, + 'Admin accepts the user flag': client => { + const adminPage = client.page.admin(); + const { testData: { admin } } = client.globals; + + adminPage.navigateAndLogin(admin); + + const community = adminPage + .navigate() + .ready() + .goToCommunity(); + + community + .waitForElementVisible('@flaggedAccountsContainer') + .waitForElementVisible('@flaggedUser') + .waitForElementVisible('@flaggedUserApproveButton') + .click('@flaggedUserApproveButton'); + + client.page.admin().logout(); + }, + 'user logs in to check comment': client => { + const { testData: { user } } = client.globals; + const embedStream = client.page.embedStream(); + + embedStream + .navigate() + .ready() + .openLoginPopup(popup => popup.login(user)); + }, 'user should be able to comment': client => { const embedStream = client.page.embedStream(); const comments = embedStream.section.comments; From efe84f3f983fa8e99baa3434a6d84cccae60faa2 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 30 Jan 2018 14:50:35 +0100 Subject: [PATCH 10/18] Make Approve/Reject button styles more robust for long texts. For other languages than English the 'Approve' text did not fit into the button. This commit makes the CSS a bit more flexible by removing some very pixel-specfic styles. --- client/coral-admin/src/components/ApproveButton.css | 9 ++------- client/coral-admin/src/components/RejectButton.css | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/client/coral-admin/src/components/ApproveButton.css b/client/coral-admin/src/components/ApproveButton.css index 071be2fcb..db3ee63f6 100644 --- a/client/coral-admin/src/components/ApproveButton.css +++ b/client/coral-admin/src/components/ApproveButton.css @@ -5,16 +5,11 @@ background: white; padding: 10px 12px; box-sizing: border-box; - vertical-align: middle; - line-height: 24px; - font-size: 17px; - height: 47px; border-radius: 3px; text-transform: capitalize; box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.03), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.09); - width: 129px; - transform: scale(.8); - margin: 0; + width: 100%; + margin: 0 0 .5em; &:not(:disabled):hover { box-shadow: none; diff --git a/client/coral-admin/src/components/RejectButton.css b/client/coral-admin/src/components/RejectButton.css index 3885ebf9d..62a061fa4 100644 --- a/client/coral-admin/src/components/RejectButton.css +++ b/client/coral-admin/src/components/RejectButton.css @@ -5,16 +5,11 @@ background: white; padding: 10px 11px; box-sizing: border-box; - vertical-align: middle; - line-height: 24px; - font-size: 17px; - height: 47px; border-radius: 3px; text-transform: capitalize; box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.03), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.09); - width: 129px; - transform: scale(.8); - margin: 0; + width: 100%; + margin: 0 0 .5em; &:not(:disabled):hover { color: white; From ebb85d17ce992f6cd54a5762bfe1c07e72d89e98 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 15:13:14 +0100 Subject: [PATCH 11/18] Refactor --- .../src/tabs/stream/components/Comment.js | 14 +++++++++++++- .../src/tabs/stream/components}/ReplyButton.css | 0 .../src/tabs/stream/components}/ReplyButton.js | 1 + client/talk-plugin-replies/index.js | 1 - .../client/components/FakeComment.js | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) rename client/{talk-plugin-replies => coral-embed-stream/src/tabs/stream/components}/ReplyButton.css (100%) rename client/{talk-plugin-replies => coral-embed-stream/src/tabs/stream/components}/ReplyButton.js (96%) delete mode 100644 client/talk-plugin-replies/index.js diff --git a/client/coral-embed-stream/src/tabs/stream/components/Comment.js b/client/coral-embed-stream/src/tabs/stream/components/Comment.js index 68cba9bc9..34334567f 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Comment.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Comment.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import TagLabel from './TagLabel'; import CommentTimestamp from 'coral-framework/components/CommentTimestamp'; -import { ReplyButton } from 'talk-plugin-replies'; +import ReplyButton from './ReplyButton'; import ReplyBox from './ReplyBox'; import { FlagComment } from 'talk-plugin-flags'; import { can } from 'coral-framework/services/perms'; @@ -80,6 +80,11 @@ const ActionButton = ({ children }) => { ); }; +ActionButton.propTypes = { + // id of currently opened ReplyBox. tracked in Stream.js + children: PropTypes.node, +}; + // Determine whether the comment with id is in the part of the comments tree. function containsCommentId(props, id) { if (props.comment.id === id) { @@ -155,6 +160,7 @@ export default class Comment extends React.Component { static propTypes = { // id of currently opened ReplyBox. tracked in Stream.js + children: PropTypes.node, activeReplyBox: PropTypes.string.isRequired, disableReply: PropTypes.bool, setActiveReplyBox: PropTypes.func.isRequired, @@ -173,6 +179,12 @@ export default class Comment extends React.Component { }), charCountEnable: PropTypes.bool.isRequired, maxCharCount: PropTypes.number, + data: PropTypes.object, + root: PropTypes.object, + loadMore: PropTypes.func, + postDontAgree: PropTypes.func, + animateEnter: PropTypes.bool, + commentClassNames: PropTypes.array, comment: PropTypes.shape({ depth: PropTypes.number, action_summaries: PropTypes.array.isRequired, diff --git a/client/talk-plugin-replies/ReplyButton.css b/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.css similarity index 100% rename from client/talk-plugin-replies/ReplyButton.css rename to client/coral-embed-stream/src/tabs/stream/components/ReplyButton.css diff --git a/client/talk-plugin-replies/ReplyButton.js b/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js similarity index 96% rename from client/talk-plugin-replies/ReplyButton.js rename to client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js index 66433bdba..a19799a7c 100644 --- a/client/talk-plugin-replies/ReplyButton.js +++ b/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js @@ -6,6 +6,7 @@ import t from 'coral-framework/services/i18n'; import cn from 'classnames'; import styles from './ReplyButton.css'; +// @TODO: remove this. const name = 'talk-plugin-replies'; const ReplyButton = ({ onClick }) => { diff --git a/client/talk-plugin-replies/index.js b/client/talk-plugin-replies/index.js deleted file mode 100644 index f099e742b..000000000 --- a/client/talk-plugin-replies/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as ReplyButton } from './ReplyButton'; diff --git a/plugins/talk-plugin-auth/client/components/FakeComment.js b/plugins/talk-plugin-auth/client/components/FakeComment.js index d7367e838..82c61182b 100644 --- a/plugins/talk-plugin-auth/client/components/FakeComment.js +++ b/plugins/talk-plugin-auth/client/components/FakeComment.js @@ -1,6 +1,6 @@ import React from 'react'; import t from 'coral-framework/services/i18n'; -import { ReplyButton } from 'talk-plugin-replies'; +import ReplyButton from 'coral-embed-stream/src/tabs/stream/components/ReplyButton'; import styles from './FakeComment.css'; import { Icon } from 'plugin-api/beta/client/components/ui'; import { CommentTimestamp } from 'plugin-api/beta/client/components'; From d80cd6f0a2a11f95584f59a0929f7be9eba5872d Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 15:49:28 +0100 Subject: [PATCH 12/18] More Refactor --- .../src/routes/Community/components/FlaggedUser.js | 2 +- .../coral-embed-stream/src/tabs/stream/components/Comment.js | 2 +- .../src/tabs/stream/components/FlagButton.css} | 0 .../src/tabs/stream}/components/FlagButton.js | 5 +++-- .../src/tabs/stream}/components/FlagComment.js | 2 +- .../helpers => coral-framework/graphql}/flagReasons.js | 0 client/talk-plugin-flags/index.js | 1 - 7 files changed, 6 insertions(+), 6 deletions(-) rename client/{talk-plugin-flags/components/styles.css => coral-embed-stream/src/tabs/stream/components/FlagButton.css} (100%) rename client/{talk-plugin-flags => coral-embed-stream/src/tabs/stream}/components/FlagButton.js (98%) rename client/{talk-plugin-flags => coral-embed-stream/src/tabs/stream}/components/FlagComment.js (95%) rename client/{talk-plugin-flags/helpers => coral-framework/graphql}/flagReasons.js (100%) delete mode 100644 client/talk-plugin-flags/index.js diff --git a/client/coral-admin/src/routes/Community/components/FlaggedUser.js b/client/coral-admin/src/routes/Community/components/FlaggedUser.js index 00377e679..72a46e27e 100644 --- a/client/coral-admin/src/routes/Community/components/FlaggedUser.js +++ b/client/coral-admin/src/routes/Community/components/FlaggedUser.js @@ -3,7 +3,7 @@ import styles from './FlaggedUser.css'; import PropTypes from 'prop-types'; import cn from 'classnames'; import t from 'coral-framework/services/i18n'; -import { username } from 'talk-plugin-flags/helpers/flagReasons'; +import { username } from 'coral-framework/graphql/flagReasons'; import ApproveButton from 'coral-admin/src/components/ApproveButton'; import RejectButton from 'coral-admin/src/components/RejectButton'; import { isFlaggedUserDangling } from '../utils'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/Comment.js b/client/coral-embed-stream/src/tabs/stream/components/Comment.js index 34334567f..1b4beb14d 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/Comment.js +++ b/client/coral-embed-stream/src/tabs/stream/components/Comment.js @@ -5,7 +5,7 @@ import TagLabel from './TagLabel'; import CommentTimestamp from 'coral-framework/components/CommentTimestamp'; import ReplyButton from './ReplyButton'; import ReplyBox from './ReplyBox'; -import { FlagComment } from 'talk-plugin-flags'; +import FlagComment from './FlagComment'; import { can } from 'coral-framework/services/perms'; import { TransitionGroup } from 'react-transition-group'; import cn from 'classnames'; diff --git a/client/talk-plugin-flags/components/styles.css b/client/coral-embed-stream/src/tabs/stream/components/FlagButton.css similarity index 100% rename from client/talk-plugin-flags/components/styles.css rename to client/coral-embed-stream/src/tabs/stream/components/FlagButton.css diff --git a/client/talk-plugin-flags/components/FlagButton.js b/client/coral-embed-stream/src/tabs/stream/components/FlagButton.js similarity index 98% rename from client/talk-plugin-flags/components/FlagButton.js rename to client/coral-embed-stream/src/tabs/stream/components/FlagButton.js index b2048e105..6ab4a8d74 100644 --- a/client/talk-plugin-flags/components/FlagButton.js +++ b/client/coral-embed-stream/src/tabs/stream/components/FlagButton.js @@ -6,11 +6,12 @@ import { can } from 'coral-framework/services/perms'; import { PopupMenu, Button } from 'coral-ui'; import ClickOutside from 'coral-framework/components/ClickOutside'; import cn from 'classnames'; -import styles from './styles.css'; -import * as REASONS from '../helpers/flagReasons'; +import styles from './FlagButton.css'; +import * as REASONS from 'coral-framework/graphql/flagReasons'; import { getErrorMessages, forEachError } from 'coral-framework/utils'; +// TODO: remove this. const name = 'talk-plugin-flags'; export default class FlagButton extends Component { diff --git a/client/talk-plugin-flags/components/FlagComment.js b/client/coral-embed-stream/src/tabs/stream/components/FlagComment.js similarity index 95% rename from client/talk-plugin-flags/components/FlagComment.js rename to client/coral-embed-stream/src/tabs/stream/components/FlagComment.js index bd8607c6b..48379f7dd 100644 --- a/client/talk-plugin-flags/components/FlagComment.js +++ b/client/coral-embed-stream/src/tabs/stream/components/FlagComment.js @@ -2,7 +2,7 @@ import React from 'react'; import FlagButton from './FlagButton'; import t from 'coral-framework/services/i18n'; -import { username, comment } from '../helpers/flagReasons'; +import { username, comment } from 'coral-framework/graphql/flagReasons'; const FlagComment = props => ( diff --git a/client/talk-plugin-flags/helpers/flagReasons.js b/client/coral-framework/graphql/flagReasons.js similarity index 100% rename from client/talk-plugin-flags/helpers/flagReasons.js rename to client/coral-framework/graphql/flagReasons.js diff --git a/client/talk-plugin-flags/index.js b/client/talk-plugin-flags/index.js deleted file mode 100644 index 8385ce482..000000000 --- a/client/talk-plugin-flags/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as FlagComment } from './components/FlagComment'; From b33cde03c321fabd0dceeaef5d102c37dccc8d28 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 15:59:02 +0100 Subject: [PATCH 13/18] Removes some weird characters --- client/coral-admin/src/constants/install.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/constants/install.js b/client/coral-admin/src/constants/install.js index fb2cc4bef..034453ecc 100644 --- a/client/coral-admin/src/constants/install.js +++ b/client/coral-admin/src/constants/install.js @@ -2,8 +2,8 @@ export const NEXT_STEP = 'NEXT_STEP'; export const GO_TO_STEP = 'GO_TO_STEP'; export const PREVIOUS_STEP = 'PREVIOUS_STEP'; export const ADD_ERROR = 'ADD_ERROR'; -export const HAS_ERROR = 'HAS_ERROR'; -export const SHOW_ERRORS = 'SHOW_ERRORS'; +export const HAS_ERROR = 'HAS_ERROR'; +export const SHOW_ERRORS = 'SHOW_ERRORS'; export const CLEAR_ERRORS = 'CLEAR_ERRORS'; export const INSTALL_REQUEST = 'INSTALL_REQUEST'; export const INSTALL_SUCCESS = 'INSTALL_SUCCESS'; From cb5a41f11925949bee3bbaf6d40de7a51077ce45 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 17:18:09 +0100 Subject: [PATCH 14/18] Refactor --- .../src/actions/commentBox.js | 13 --------- .../coral-embed-stream/src/actions/stream.js | 14 ++++++++++ .../src/constants/commentBox.js | 5 ---- .../src/constants/stream.js | 5 ++++ .../coral-embed-stream/src/graphql/index.js | 3 --- .../src/reducers/commentBox.js | 27 ------------------- .../coral-embed-stream/src/reducers/index.js | 2 -- .../coral-embed-stream/src/reducers/stream.js | 19 +++++++++++++ .../src/tabs/stream/containers/CommentBox.js | 8 +++--- plugin-api/alpha/client/actions/index.js | 3 ++- plugin-api/alpha/client/selectors/index.js | 2 +- 11 files changed, 46 insertions(+), 55 deletions(-) delete mode 100644 client/coral-embed-stream/src/actions/commentBox.js delete mode 100644 client/coral-embed-stream/src/constants/commentBox.js delete mode 100644 client/coral-embed-stream/src/reducers/commentBox.js diff --git a/client/coral-embed-stream/src/actions/commentBox.js b/client/coral-embed-stream/src/actions/commentBox.js deleted file mode 100644 index 7a6aa3249..000000000 --- a/client/coral-embed-stream/src/actions/commentBox.js +++ /dev/null @@ -1,13 +0,0 @@ -export const addTag = tag => ({ - type: 'ADD_TAG', - tag, -}); - -export const removeTag = idx => ({ - type: 'REMOVE_TAG', - idx, -}); - -export const clearTags = () => ({ - type: 'CLEAR_TAGS', -}); diff --git a/client/coral-embed-stream/src/actions/stream.js b/client/coral-embed-stream/src/actions/stream.js index 8af2dfef2..bc31c90e9 100644 --- a/client/coral-embed-stream/src/actions/stream.js +++ b/client/coral-embed-stream/src/actions/stream.js @@ -70,3 +70,17 @@ export const removeCommentClassName = idx => ({ export const setActiveTab = tab => dispatch => { dispatch({ type: actions.SET_ACTIVE_TAB, tab }); }; + +export const addCommentBoxTag = tag => ({ + type: actions.ADD_COMMENT_BOX_TAG, + tag, +}); + +export const removeCommentBoxTag = idx => ({ + type: actions.REMOVE_COMMENT_BOX_TAG, + idx, +}); + +export const clearCommentBoxTags = () => ({ + type: actions.CLEAR_COMMENT_BOX_TAGS, +}); diff --git a/client/coral-embed-stream/src/constants/commentBox.js b/client/coral-embed-stream/src/constants/commentBox.js deleted file mode 100644 index 51130d6c0..000000000 --- a/client/coral-embed-stream/src/constants/commentBox.js +++ /dev/null @@ -1,5 +0,0 @@ -const prefix = 'TALK_EMBED_STREAM_COMMENT_BOX'; - -export const ADD_TAG = `${prefix}_ADD_TAG`; -export const REMOVE_TAG = `${prefix}_REMOVE_TAG`; -export const CLEAR_TAGS = `${prefix}_CLEAR_TAGS`; diff --git a/client/coral-embed-stream/src/constants/stream.js b/client/coral-embed-stream/src/constants/stream.js index b4deb24e1..09d069851 100644 --- a/client/coral-embed-stream/src/constants/stream.js +++ b/client/coral-embed-stream/src/constants/stream.js @@ -1,3 +1,5 @@ +const prefix = 'TALK_EMBED_STREAM'; + export const SET_ACTIVE_REPLY_BOX = 'SET_ACTIVE_REPLY_BOX'; export const ADDTL_COMMENTS_ON_LOAD_MORE = 10; export const VIEW_ALL_COMMENTS = 'VIEW_ALL_COMMENTS'; @@ -7,3 +9,6 @@ export const REMOVE_COMMENT_CLASSNAME = 'REMOVE_COMMENT_CLASSNAME'; export const THREADING_LEVEL = process.env.TALK_THREADING_LEVEL; export const SET_ACTIVE_TAB = 'CORAL_STREAM_SET_ACTIVE_TAB'; export const SET_SORT = 'CORAL_STREAM_SET_SORT'; +export const ADD_COMMENT_BOX_TAG = `${prefix}_COMMENT_BOX_ADD_TAG`; +export const REMOVE_COMMENT_BOX_TAG = `${prefix}_COMMENT_BOX_REMOVE_TAG`; +export const CLEAR_COMMENT_BOX_TAGS = `${prefix}_COMMENT_BOX_CLEAR_TAGS`; diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js index dcded6b45..db4f92671 100644 --- a/client/coral-embed-stream/src/graphql/index.js +++ b/client/coral-embed-stream/src/graphql/index.js @@ -93,9 +93,6 @@ export default { name created_at } - assigned_by { - id - } } user { id diff --git a/client/coral-embed-stream/src/reducers/commentBox.js b/client/coral-embed-stream/src/reducers/commentBox.js deleted file mode 100644 index 9621f1447..000000000 --- a/client/coral-embed-stream/src/reducers/commentBox.js +++ /dev/null @@ -1,27 +0,0 @@ -import { ADD_TAG, REMOVE_TAG, CLEAR_TAGS } from '../constants/commentBox'; - -const initialState = { - tags: [], -}; - -export default function commentBox(state = initialState, action) { - switch (action.type) { - case ADD_TAG: - return { - ...state, - tags: [...state.tags, action.tag], - }; - case REMOVE_TAG: - return { - ...state, - tags: [ - ...state.tags.slice(0, action.idx), - ...state.tags.slice(action.idx + 1), - ], - }; - case CLEAR_TAGS: - return initialState; - default: - return state; - } -} diff --git a/client/coral-embed-stream/src/reducers/index.js b/client/coral-embed-stream/src/reducers/index.js index 0152c837d..ac581557b 100644 --- a/client/coral-embed-stream/src/reducers/index.js +++ b/client/coral-embed-stream/src/reducers/index.js @@ -4,12 +4,10 @@ import embed from './embed'; import config from './config'; import configure from './configure'; import stream from './stream'; -import commentBox from './commentBox'; export default { auth, asset, - commentBox, embed, config, configure, diff --git a/client/coral-embed-stream/src/reducers/stream.js b/client/coral-embed-stream/src/reducers/stream.js index b5afddafc..42af4453a 100644 --- a/client/coral-embed-stream/src/reducers/stream.js +++ b/client/coral-embed-stream/src/reducers/stream.js @@ -25,6 +25,7 @@ const initialState = { previousTab: '', sortBy: 'CREATED_AT', sortOrder: 'DESC', + commentBoxTags: [], }; export default function stream(state = initialState, action) { @@ -74,6 +75,24 @@ export default function stream(state = initialState, action) { sortOrder: action.sortOrder ? action.sortOrder : state.sortOrder, sortBy: action.sortBy ? action.sortBy : state.sortBy, }; + case actions.ADD_COMMENT_BOX_TAG: + return { + ...state, + commentBoxTags: [...state.commentBoxTags, action.tag], + }; + case actions.REMOVE_COMMENT_BOX_TAG: + return { + ...state, + commentBoxTags: [ + ...state.commentBoxTags.slice(0, action.idx), + ...state.commentBoxTags.slice(action.idx + 1), + ], + }; + case actions.CLEAR_COMMENT_BOX_TAGS: + return { + ...state, + commentBoxTags: [], + }; default: return state; } diff --git a/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js index 9c04801c6..b280ce741 100644 --- a/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js +++ b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js @@ -71,7 +71,7 @@ class CommentBox extends React.Component { asset_id: assetId, parent_id: parentId, body: this.state.body, - ...this.props.commentBox, + tags: this.props.tags, }; // Execute preSubmit Hooks @@ -203,9 +203,11 @@ CommentBox.propTypes = { isReply: PropTypes.bool.isRequired, canPost: PropTypes.bool, notify: PropTypes.func.isRequired, - commentBox: PropTypes.object, + tags: PropTypes.array, }; -const mapStateToProps = ({ commentBox }) => ({ commentBox }); +const mapStateToProps = state => ({ + tags: state.stream.commentBoxTags, +}); export default connect(mapStateToProps, null)(CommentBox); diff --git a/plugin-api/alpha/client/actions/index.js b/plugin-api/alpha/client/actions/index.js index 9de7b5de3..9ef89f11b 100644 --- a/plugin-api/alpha/client/actions/index.js +++ b/plugin-api/alpha/client/actions/index.js @@ -1,5 +1,6 @@ -export { addTag, removeTag } from 'coral-embed-stream/src/actions/commentBox'; export { addCommentClassName, removeCommentClassName, + addCommentBoxTag as addTag, + removeCommentBoxTag as removeTag, } from 'coral-embed-stream/src/actions/stream'; diff --git a/plugin-api/alpha/client/selectors/index.js b/plugin-api/alpha/client/selectors/index.js index 988155308..214a07d0c 100644 --- a/plugin-api/alpha/client/selectors/index.js +++ b/plugin-api/alpha/client/selectors/index.js @@ -1,3 +1,3 @@ -export const commentBoxTagsSelector = state => state.commentBox.tags; +export const commentBoxTagsSelector = state => state.stream.commentBoxTags; export const commentClassNamesSelector = state => state.stream.commentClassNames; From 81e68c8ef4dea60e143ba4438fc0a6bac0998053 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 17:34:18 +0100 Subject: [PATCH 15/18] Fix edited comment not showing notifications --- .../components/EditableCommentContent.js | 9 +++++-- .../src/tabs/stream/containers/CommentBox.js | 25 ++----------------- .../src/tabs/stream/helpers.js | 23 +++++++++++++++++ 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 client/coral-embed-stream/src/tabs/stream/helpers.js diff --git a/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js b/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js index 7d3ae6600..877ca7aea 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js +++ b/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; // TODO: move this function. -import { notifyForNewCommentStatus } from '../containers/CommentBox'; +import { notifyForNewCommentStatus } from '../helpers'; import { CommentForm } from './CommentForm'; import styles from './Comment.css'; import { CountdownSeconds } from './CountdownSeconds'; @@ -45,6 +45,8 @@ export class EditableCommentContent extends React.Component { stopEditing: PropTypes.func, }; + unmounted = false; + constructor(props) { super(props); this.editWindowExpiryTimeout = null; @@ -64,6 +66,7 @@ export class EditableCommentContent extends React.Component { } } componentWillUnmount() { + this.unmounted = true; if (this.editWindowExpiryTimeout) { this.editWindowExpiryTimeout = clearTimeout(this.editWindowExpiryTimeout); } @@ -88,7 +91,9 @@ export class EditableCommentContent extends React.Component { let response; try { response = await editComment({ body: this.state.body }); - this.setState({ loadingState: 'success' }); + if (!this.unmounted) { + this.setState({ loadingState: 'success' }); + } const status = response.data.editComment.comment.status; notifyForNewCommentStatus(this.props.notify, status); if (typeof stopEditing === 'function') { diff --git a/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js index b280ce741..745b651e9 100644 --- a/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js +++ b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js @@ -7,32 +7,11 @@ import { can } from 'coral-framework/services/perms'; import Slot from 'coral-framework/components/Slot'; import { connect } from 'react-redux'; import { CommentForm } from '../components/CommentForm'; +import { notifyForNewCommentStatus } from '../helpers'; // TODO: change this... export const name = 'talk-plugin-commentbox'; -const notifyReasons = ['LINKS', 'TRUST']; - -function shouldNotify(actions = []) { - return actions.some( - ({ __typename, reason }) => - __typename === 'FlagAction' && notifyReasons.includes(reason) - ); -} - -// Given a newly posted comment's status, show a notification to the user -// if needed -export const notifyForNewCommentStatus = (notify, comment, actions) => { - if (comment.status === 'REJECTED') { - notify('error', t('comment_box.comment_post_banned_word')); - } else if ( - comment.status === 'PREMOD' || - (comment.status === 'SYSTEM_WITHHELD' && shouldNotify(actions)) - ) { - notify('success', t('comment_box.comment_post_notif_premod')); - } -}; - /** * Container for posting a new Comment */ @@ -87,7 +66,7 @@ class CommentBox extends React.Component { // Execute postSubmit Hooks this.state.hooks.postSubmit.forEach(hook => hook(data)); - notifyForNewCommentStatus(notify, postedComment, actions); + notifyForNewCommentStatus(notify, postedComment.status, actions); if (commentPostedHandler) { commentPostedHandler(); diff --git a/client/coral-embed-stream/src/tabs/stream/helpers.js b/client/coral-embed-stream/src/tabs/stream/helpers.js new file mode 100644 index 000000000..f44f777e4 --- /dev/null +++ b/client/coral-embed-stream/src/tabs/stream/helpers.js @@ -0,0 +1,23 @@ +import t from 'coral-framework/services/i18n'; + +const notifyReasons = ['LINKS', 'TRUST']; + +function shouldNotify(actions = []) { + return actions.some( + ({ __typename, reason }) => + __typename === 'FlagAction' && notifyReasons.includes(reason) + ); +} + +// Given a newly posted or edited comment's status, show a notification to the user +// if needed +export const notifyForNewCommentStatus = (notify, status, actions) => { + if (status === 'REJECTED') { + notify('error', t('comment_box.comment_post_banned_word')); + } else if ( + status === 'PREMOD' || + (status === 'SYSTEM_WITHHELD' && shouldNotify(actions)) + ) { + notify('success', t('comment_box.comment_post_notif_premod')); + } +}; From 665d8c1ef0017ee69ec057f437604da6eabbad6d Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 17:42:30 +0100 Subject: [PATCH 16/18] Fix gender translation --- locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/en.yml b/locales/en.yml index 8a9ce4bcb..8f858ee24 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -65,7 +65,7 @@ en: notify_approved: '{0} approved username {1}' notify_rejected: '{0} rejected username {1}' notify_flagged: '{0} reported username {1}' - notify_changed: 'user {0} changed his username to {1}' + notify_changed: 'user {0} changed their username to {1}' community: account_creation_date: "Account Creation Date" active: Active From 3d57122a65e7b96007a9ba112635ab04a37f3fc9 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 17:56:15 +0100 Subject: [PATCH 17/18] Add IE CSS fixes --- client/coral-admin/src/components/UserDetailComment.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/coral-admin/src/components/UserDetailComment.css b/client/coral-admin/src/components/UserDetailComment.css index 50e37e28e..75b968625 100644 --- a/client/coral-admin/src/components/UserDetailComment.css +++ b/client/coral-admin/src/components/UserDetailComment.css @@ -81,6 +81,8 @@ } .sideActions { + /* IE 11 needs this... */ + width: 105px; } .editedMarker { From feeaa8ee8baaa2cd7ddd90b19b354918a803b415 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 30 Jan 2018 18:19:31 +0100 Subject: [PATCH 18/18] Better todo descr --- .../src/tabs/stream/components/CommentForm.js | 2 +- .../src/tabs/stream/components/EditableCommentContent.js | 1 - .../coral-embed-stream/src/tabs/stream/components/FlagButton.js | 2 +- client/coral-embed-stream/src/tabs/stream/components/InfoBox.js | 2 +- .../coral-embed-stream/src/tabs/stream/components/ReplyBox.js | 2 +- .../src/tabs/stream/components/ReplyButton.js | 2 +- .../coral-embed-stream/src/tabs/stream/components/TagLabel.js | 2 +- .../coral-embed-stream/src/tabs/stream/containers/CommentBox.js | 2 +- 8 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/coral-embed-stream/src/tabs/stream/components/CommentForm.js b/client/coral-embed-stream/src/tabs/stream/components/CommentForm.js index ac9abc446..9a84bdbe8 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/CommentForm.js +++ b/client/coral-embed-stream/src/tabs/stream/components/CommentForm.js @@ -4,7 +4,7 @@ import { Button } from 'coral-ui'; import cn from 'classnames'; import Slot from 'coral-framework/components/Slot'; -// TODO: need to change this. +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. import { name } from '../containers/CommentBox'; import styles from './CommentForm.css'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js b/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js index 877ca7aea..ac50df9af 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js +++ b/client/coral-embed-stream/src/tabs/stream/components/EditableCommentContent.js @@ -1,7 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -// TODO: move this function. import { notifyForNewCommentStatus } from '../helpers'; import { CommentForm } from './CommentForm'; import styles from './Comment.css'; diff --git a/client/coral-embed-stream/src/tabs/stream/components/FlagButton.js b/client/coral-embed-stream/src/tabs/stream/components/FlagButton.js index 6ab4a8d74..bc673ba28 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/FlagButton.js +++ b/client/coral-embed-stream/src/tabs/stream/components/FlagButton.js @@ -11,7 +11,7 @@ import * as REASONS from 'coral-framework/graphql/flagReasons'; import { getErrorMessages, forEachError } from 'coral-framework/utils'; -// TODO: remove this. +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. const name = 'talk-plugin-flags'; export default class FlagButton extends Component { diff --git a/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js b/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js index 5e76c9911..7b811b63c 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js +++ b/client/coral-embed-stream/src/tabs/stream/components/InfoBox.js @@ -1,7 +1,7 @@ import React from 'react'; import Markdown from 'coral-framework/components/Markdown'; -// TODO: remove this. +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. const packagename = 'talk-plugin-infobox'; const InfoBox = ({ enable, content }) => ( diff --git a/client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js b/client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js index 03b56d990..6c93cb7fe 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js +++ b/client/coral-embed-stream/src/tabs/stream/components/ReplyBox.js @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import CommentBox from '../containers/CommentBox'; -// TODO: remove this.. +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. const name = 'talk-plugin-replies'; class ReplyBox extends Component { diff --git a/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js b/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js index a19799a7c..812811741 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js +++ b/client/coral-embed-stream/src/tabs/stream/components/ReplyButton.js @@ -6,7 +6,7 @@ import t from 'coral-framework/services/i18n'; import cn from 'classnames'; import styles from './ReplyButton.css'; -// @TODO: remove this. +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. const name = 'talk-plugin-replies'; const ReplyButton = ({ onClick }) => { diff --git a/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js b/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js index bbb324c22..2b2bee48a 100644 --- a/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js +++ b/client/coral-embed-stream/src/tabs/stream/components/TagLabel.js @@ -1,6 +1,6 @@ import React from 'react'; -// TODO: change className. +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. const TagLabel = ({ children }) => (
{children}
diff --git a/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js index 745b651e9..a9f9123c5 100644 --- a/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js +++ b/client/coral-embed-stream/src/tabs/stream/containers/CommentBox.js @@ -9,7 +9,7 @@ import { connect } from 'react-redux'; import { CommentForm } from '../components/CommentForm'; import { notifyForNewCommentStatus } from '../helpers'; -// TODO: change this... +// TODO: (kiwi) Need to adapt CSS classes post refactor to match the rest. export const name = 'talk-plugin-commentbox'; /**