From a1114a8a83436f92a3f254d6e51fb43da1af2a2f Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 6 Mar 2020 08:09:38 +0100 Subject: [PATCH] feat: additional confirm inserted before really deleting --- .../src/middleware/permissionsMiddleware.js | 6 +- backend/src/schema/resolvers/users.js | 19 +- backend/src/schema/types/schema.gql | 5 - backend/src/schema/types/type/User.gql | 5 + .../DeleteUserModal/DeleteUserModal.spec.js | 29 --- .../DeleteUserModal/DeleteUserModal.vue | 103 ----------- webapp/components/Modal.vue | 14 +- .../components/Modal/DeleteUserModal.spec.js | 87 +++++++++ webapp/components/Modal/DeleteUserModal.vue | 169 ++++++++++++++++++ webapp/locales/de.json | 5 +- webapp/locales/en.json | 3 +- webapp/pages/profile/_id/_slug.vue | 8 +- 12 files changed, 279 insertions(+), 174 deletions(-) delete mode 100644 webapp/components/DeleteUserModal/DeleteUserModal.spec.js delete mode 100644 webapp/components/DeleteUserModal/DeleteUserModal.vue create mode 100644 webapp/components/Modal/DeleteUserModal.spec.js create mode 100644 webapp/components/Modal/DeleteUserModal.vue diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index d307eaacc..fa88d9348 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -68,11 +68,7 @@ const isAuthor = rule({ const isDeletingOwnAccount = rule({ cache: 'no_cache', })(async (parent, args, context, info) => { - if (isAdmin === true) { - return true - } else { - return context.user.id === args.id - } + return context.user.id === args.id }) const noEmailFilter = rule({ diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index f68f4c2c5..2e1effd6c 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -173,8 +173,7 @@ export default { } }, DeleteUser: async (object, params, context, resolveInfo) => { - const { resource } = params - const { id } = params + const { resource, id } = params const session = context.driver.session() try { if (resource && resource.length) { @@ -182,14 +181,14 @@ export default { resource.map(node => { return transaction.run( ` - MATCH (resource:${node})<-[:WROTE]-(author:User {id: $userId}) - OPTIONAL MATCH (resource)<-[:COMMENTS]-(comment:Comment) - SET resource.deleted = true - SET resource.content = 'UNAVAILABLE' - SET resource.contentExcerpt = 'UNAVAILABLE' - SET comment.deleted = true - RETURN author - `, + MATCH (resource:${node})<-[:WROTE]-(author:User {id: $userId}) + OPTIONAL MATCH (resource)<-[:COMMENTS]-(comment:Comment) + SET resource.deleted = true + SET resource.content = 'UNAVAILABLE' + SET resource.contentExcerpt = 'UNAVAILABLE' + SET comment.deleted = true + RETURN author + `, { userId: id, }, diff --git a/backend/src/schema/types/schema.gql b/backend/src/schema/types/schema.gql index 23c2ded4d..b15179443 100644 --- a/backend/src/schema/types/schema.gql +++ b/backend/src/schema/types/schema.gql @@ -12,11 +12,6 @@ type Mutation { unfollowUser(id: ID!): User } -enum Deletable { - Post - Comment -} - enum ShoutTypeEnum { Post } diff --git a/backend/src/schema/types/type/User.gql b/backend/src/schema/types/type/User.gql index 948d8e7d3..1bee193ae 100644 --- a/backend/src/schema/types/type/User.gql +++ b/backend/src/schema/types/type/User.gql @@ -192,6 +192,11 @@ type Query { ) } +enum Deletable { + Post + Comment +} + type Mutation { UpdateUser ( id: ID! diff --git a/webapp/components/DeleteUserModal/DeleteUserModal.spec.js b/webapp/components/DeleteUserModal/DeleteUserModal.spec.js deleted file mode 100644 index e8a11ee1e..000000000 --- a/webapp/components/DeleteUserModal/DeleteUserModal.spec.js +++ /dev/null @@ -1,29 +0,0 @@ -import { config, shallowMount, mount } from '@vue/test-utils' - -import ConfirmModal from './DeleteUserModal.vue' - -const localVue = global.localVue - -describe('DisableModal.vue', () => { - let mocks - let propsData - let wrapper - - beforeEach(() => { - propsData = { - slug: "oger-ly", - id: "u1", - name: "Oger Ly", - avatar: "avatar-link", - contributionsCount: "42", - commentedCount: "24", - createdAt: "date-created-at", - } - mocks = { - $t: jest.fn(), - $filters: { - truncate: a => a, - }, - } - }) -}) \ No newline at end of file diff --git a/webapp/components/DeleteUserModal/DeleteUserModal.vue b/webapp/components/DeleteUserModal/DeleteUserModal.vue deleted file mode 100644 index 80119a722..000000000 --- a/webapp/components/DeleteUserModal/DeleteUserModal.vue +++ /dev/null @@ -1,103 +0,0 @@ - - - diff --git a/webapp/components/Modal.vue b/webapp/components/Modal.vue index 71d8a2659..a76adac3f 100644 --- a/webapp/components/Modal.vue +++ b/webapp/components/Modal.vue @@ -30,17 +30,7 @@ :modalData="data.modalData" @close="close" /> - + @@ -49,7 +39,7 @@ import ConfirmModal from '~/components/Modal/ConfirmModal' import DisableModal from '~/components/Modal/DisableModal' import ReleaseModal from '~/components/ReleaseModal/ReleaseModal.vue' import ReportModal from '~/components/Modal/ReportModal' -import DeleteUserModal from '~/components/DeleteUserModal/DeleteUserModal.vue' +import DeleteUserModal from '~/components/Modal/DeleteUserModal.vue' import { mapGetters } from 'vuex' export default { diff --git a/webapp/components/Modal/DeleteUserModal.spec.js b/webapp/components/Modal/DeleteUserModal.spec.js new file mode 100644 index 000000000..5e81f96aa --- /dev/null +++ b/webapp/components/Modal/DeleteUserModal.spec.js @@ -0,0 +1,87 @@ +/* +import { mount } from '@vue/test-utils' +import Vuex from 'vuex' + + +import DeleteUserModal from './DeleteUserModal.vue' + +const localVue = global.localVue + + +describe('ConfirmModal.vue', () => { + let getters, mutations, mocks, propsData + + + beforeEach(() => { + propsData = { + type: 'user', + id: 'u23', + name: 'Huey', + slug: 'huey', + avatar: 'link', + contributionsCount: 2, + commentedCount: 3, + createdAt: 'datum', + + + } + mocks = { + $t: jest.fn(str => str), + $i18n: { + locale: () => 'en', + }, + $router: { + push: jest.fn(), + }, + } + }) + + + + describe('mount', () => { + mutations = { + 'modal/SET_OPEN': jest.fn(), + } + getters = { + 'auth/isModerator': () => false, + 'auth/isAdmin': () => false, + } + + const store = new Vuex.Store({ mutations, getters }) + const wrapper = mount(DeleteUserModal, { + propsData: { + ...values, + }, + mocks, + store, + localVue, + }) + console.log("wrapper", wrapper) + // menuToggle = wrapper.find('[data-test="content-menu-button"]') + // menuToggle.trigger('click') + //return wrapper + + + + describe('owner of contribution', () => { + let wrapper + beforeEach(() => { + wrapper = openContentMenu({ + isOwner: true, + resourceType: 'contribution', + resource: { + id: 'd23a4265-f5f7-4e17-9f86-85f714b4b9f8', + }, + }) + openModalSpy = jest.spyOn(wrapper.vm, 'openModal') + }) + + + + + }) +}) + + +}) +*/ diff --git a/webapp/components/Modal/DeleteUserModal.vue b/webapp/components/Modal/DeleteUserModal.vue new file mode 100644 index 000000000..708c2e545 --- /dev/null +++ b/webapp/components/Modal/DeleteUserModal.vue @@ -0,0 +1,169 @@ + + + + + diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 1ec1bcbb2..8b4416f30 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -640,11 +640,12 @@ "accountDescription": "Sei dir bewusst, dass deine Beiträge und Kommentare für unsere Community wichtig sind. Wenn du sie trotzdem löschen möchtest, musst du sie unten markieren.", "accountWarning": "Dein Konto, deine Beiträge oder Kommentare kannst du nach dem Löschen WEDER VERWALTEN NOCH WIEDERHERSTELLEN!", "accountWarningAdmin": "Das Konto, die Beiträge oder Kommentare können nach dem Löschen WEDER VERWALTEN NOCH WIEDERHERGESTELLT WERDEN!", - "accountWarningIsAdmin": "Achtung! Du bist Admin!!", + "accountWarningIsAdmin": "Achtung! Du löschst jetzt ein Benutzerkonto!", "commentedCount": "Meine {count} Kommentare löschen", "contributionsCount": "Meine {count} Beiträge löschen", + "confirmDeleting": "Benutzerkonto jetzt löschen", "infoAdmin": "Alle Beiträge und Kommentare des Users werden zusätzlich gelöscht!", - "name": "Benutzerkonto löschen", + "name": "Benutzerkonto löschen", "pleaseConfirm": "Zerstörerische Aktion! Gib „{confirm}“ ein, um zu bestätigen.", "success": "Konto erfolgreich gelöscht!" }, diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 6e4020783..0a8391ee1 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -640,9 +640,10 @@ "accountDescription": "Be aware that your Posts and Comments are important to our community. If you still choose to delete them, you have to mark them below.", "accountWarning": "You CAN'T MANAGE and CAN'T RECOVER your Account, Posts, or Comments after deleting your account!", "accountWarningAdmin": "The account, contributions or comments can NOT BE ADMINISTERED OR RESTORED after deletion!", - "accountWarningIsAdmin": "Heads up! You are Admin!!", + "accountWarningIsAdmin": "Heads up! You are about to delete a user account!", "commentedCount": "Delete my {count} comments", "contributionsCount": "Delete my {count} posts", + "confirmDeleting": "Delete user account now", "infoAdmin": "All contributions and comments of the user are additionally deleted!", "name": "Delete user account", "pleaseConfirm": "Destructive action! Type “{confirm}” to confirm.", diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index a5de575f9..ba34ae6a2 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -441,13 +441,7 @@ export default { this.$store.commit('modal/SET_OPEN', { name: 'delete', data: { - id: userdata.id, - name: userdata.name, - slug: userdata.slug, - avatar: userdata.avatar, - contributionsCount: userdata.contributionsCount, - commentedCount: userdata.commentedCount, - createdAt: userdata.createdAt, + userdata: userdata, }, }) },