Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented auto logout after account deletion was requested #906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
import { ERROR_HANDLE_SUPPRESS } from '@shopgate/pwa-core/constants/ErrorHandleTypes';
import config from './../config';
import config from '../config';

export default () => (dispatch) => {
if (!config.isActive) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { isUserLoggedIn } from '@shopgate/pwa-common/selectors/user';
import config from './../config';
import config from '../config';

/**
* @param {Object} state The current application state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { main$ } from '@shopgate/pwa-common/streams/main';
import ToastProvider from '@shopgate/pwa-common/providers/toast';
import { logout, userDidLogout$ } from '@shopgate/engage/user';
import { historyPush } from '@shopgate/engage/core';
import { NavDrawer } from '@shopgate/pwa-ui-material';
import showModal from '@shopgate/pwa-common/actions/modal/showModal';
import deleteAccountAction from './action';
Expand All @@ -9,23 +10,35 @@ export default (subscribe) => {
const deleteAccountSuccess$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_SUCCESS');
const deleteAccountFailed$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_FAILED');

const processSuccess$ = deleteAccountSuccess$.zip(userDidLogout$).map(([first]) => first);

subscribe(deleteAccountRequested$, async ({ dispatch }) => {
const confirmed = await dispatch(showModal({
message: 'user.delete_account_confirm',
title: null,
}));
if (confirmed) {
deleteAccountAction()(dispatch);
dispatch(deleteAccountAction());
dispatch(logout(false));
}
});

subscribe(deleteAccountSuccess$, ({ events }) => {
subscribe(processSuccess$, async ({ dispatch }) => {
NavDrawer.close();

events.emit(ToastProvider.ADD, {
id: 'user.account.deleted',
const confirmed = await dispatch(showModal({
confirm: 'modal.ok',
dismiss: 'user.contact_us',
message: 'user.delete_account_success',
});
title: null,
}));

if (confirmed === false) {
// User pressed the "contact us" button
dispatch(historyPush({
pathname: '/page/imprint',
}));
}
});

subscribe(deleteAccountFailed$, ({ dispatch }) => {
Expand Down
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/de-DE.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Kontodaten löschen",
"delete_account_success": "Wir haben Ihre Anfrage zum Löschen Ihrer Kontodaten erhalten.",
"delete_account_success": "Löschanfrage erhalten. Sie wurden ausgeloggt und wir werden Ihre Daten löschen, soweit das rechtlich möglich ist. Dieser Prozess kann einige Tage in Anspruch nehmen.",
"delete_account_error": "Ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es später erneut",
"delete_account_confirm": "Bitte bestätigen Sie die Löschung aller Kontodaten. Dies kann nicht rückgängig gemacht werden."
"delete_account_confirm": "Bitte bestätigen Sie die Löschung aller Kontodaten. Dies kann nicht rückgängig gemacht werden.",
"contact_us": "Kontakt"
}
}
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/en-US.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Delete my account",
"delete_account_success": "We received your request to delete your account.",
"delete_account_success": "Deletion request received. You have been logged out and we will take care of deleting your data in our system where legally possible. This process might take a few days.",
"delete_account_error": "An unexpected error occurred. Please try again later.",
"delete_account_confirm": "Press Confirm to delete all account data. This operation cannot be undone."
"delete_account_confirm": "Press Confirm to delete all account data. This operation cannot be undone.",
"contact_us": "Contact us"
}
}
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/es-ES.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Eliminar mi cuenta",
"delete_account_success": "Hemos recibido la solicitud de eliminar tu cuenta.",
"delete_account_success": "Solicitud de eliminación recibida. Se ha cerrado la sesión y eliminaremos sus datos en nuestro sistema siempre que sea legalmente posible. Este proceso puede tardar algunos días.",
"delete_account_error": "Se ha producido un error inesperado. Inténtalo de nuevo más tarde.",
"delete_account_confirm": "Pulsa Confirmar para eliminar todos los datos de tu cuenta. Esta operación no se puede deshacer."
"delete_account_confirm": "Pulsa Confirmar para eliminar todos los datos de tu cuenta. Esta operación no se puede deshacer.",
"contact_us": "Contáctenos"
}
}
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/fr-FR.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Supprimer mon compte",
"delete_account_success": "Nous avons reçu votre demande de suppression de votre compte.",
"delete_account_success": "Demande de suppression reçue. Vous avez été déconnecté et nous supprimerons vos données de notre système lorsque cela sera légalement possible. Ce processus peut prendre quelques jours.",
"delete_account_error": "Une erreur inopinée s'est produite. Veuillez réessayer ultérieurement.",
"delete_account_confirm": "Appuyez sur la touche Confirmer pour supprimer toutes les données du compte. Cette opération ne pourra être annulée."
"delete_account_confirm": "Appuyez sur la touche Confirmer pour supprimer toutes les données du compte. Cette opération ne pourra être annulée.",
"contact_us": "Nous contacter"
}
}
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/it-IT.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Cancella il mio account",
"delete_account_success": "Abbiamo ricevuto la tua richiesta di cancellazione dell'account.",
"delete_account_success": "Richiesta di cancellazione ricevuta. Sei stato disconnesso e cancelleremo i tuoi dati nel nostro sistema qualora fosse possibile legalmente. Questo processo potrebbe richiedere alcuni giorni.",
"delete_account_error": "Si è verificato un errore imprevisto. Riprova più tardi per favore.",
"delete_account_confirm": "Premi Conferma per cancellare tutti i dati dell'account. Questa operazione non può essere annullata."
"delete_account_confirm": "Premi Conferma per cancellare tutti i dati dell'account. Questa operazione non può essere annullata.",
"contact_us": "Contattaci"
}
}
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/nl-NL.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Mijn account verwijderen",
"delete_account_success": "Wij hebben uw verzoek om uw account te verwijderen ontvangen.",
"delete_account_success": "Verwijderingsverzoek ontvangen. U bent uitgelogd en wij zullen uw gegevens in ons systeem verwijderen waar dit wettelijk mogelijk is. Dit proces kan enkele dagen duren.",
"delete_account_error": "Er is een onverwachte fout opgetreden. Probeer het later nog eens.",
"delete_account_confirm": "Druk op Bevestigen om alle accountgegevens te verwijderen. Deze operatie kan niet ongedaan worden gemaakt."
"delete_account_confirm": "Druk op Bevestigen om alle accountgegevens te verwijderen. Deze operatie kan niet ongedaan worden gemaakt.",
"contact_us": "Contacteer ons"
}
}
5 changes: 3 additions & 2 deletions extensions/@shopgate-user-privacy/frontend/locale/pt-PT.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"user": {
"delete_account": "Deletar minha conta",
"delete_account_success": "Recebemos o seu pedido de eliminação da sua conta.",
"delete_account_success": "Solicitaçăo de exclusăo recebida. Vocę foi desconectado e excluiremos os seus dados no nosso sistema onde for legalmente possível. Esse processo pode demorar alguns dias.",
"delete_account_error": "Ocorreu um erro inesperado. Por favor, tente novamente mais tarde.",
"delete_account_confirm": "Pressione Confirmar para excluir todos os dados da conta. Esta operação não pode ser desfeita."
"delete_account_confirm": "Pressione Confirmar para excluir todos os dados da conta. Esta operação não pode ser desfeita.",
"contact_us": "Contacte-nos"
}
}
4 changes: 3 additions & 1 deletion libraries/common/action-creators/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ export const requestLogout = () => ({

/**
* Creates the dispatched RECEIVE_LOGOUT action object.
* @param {boolean} [notify=true] If set to TRUE users are notified when the logout was successful.
* @returns {Object} The dispatched action object.
*/
export const successLogout = () => ({
export const successLogout = (notify = true) => ({
type: SUCCESS_LOGOUT,
notify,
});

/**
Expand Down
22 changes: 20 additions & 2 deletions libraries/common/action-creators/user/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,28 @@ describe('Action Creators: user', () => {
});

describe('successLogout()', () => {
it('should work as expected', () => {
const expected = { type: SUCCESS_LOGOUT };
it('should work as expected when called without parameter', () => {
const expected = {
type: SUCCESS_LOGOUT,
notify: true,
};
expect(successLogout()).toEqual(expected);
});

it('should work as expected when called with true', () => {
const expected = {
type: SUCCESS_LOGOUT,
notify: true,
};
expect(successLogout(true)).toEqual(expected);
});
it('should work as expected when called with false', () => {
const expected = {
type: SUCCESS_LOGOUT,
notify: false,
};
expect(successLogout(false)).toEqual(expected);
});
});

describe('errorLogout()', () => {
Expand Down
5 changes: 3 additions & 2 deletions libraries/common/actions/user/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { mutable } from '../../helpers/redux';

/**
* Logout the current user.
* @param {boolean} [notify=true] If set to TRUE users are notified when the logout was successful.
* @return {Function} A redux thunk.
*/
function logout() {
function logout(notify = true) {
return (dispatch) => {
dispatch(requestLogout());

Expand All @@ -24,7 +25,7 @@ function logout() {
const { success, messages } = result;

if (success) {
dispatch(successLogout());
dispatch(successLogout(notify));
} else {
dispatch(errorLogout(messages));
}
Expand Down
6 changes: 5 additions & 1 deletion libraries/common/subscriptions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export default function user(subscribe) {
dispatch(fetchUser());
});

subscribe(userDidLogout$, ({ dispatch }) => {
subscribe(userDidLogout$, ({ dispatch, action }) => {
if (action.notify === false) {
return;
}

dispatch(showModal({
confirm: 'modal.ok',
dismiss: null,
Expand Down