From f8dbcb80ab4cfdd49ff27cf7db88e7c852c0ab55 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 17 Jul 2020 13:45:39 +0300 Subject: [PATCH 1/6] Add confirmation when deleting a single user --- src/views/users/components/ModerationDropdown.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/views/users/components/ModerationDropdown.vue b/src/views/users/components/ModerationDropdown.vue index 3a145290..f06cbd3c 100644 --- a/src/views/users/components/ModerationDropdown.vue +++ b/src/views/users/components/ModerationDropdown.vue @@ -143,7 +143,18 @@ export default { this.$store.dispatch('ResendConfirmationEmail', [user]) }, handleDeletion(user) { - this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id }) + this.$confirm('Are you sure you want to delete this account?', 'Warning', { + confirmButtonText: 'Delete', + cancelButtonText: 'Cancel', + type: 'warning' + }).then(() => { + this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id }) + }).catch(() => { + this.$message({ + type: 'info', + message: 'Delete canceled' + }) + }) }, handleEmailConfirmation(user) { this.$store.dispatch('ConfirmUsersEmail', { users: [user], _userId: user.id, _statusId: this.statusId }) From 434f8ad2dd87d83dced0fe03f4ed92ae515b6754 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 17 Jul 2020 13:47:50 +0300 Subject: [PATCH 2/6] Do not fetch user profile when deleting multiple accounts --- src/store/modules/users.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 5f35bf44..83d2ceee 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -197,7 +197,9 @@ const users = { const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id)) commit('SET_USERS', updatedUsers) - dispatch('FetchUserProfile', { userId: _userId, godmode: false }) + if (_userId) { + dispatch('FetchUserProfile', { userId: _userId, godmode: false }) + } dispatch('SuccessMessage') }, async FetchUsers({ commit, dispatch, getters, state }, { page }) { From d211d4f9349a7331e4170bf3db711c644d005e17 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 17 Jul 2020 14:15:39 +0300 Subject: [PATCH 3/6] Fix optimistc update for deleting users --- src/store/modules/users.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 83d2ceee..4db8042f 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -193,9 +193,10 @@ const users = { } catch (_e) { return } - const deletedUsersIds = users.map(deletedUser => deletedUser.id) - const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id)) - commit('SET_USERS', updatedUsers) + const updatedUsers = users.map(user => { + return { ...user, deactivated: true } + }) + commit('SWAP_USERS', updatedUsers) if (_userId) { dispatch('FetchUserProfile', { userId: _userId, godmode: false }) From a70a5bb15cd6eec9adf21272c030567343ae5560 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 18 Jul 2020 00:13:06 +0300 Subject: [PATCH 4/6] Fix tests --- test/views/users/index.test.js | 6 ++++-- test/views/users/multipleUsersMenu.test.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/views/users/index.test.js b/test/views/users/index.test.js index 57cefad1..847de253 100644 --- a/test/views/users/index.test.js +++ b/test/views/users/index.test.js @@ -156,11 +156,13 @@ describe('Users actions', () => { stubs: ['router-link'] }) await flushPromises() - expect(store.state.users.fetchedUsers.length).toEqual(3) + expect(store.state.users.fetchedUsers[1].deactivated).toBe(false) wrapper.find(htmlElement(2, 2)).trigger('click') + store.dispatch('DeleteUsers', { users: [{ active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['sandbox'] }] }) + await flushPromises() - expect(store.state.users.fetchedUsers.length).toEqual(2) + expect(store.state.users.fetchedUsers[1].deactivated).toBe(true) done() }) diff --git a/test/views/users/multipleUsersMenu.test.js b/test/views/users/multipleUsersMenu.test.js index aea1a9aa..c956bed4 100644 --- a/test/views/users/multipleUsersMenu.test.js +++ b/test/views/users/multipleUsersMenu.test.js @@ -225,11 +225,11 @@ describe('Apply users actions to multiple users', () => { expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled() const remove = wrapper.vm.mappers().remove - expect(store.state.users.fetchedUsers.length).toEqual(3) + expect(store.state.users.fetchedUsers.filter(user => user.deactivated).length).toEqual(1) remove() await flushPromises() - expect(store.state.users.fetchedUsers.length).toEqual(0) + expect(store.state.users.fetchedUsers.length).toEqual(3) done() }) From c771ab057cc9accca34d825fc959f316f9838eaf Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 18 Jul 2020 00:18:06 +0300 Subject: [PATCH 5/6] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3b692bf..d3b7f3af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add ability to disable multi-factor authentication for a user - Ability to configure S3 settings on Upload tab - Show number of open reports in Sidebar Menu +- Add confirmation message when deleting a user ### Changed From 240340ff83cba0624c5cae3aa49561ecaaf27d8f Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 18 Jul 2020 00:28:04 +0300 Subject: [PATCH 6/6] Update confirmation message --- src/lang/en.js | 1 + src/views/users/components/ModerationDropdown.vue | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lang/en.js b/src/lang/en.js index 35d91252..0dcfaf4c 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -212,6 +212,7 @@ export default { revokeRightConfirmation: 'Are you sure you want to revoke {right} rights from all selected users?', activateMultipleUsersConfirmation: 'Are you sure you want to activate accounts of all selected users?', deactivateMultipleUsersConfirmation: 'Are you sure you want to deactivate accounts of all selected users?', + deleteUsersConfirmation: 'Are you sure you want to delete this account? This action cannot be undone.', deleteMultipleUsersConfirmation: 'Are you sure you want to delete accounts of all selected users?', addTagForMultipleUsersConfirmation: 'Are you sure you want to apply tag to all selected users?', removeTagFromMultipleUsersConfirmation: 'Are you sure you want to remove tag from all selected users?', diff --git a/src/views/users/components/ModerationDropdown.vue b/src/views/users/components/ModerationDropdown.vue index f06cbd3c..6f9a5651 100644 --- a/src/views/users/components/ModerationDropdown.vue +++ b/src/views/users/components/ModerationDropdown.vue @@ -143,11 +143,13 @@ export default { this.$store.dispatch('ResendConfirmationEmail', [user]) }, handleDeletion(user) { - this.$confirm('Are you sure you want to delete this account?', 'Warning', { - confirmButtonText: 'Delete', - cancelButtonText: 'Cancel', - type: 'warning' - }).then(() => { + this.$confirm( + this.$t('users.deleteUsersConfirmation'), + { + confirmButtonText: 'Delete', + cancelButtonText: 'Cancel', + type: 'warning' + }).then(() => { this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id }) }).catch(() => { this.$message({