From 8a9af896992c12ee9b955c08c05806bf84011f0e Mon Sep 17 00:00:00 2001 From: okbel Date: Thu, 3 May 2018 15:12:23 -0300 Subject: [PATCH 01/13] withUpdateEmailAddress in the plugins hoc --- client/coral-framework/graphql/mutations.js | 44 ----------------- .../client/containers/Profile.js | 6 +-- .../client/hocs/index.js | 47 +++++++++++++++++++ 3 files changed, 49 insertions(+), 48 deletions(-) create mode 100644 plugins/talk-plugin-local-auth/client/hocs/index.js diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index 29ec3fc96..228911d4a 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -321,50 +321,6 @@ const SetUsernameFragment = gql` } `; -export const withUpdateEmailAddress = withMutation( - gql` - mutation UpdateEmailAddress($input: UpdateEmailAddressInput!) { - updateEmailAddress(input: $input) { - ...UpdateEmailAddressResponse - } - } - `, - { - props: ({ mutate }) => ({ - updateEmailAddress: input => { - return mutate({ - variables: { - input, - }, - update: proxy => { - const UpdateEmailAddressQuery = gql` - query Talk_UpdateEmailAddress { - me { - id - email - } - } - `; - - const prev = proxy.readQuery({ query: UpdateEmailAddressQuery }); - - const data = update(prev, { - me: { - email: { $set: input.email }, - }, - }); - - proxy.writeQuery({ - query: UpdateEmailAddressQuery, - data, - }); - }, - }); - }, - }), - } -); - export const withChangeUsername = withMutation( gql` mutation ChangeUsername($id: ID!, $username: String!) { diff --git a/plugins/talk-plugin-local-auth/client/containers/Profile.js b/plugins/talk-plugin-local-auth/client/containers/Profile.js index 239304535..8f442ea43 100644 --- a/plugins/talk-plugin-local-auth/client/containers/Profile.js +++ b/plugins/talk-plugin-local-auth/client/containers/Profile.js @@ -3,10 +3,8 @@ import { bindActionCreators } from 'redux'; import { connect, withFragments } from 'plugin-api/beta/client/hocs'; import Profile from '../components/Profile'; import { notify } from 'coral-framework/actions/notification'; -import { - withChangeUsername, - withUpdateEmailAddress, -} from 'plugin-api/beta/client/hocs'; +import { withChangeUsername } from 'plugin-api/beta/client/hocs'; +import { withUpdateEmailAddress } from './hocs'; const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch); diff --git a/plugins/talk-plugin-local-auth/client/hocs/index.js b/plugins/talk-plugin-local-auth/client/hocs/index.js new file mode 100644 index 000000000..bcd439af2 --- /dev/null +++ b/plugins/talk-plugin-local-auth/client/hocs/index.js @@ -0,0 +1,47 @@ +import { gql } from 'react-apollo'; +import update from 'immutability-helper'; +import withMutation from 'coral-framework/hocs/withMutation'; + +export const withUpdateEmailAddress = withMutation( + gql` + mutation UpdateEmailAddress($input: UpdateEmailAddressInput!) { + updateEmailAddress(input: $input) { + ...UpdateEmailAddressResponse + } + } + `, + { + props: ({ mutate }) => ({ + updateEmailAddress: input => { + return mutate({ + variables: { + input, + }, + update: proxy => { + const UpdateEmailAddressQuery = gql` + query Talk_UpdateEmailAddress { + me { + id + email + } + } + `; + + const prev = proxy.readQuery({ query: UpdateEmailAddressQuery }); + + const data = update(prev, { + me: { + email: { $set: input.email }, + }, + }); + + proxy.writeQuery({ + query: UpdateEmailAddressQuery, + data, + }); + }, + }); + }, + }), + } +); From 687d0555c87996b7f6ff6f28639d0b37df8aecf1 Mon Sep 17 00:00:00 2001 From: okbel Date: Thu, 3 May 2018 15:18:09 -0300 Subject: [PATCH 02/13] moving mutations to /hocs folder --- .../client/containers/DownloadCommentHistory.js | 2 +- .../client/{mutations.js => hocs/index.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename plugins/talk-plugin-profile-data/client/{mutations.js => hocs/index.js} (100%) diff --git a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js index 96dbf6975..df9843d4a 100644 --- a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js +++ b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { compose, gql } from 'react-apollo'; import DownloadCommentHistory from '../components/DownloadCommentHistory'; import { withFragments } from 'plugin-api/beta/client/hocs'; -import { withRequestDownloadLink } from '../mutations'; +import { withRequestDownloadLink } from '../hocs'; class DownloadCommentHistoryContainer extends Component { static propTypes = { diff --git a/plugins/talk-plugin-profile-data/client/mutations.js b/plugins/talk-plugin-profile-data/client/hocs/index.js similarity index 100% rename from plugins/talk-plugin-profile-data/client/mutations.js rename to plugins/talk-plugin-profile-data/client/hocs/index.js From 788cf25fa50acb9fa7888260b228c6aae77ba858 Mon Sep 17 00:00:00 2001 From: okbel Date: Thu, 3 May 2018 15:20:07 -0300 Subject: [PATCH 03/13] moving mutations to /hocs folder --- plugins/talk-plugin-local-auth/client/containers/Profile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/talk-plugin-local-auth/client/containers/Profile.js b/plugins/talk-plugin-local-auth/client/containers/Profile.js index 8f442ea43..e1ed99ef6 100644 --- a/plugins/talk-plugin-local-auth/client/containers/Profile.js +++ b/plugins/talk-plugin-local-auth/client/containers/Profile.js @@ -4,7 +4,7 @@ import { connect, withFragments } from 'plugin-api/beta/client/hocs'; import Profile from '../components/Profile'; import { notify } from 'coral-framework/actions/notification'; import { withChangeUsername } from 'plugin-api/beta/client/hocs'; -import { withUpdateEmailAddress } from './hocs'; +import { withUpdateEmailAddress } from '../hocs'; const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch); From 29a840fe067d774fcf1928017c5f80c0df5b433a Mon Sep 17 00:00:00 2001 From: okbel Date: Thu, 3 May 2018 15:38:17 -0300 Subject: [PATCH 04/13] InputField conflict --- .../client/components/ChangePassword.css | 2 +- .../client/components/InputField.css | 6 +- .../client/components/InputField.js | 60 ++++++++++--------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/plugins/talk-plugin-local-auth/client/components/ChangePassword.css b/plugins/talk-plugin-local-auth/client/components/ChangePassword.css index 6c7f9ae41..af59ae65f 100644 --- a/plugins/talk-plugin-local-auth/client/components/ChangePassword.css +++ b/plugins/talk-plugin-local-auth/client/components/ChangePassword.css @@ -31,7 +31,7 @@ display: block; padding-top: 4px; text-align: right; - width: 280px; + width: 230px; } .detailLink { diff --git a/plugins/talk-plugin-local-auth/client/components/InputField.css b/plugins/talk-plugin-local-auth/client/components/InputField.css index cd6015e47..d0dc51494 100644 --- a/plugins/talk-plugin-local-auth/client/components/InputField.css +++ b/plugins/talk-plugin-local-auth/client/components/InputField.css @@ -5,6 +5,7 @@ .detailItemContainer { display: flex; + flex-direction: column; } .columnDisplay { @@ -16,6 +17,10 @@ } .detailItemContent { + display: flex; +} + +.detailInput { border: solid 1px #787D80; border-radius: 2px; background-color: white; @@ -64,7 +69,6 @@ display: flex; align-items: center; padding-left: 6px; - padding-top: 16px; .warningIcon, .checkIcon { font-size: 17px; diff --git a/plugins/talk-plugin-local-auth/client/components/InputField.js b/plugins/talk-plugin-local-auth/client/components/InputField.js index 34c314c20..944f5e7cf 100644 --- a/plugins/talk-plugin-local-auth/client/components/InputField.js +++ b/plugins/talk-plugin-local-auth/client/components/InputField.js @@ -30,41 +30,45 @@ const InputField = ({ return (
-
+
{label && ( )}
- {icon && } - -
-
- {!hasError && - showSuccess && - value && } - {hasError && showError && {errorMsg}} +
+ {icon && } + +
+
+ {!hasError && + showSuccess && + value && ( + + )} + {hasError && showError && {errorMsg}} +
{children} From 58b73a4d0a7d15734b9b88306c75150a421a8771 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Thu, 3 May 2018 17:08:20 -0400 Subject: [PATCH 05/13] Add feature overview to GDPR docs --- docs/source/03-08-gdpr.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/source/03-08-gdpr.md b/docs/source/03-08-gdpr.md index 187920bbc..76fe23211 100644 --- a/docs/source/03-08-gdpr.md +++ b/docs/source/03-08-gdpr.md @@ -12,9 +12,19 @@ can enable the following plugins: - [talk-plugin-profile-data](/talk/plugin/talk-plugin-profile-data) - to facilitate account download and deletion Even if you don't reside in a location where GDPR will apply, it is recommended -to enable these features anyways to provide your users with control over their +to enable these features as a best practice to provide your users with control over their own data. +## GPDR Feature Overview + +Integrating our GDPR tools will give your users and organization the following benefits: + +- **Download my comment data**: Users can request a download of their comments. An email with a link is emailed to them to download a CSV with each comment they've made, what story it was made on, and the comment's ID and timestamp. +- **Delete my acccount**: Users can request deletion of their account. Deleted account requests are pending for 24 hours to allow the user to download their comments, or to change their mind and reactivate their account before the expiry. Account deletions remove all of their comments from the site, all their comments and actions from the database, and their account info from our system. +- **Add an email to an Oauth/external account**: Users are prompted to add an email to their non-Talk account (Facebook, Google, external, etc) so that they can take part in GDPR and other features requiring email communication. +** Change my username: Users can update their username. This is capped at once every 2 weeks. +** Change my email: Users can change their email. + ## Custom Authentication Solutions As many of the newsrooms who have integrated Talk have followed our guides on From bc3ceac61a405c25c5776b97c34a613641015eba Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 15:26:50 -0600 Subject: [PATCH 06/13] docs patch --- docs/source/03-08-gdpr.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/03-08-gdpr.md b/docs/source/03-08-gdpr.md index 76fe23211..868897955 100644 --- a/docs/source/03-08-gdpr.md +++ b/docs/source/03-08-gdpr.md @@ -22,8 +22,8 @@ Integrating our GDPR tools will give your users and organization the following b - **Download my comment data**: Users can request a download of their comments. An email with a link is emailed to them to download a CSV with each comment they've made, what story it was made on, and the comment's ID and timestamp. - **Delete my acccount**: Users can request deletion of their account. Deleted account requests are pending for 24 hours to allow the user to download their comments, or to change their mind and reactivate their account before the expiry. Account deletions remove all of their comments from the site, all their comments and actions from the database, and their account info from our system. - **Add an email to an Oauth/external account**: Users are prompted to add an email to their non-Talk account (Facebook, Google, external, etc) so that they can take part in GDPR and other features requiring email communication. -** Change my username: Users can update their username. This is capped at once every 2 weeks. -** Change my email: Users can change their email. +- **Change my username**: Users can update their username. This is capped at once every 2 weeks. +- **Change my email**: Users can change their email. ## Custom Authentication Solutions From aee963ce39e788f9be6157ebe22dae42ab9c06db Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Thu, 3 May 2018 17:34:41 -0400 Subject: [PATCH 07/13] Missed an s --- docs/source/03-08-gdpr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/03-08-gdpr.md b/docs/source/03-08-gdpr.md index 868897955..9b1050454 100644 --- a/docs/source/03-08-gdpr.md +++ b/docs/source/03-08-gdpr.md @@ -17,7 +17,7 @@ own data. ## GPDR Feature Overview -Integrating our GDPR tools will give your users and organization the following benefits: +Integrating our GDPR tools will give your users and organizations the following benefits: - **Download my comment data**: Users can request a download of their comments. An email with a link is emailed to them to download a CSV with each comment they've made, what story it was made on, and the comment's ID and timestamp. - **Delete my acccount**: Users can request deletion of their account. Deleted account requests are pending for 24 hours to allow the user to download their comments, or to change their mind and reactivate their account before the expiry. Account deletions remove all of their comments from the site, all their comments and actions from the database, and their account info from our system. From 35cefd55706c19ca15165c46e1768c9bc7e8aa97 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Thu, 3 May 2018 17:42:47 -0400 Subject: [PATCH 08/13] Fix build fail --- .../client/containers/DownloadCommentHistory.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js index a610e834b..7a22ef37f 100644 --- a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js +++ b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import { bindActionCreators } from 'redux'; import { compose, gql } from 'react-apollo'; import DownloadCommentHistory from '../components/DownloadCommentHistory'; -import { withFragments } from 'plugin-api/beta/client/hocs'; import { withRequestDownloadLink } from '../hocs'; import { connect, withFragments } from 'plugin-api/beta/client/hocs'; import { withRequestDownloadLink } from '../hocs'; From b5958d5879153274faa7d48250432f4e7f524686 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 15:45:43 -0600 Subject: [PATCH 09/13] fixed merge error --- .../containers/DownloadCommentHistory.js | 1 - .../client/hocs/index.js | 92 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js index 7a22ef37f..1716de983 100644 --- a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js +++ b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js @@ -5,7 +5,6 @@ import { compose, gql } from 'react-apollo'; import DownloadCommentHistory from '../components/DownloadCommentHistory'; import { withRequestDownloadLink } from '../hocs'; import { connect, withFragments } from 'plugin-api/beta/client/hocs'; -import { withRequestDownloadLink } from '../hocs'; import { notify } from 'coral-framework/actions/notification'; class DownloadCommentHistoryContainer extends Component { diff --git a/plugins/talk-plugin-profile-data/client/hocs/index.js b/plugins/talk-plugin-profile-data/client/hocs/index.js index a370c9ff0..c90ad21df 100644 --- a/plugins/talk-plugin-profile-data/client/hocs/index.js +++ b/plugins/talk-plugin-profile-data/client/hocs/index.js @@ -1,5 +1,7 @@ import { withMutation } from 'plugin-api/beta/client/hocs'; import { gql } from 'react-apollo'; +import moment from 'moment'; +import update from 'immutability-helper'; export const withRequestDownloadLink = withMutation( gql` @@ -17,3 +19,93 @@ export const withRequestDownloadLink = withMutation( }), } ); + +export const withRequestAccountDeletion = withMutation( + gql` + mutation RequestAccountDeletion { + requestAccountDeletion { + ...RequestAccountDeletionResponse + } + } + `, + { + props: ({ mutate }) => ({ + requestAccountDeletion: () => { + return mutate({ + variables: {}, + update: proxy => { + const RequestAccountDeletionQuery = gql` + query Talk_CancelAccountDeletion { + me { + id + scheduledDeletionDate + } + } + `; + + const prev = proxy.readQuery({ + query: RequestAccountDeletionQuery, + }); + + const scheduledDeletionDate = moment() + .add(24, 'hours') + .toDate(); + + const data = update(prev, { + me: { + scheduledDeletionDate: { $set: scheduledDeletionDate }, + }, + }); + + proxy.writeQuery({ + query: RequestAccountDeletionQuery, + data, + }); + }, + }); + }, + }), + } +); + +export const withCancelAccountDeletion = withMutation( + gql` + mutation RequestDownloadLink { + cancelAccountDeletion { + ...CancelAccountDeletionResponse + } + } + `, + { + props: ({ mutate }) => ({ + cancelAccountDeletion: () => { + return mutate({ + variables: {}, + update: proxy => { + const CancelAccountDeletionQuery = gql` + query Talk_CancelAccountDeletion { + me { + id + scheduledDeletionDate + } + } + `; + + const prev = proxy.readQuery({ query: CancelAccountDeletionQuery }); + + const data = update(prev, { + me: { + scheduledDeletionDate: { $set: null }, + }, + }); + + proxy.writeQuery({ + query: CancelAccountDeletionQuery, + data, + }); + }, + }); + }, + }), + } +); From ea71b779d2df69464235a18f0627611304c06054 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 15:51:50 -0600 Subject: [PATCH 10/13] password patches --- .../client/components/ChangePassword.css | 17 +++++++++++------ .../client/components/DeleteMyAccountDialog.js | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/talk-plugin-local-auth/client/components/ChangePassword.css b/plugins/talk-plugin-local-auth/client/components/ChangePassword.css index af59ae65f..0df8eb409 100644 --- a/plugins/talk-plugin-local-auth/client/components/ChangePassword.css +++ b/plugins/talk-plugin-local-auth/client/components/ChangePassword.css @@ -1,22 +1,27 @@ .container { position: relative; color: #202020; - padding: 10px; border-radius: 2px; border: solid 1px transparent; box-sizing: border-box; justify-content: space-between; - + &.editing { + padding: 10px; border-color: #979797; background-color: #EDEDED; + + .actions { + top: 10px; + right: 10px; + } } } .actions { position: absolute; - top: 10px; - right: 10px; + top: 0px; + right: 0px; display: flex; flex-direction: column; align-items: center; @@ -35,7 +40,7 @@ } .detailLink { - color: #00538A; + color: #00538A; text-decoration: none; font-size: 0.9em; &:hover { @@ -59,7 +64,7 @@ > i { font-size: 17px; } - + &:hover { background-color: #399ee2; color: white; diff --git a/plugins/talk-plugin-profile-data/client/components/DeleteMyAccountDialog.js b/plugins/talk-plugin-profile-data/client/components/DeleteMyAccountDialog.js index 9264bb75c..584fbb1b8 100644 --- a/plugins/talk-plugin-profile-data/client/components/DeleteMyAccountDialog.js +++ b/plugins/talk-plugin-profile-data/client/components/DeleteMyAccountDialog.js @@ -97,7 +97,7 @@ DeleteMyAccountDialog.propTypes = { showDialog: PropTypes.bool.isRequired, closeDialog: PropTypes.func.isRequired, requestAccountDeletion: PropTypes.func.isRequired, - scheduledDeletionDate: PropTypes.any.isRequired, + scheduledDeletionDate: PropTypes.any, organizationContactEmail: PropTypes.string.isRequired, }; From fa66f07db6cbd8bf915a07e327186a387f4b8caa Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 15:58:52 -0600 Subject: [PATCH 11/13] standardized styles, fixed mutation bug --- .../client/components/DeleteMyAccount.css | 23 ------------- .../client/components/DeleteMyAccount.js | 34 +++---------------- .../client/graphql.js | 2 +- 3 files changed, 6 insertions(+), 53 deletions(-) diff --git a/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.css b/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.css index e524d990a..e69de29bb 100644 --- a/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.css +++ b/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.css @@ -1,23 +0,0 @@ -.button { - color: #787D80; - border-radius: 2px; - border: 1px solid #787d80; - background-color: transparent; - height: 30px; - font-size: 0.9em; - line-height: normal; - - &:hover { - background-color: #eaeaea; - } - - &.secondary { - background-color: #787D80; - color: white; - } - - > i { - font-size: 1.2em; - vertical-align: middle; - } -} \ No newline at end of file diff --git a/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.js b/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.js index bbaca5b96..bbada134f 100644 --- a/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.js +++ b/plugins/talk-plugin-profile-data/client/components/DeleteMyAccount.js @@ -1,8 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import cn from 'classnames'; import moment from 'moment'; -import styles from './DeleteMyAccount.css'; import { Button } from 'plugin-api/beta/client/components/ui'; import DeleteMyAccountDialog from './DeleteMyAccountDialog'; import { getErrorMessages } from 'coral-framework/utils'; @@ -59,28 +57,13 @@ class DeleteMyAccount extends React.Component { scheduledDeletionDate={scheduledDeletionDate} organizationContactEmail={organizationContactEmail} /> -

+

{t('delete_request.delete_my_account')}

-

+

{t('delete_request.delete_my_account_description')}

-

+

{scheduledDeletionDate && t( 'delete_request.already_submitted_request_description', @@ -88,18 +71,11 @@ class DeleteMyAccount extends React.Component { )}

{scheduledDeletionDate ? ( - ) : ( - )} diff --git a/plugins/talk-plugin-profile-data/client/graphql.js b/plugins/talk-plugin-profile-data/client/graphql.js index e0c459f7e..9b3711bfc 100644 --- a/plugins/talk-plugin-profile-data/client/graphql.js +++ b/plugins/talk-plugin-profile-data/client/graphql.js @@ -10,7 +10,7 @@ export default { ), }, mutations: { - RequestDownloadLink: () => ({ + DownloadCommentHistory: () => ({ updateQueries: { CoralEmbedStream_Profile: previousData => update(previousData, { From 949925586f414cb54dc4aa0621174b4ce1f2c838 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 17:50:53 -0600 Subject: [PATCH 12/13] handle confirmed email better --- .../talk-plugin-local-auth/client/graphql.js | 34 +++++++++++++++++++ .../talk-plugin-local-auth/client/index.js | 2 ++ .../talk-plugin-local-auth/server/mutators.js | 1 + services/users.js | 5 ++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 plugins/talk-plugin-local-auth/client/graphql.js diff --git a/plugins/talk-plugin-local-auth/client/graphql.js b/plugins/talk-plugin-local-auth/client/graphql.js new file mode 100644 index 000000000..67fde246a --- /dev/null +++ b/plugins/talk-plugin-local-auth/client/graphql.js @@ -0,0 +1,34 @@ +import update from 'immutability-helper'; +import get from 'lodash/get'; + +export default { + mutations: { + UpdateEmailAddress: () => ({ + updateQueries: { + CoralEmbedStream_Profile: previousData => { + // Find the local profile (if they have one). + const localIndex = get(previousData, 'me.profiles', []).indexOf( + ({ provider }) => provider === 'local' + ); + if (localIndex < 0) { + return previousData; + } + + // Mutate the confirmedAt, because we changed the email address, they + // can't possibly be confirmed now as well. + return update(previousData, { + me: { + profiles: { + [localIndex]: { + confirmedAt: { + $set: null, + }, + }, + }, + }, + }); + }, + }, + }), + }, +}; diff --git a/plugins/talk-plugin-local-auth/client/index.js b/plugins/talk-plugin-local-auth/client/index.js index c669effaa..d5f9f8636 100644 --- a/plugins/talk-plugin-local-auth/client/index.js +++ b/plugins/talk-plugin-local-auth/client/index.js @@ -1,6 +1,7 @@ import ChangePassword from './containers/ChangePassword'; import Profile from './containers/Profile'; import translations from './translations.yml'; +import graphql from './graphql'; export default { translations, @@ -8,4 +9,5 @@ export default { profileHeader: [Profile], profileSettings: [ChangePassword], }, + ...graphql, }; diff --git a/plugins/talk-plugin-local-auth/server/mutators.js b/plugins/talk-plugin-local-auth/server/mutators.js index cb34bed7a..6798584f5 100644 --- a/plugins/talk-plugin-local-auth/server/mutators.js +++ b/plugins/talk-plugin-local-auth/server/mutators.js @@ -43,6 +43,7 @@ async function updateUserEmailAddress(ctx, email, confirmPassword) { }, { $set: { 'profiles.$.id': email }, + $unset: { 'profiles.$.metadata.confirmed_at': 1 }, } ); diff --git a/services/users.js b/services/users.js index 1e84c8ff1..d5486b3f8 100644 --- a/services/users.js +++ b/services/users.js @@ -32,6 +32,7 @@ const i18n = require('./i18n'); const Wordlist = require('./wordlist'); const DomainList = require('./domain_list'); const Limit = require('./limit'); +const { get } = require('lodash'); const EMAIL_CONFIRM_JWT_SUBJECT = 'email_confirm'; const PASSWORD_RESET_JWT_SUBJECT = 'password_reset'; @@ -965,7 +966,9 @@ class Users { throw new ErrNotFound(); } - if (profile.metadata && profile.metadata.confirmed_at !== null) { + // Check to see if the profile has already been confirmed. + const confirmedAt = get(profile, 'metadata.confirmed_at', null); + if (confirmedAt && confirmedAt < Date.now()) { throw new ErrEmailAlreadyVerified(); } From 15df20e72056739c0a200db23cb81f87c751cda4 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 17:57:09 -0600 Subject: [PATCH 13/13] fix --- plugins/talk-plugin-local-auth/client/graphql.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/talk-plugin-local-auth/client/graphql.js b/plugins/talk-plugin-local-auth/client/graphql.js index 67fde246a..eddf58315 100644 --- a/plugins/talk-plugin-local-auth/client/graphql.js +++ b/plugins/talk-plugin-local-auth/client/graphql.js @@ -1,5 +1,6 @@ import update from 'immutability-helper'; import get from 'lodash/get'; +import findIndex from 'lodash/findIndex'; export default { mutations: { @@ -7,9 +8,9 @@ export default { updateQueries: { CoralEmbedStream_Profile: previousData => { // Find the local profile (if they have one). - const localIndex = get(previousData, 'me.profiles', []).indexOf( - ({ provider }) => provider === 'local' - ); + const localIndex = findIndex(get(previousData, 'me.profiles', []), { + provider: 'local', + }); if (localIndex < 0) { return previousData; }