diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index 10dc98845..d307eaacc 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -68,7 +68,11 @@ const isAuthor = rule({ const isDeletingOwnAccount = rule({ cache: 'no_cache', })(async (parent, args, context, info) => { - return context.user.id === args.id + if (isAdmin === true) { + return true + } else { + return context.user.id === args.id + } }) const noEmailFilter = rule({ @@ -133,7 +137,7 @@ export default shield( CreateComment: isAuthenticated, UpdateComment: isAuthor, DeleteComment: isAuthor, - DeleteUser: isDeletingOwnAccount, + DeleteUser: or(isDeletingOwnAccount, isAdmin), requestPasswordReset: allow, resetPassword: allow, AddPostEmotions: isAuthenticated, diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index a1b68e20d..f68f4c2c5 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -174,6 +174,7 @@ export default { }, DeleteUser: async (object, params, context, resolveInfo) => { const { resource } = params + const { id } = params const session = context.driver.session() try { if (resource && resource.length) { @@ -190,7 +191,7 @@ export default { RETURN author `, { - userId: context.user.id, + userId: id, }, ) }) @@ -212,7 +213,7 @@ export default { DETACH DELETE socialMedia RETURN user `, - { userId: context.user.id }, + { userId: id }, ) log(deleteUserTransactionResponse) return deleteUserTransactionResponse.records.map(record => record.get('user').properties) diff --git a/webapp/components/ContentMenu/ContentMenu.vue b/webapp/components/ContentMenu/ContentMenu.vue index c69a2fcbc..4526fb6f4 100644 --- a/webapp/components/ContentMenu/ContentMenu.vue +++ b/webapp/components/ContentMenu/ContentMenu.vue @@ -154,6 +154,15 @@ export default { path: '/settings', icon: 'edit', }) + if (this.isAdmin === true) { + routes.push({ + label: this.$t(`settings.deleteUserAccount.name`), + callback: () => { + this.$emit('delete', this.resource) + }, + icon: 'trash', + }) + } } else { if (this.resource.isMuted) { routes.push({ @@ -189,6 +198,15 @@ export default { icon: 'user-times', }) } + if (this.isAdmin === true) { + routes.push({ + label: this.$t(`settings.deleteUserAccount.name`), + callback: () => { + this.$emit('delete', this.resource) + }, + icon: 'trash', + }) + } } } diff --git a/webapp/components/DeleteData/DeleteData.vue b/webapp/components/DeleteData/DeleteData.vue index fbd13b32e..6c1730b79 100644 --- a/webapp/components/DeleteData/DeleteData.vue +++ b/webapp/components/DeleteData/DeleteData.vue @@ -4,12 +4,14 @@ {{ $t('settings.deleteUserAccount.name') }} - + {{ $t('settings.deleteUserAccount.pleaseConfirm', { confirm: currentUser.name }) }} - - {{ $t('settings.deleteUserAccount.accountDescription') }} - + + + {{ $t('settings.deleteUserAccount.accountDescription') }} + + {{ $t('settings.deleteUserAccount.contributionsCount', { @@ -17,7 +19,7 @@ }) }} - + {{ $t('settings.deleteUserAccount.commentedCount', { @@ -25,11 +27,18 @@ }) }} - - {{ $t('settings.deleteUserAccount.accountWarning') }} + + {{ $t('settings.deleteUserAccount.infoAdmin') }} + + + {{ $t('settings.deleteUserAccount.accountWarning') }} + {{ $t('settings.deleteUserAccount.accountWarningAdmin') }} - ACHTUNG! Du Bist Admin!! + + {{ $t('settings.deleteUserAccount.accountWarningIsAdmin') }} + --> - löschen abbrechen + {{ $t('actions.cancel') }} - User jetzt Löschen! + {{ $t('settings.deleteUserAccount.name') }} @@ -21,26 +21,21 @@ export default { DeleteData, }, props: { - name: { type: String, default: 'jetzt löschen' }, - type: { type: String, required: true }, + slug: { type: String, required: true }, id: { type: String, required: true }, + name: { type: String, required: true }, }, data() { return { isOpen: true, success: false, loading: false, + isAdmin: this.$store.getters['auth/isAdmin'], } }, computed: { title() { - return 'User Löschen' - // return this.$t(`release.${this.type}.title`) - }, - message() { - const name = this.$filters.truncate(this.name, 30) - return name - // return this.$t(`release.${this.type}.message`, { name }) + return this.$props.name + ' (' + this.$props.slug + ')' }, }, methods: { @@ -56,50 +51,25 @@ export default { try { // TODO: Use the "modalData" structure introduced in "ConfirmModal" and refactor this here. Be aware that all the Jest tests have to be refactored as well !!! // await this.modalData.buttons.confirm.callback() - await this.$apollo.mutate({ - /* mutation: gql` - mutation($resourceId: ID!, $disable: Boolean, $closed: Boolean) { - review(resourceId: $resourceId, disable: $disable, closed: $closed) { - disable - } - } - `, */ - mutation: gql` - mutation { - DeleteUser(id: "u3", resource: [Post, Comment]) { - id - name - slug - about - deleted - contributions { + this.$apollo + .mutate({ + mutation: gql` + mutation($id: ID!, $resource: [Deletable]) { + DeleteUser(id: $id, resource: $resource) { id - content - contentExcerpt - deleted - comments { - id - content - contentExcerpt - deleted - } - } - comments { - id - content - contentExcerpt - deleted } } - } - `, - variables: { resourceId: this.id, disable: false, closed: false }, - }) - this.$toast.success('user gelöscht') + `, + variables: { id: this.$props.id, resource: ['Post', 'Comment'] }, + }) + .then(() => { + this.$toast.success(this.$t('settings.deleteUserAccount.success')) + this.$router.history.push('/') + }) + .catch(error => { + this.$toast.error(error.message) + }) this.isOpen = false - setTimeout(() => { - this.$emit('close') - }, 1000) } catch (err) { this.$toast.error(err.message) this.isOpen = false diff --git a/webapp/components/Modal.vue b/webapp/components/Modal.vue index 861dbe6b7..02f6cd074 100644 --- a/webapp/components/Modal.vue +++ b/webapp/components/Modal.vue @@ -30,11 +30,11 @@ :modalData="data.modalData" @close="close" /> - @@ -45,7 +45,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 DeleteModal from '~/components/DeleteUserModal/DeleteUserModal.vue' +import DeleteUserModal from '~/components/DeleteUserModal/DeleteUserModal.vue' import { mapGetters } from 'vuex' export default { @@ -55,7 +55,7 @@ export default { ReleaseModal, ReportModal, ConfirmModal, - DeleteModal, + DeleteUserModal, }, computed: { ...mapGetters({ diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 524ee58fa..1ec1bcbb2 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -639,9 +639,12 @@ "deleteUserAccount": { "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!!", "commentedCount": "Meine {count} Kommentare löschen", "contributionsCount": "Meine {count} Beiträge löschen", - "name": "Benutzerkonto löschen", + "infoAdmin": "Alle Beiträge und Kommentare des Users werden zusätzlich gelöscht!", + "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 e6b8def5a..6e4020783 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -639,8 +639,11 @@ "deleteUserAccount": { "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!!", "commentedCount": "Delete my {count} comments", "contributionsCount": "Delete my {count} posts", + "infoAdmin": "All contributions and comments of the user are additionally deleted!", "name": "Delete user account", "pleaseConfirm": "Destructive action! Type “{confirm}” to confirm.", "success": "Account successfully deleted!" diff --git a/webapp/pages/admin/users.vue b/webapp/pages/admin/users.vue index acf843d43..4b8ca6ffe 100644 --- a/webapp/pages/admin/users.vue +++ b/webapp/pages/admin/users.vue @@ -48,11 +48,6 @@ {{ scope.row.createdAt | dateTime }} - - - - - @@ -116,10 +111,6 @@ export default { label: this.$t('admin.users.table.columns.role'), align: 'right', }, - delete: { - label: '-', - align: 'right', - }, } }, }, @@ -164,17 +155,6 @@ export default { }, }, methods: { - openModal(userdata) { - console.log("openModal", userdata) - this.$store.commit('modal/SET_OPEN', { - name: 'delete', - data: { - id: 'sss', - type: 'dfdd', - name: {}, - }, - }) - }, back() { this.offset = Math.max(this.offset - this.pageSize, 0) }, @@ -194,10 +174,6 @@ export default { } } }, - deleteUser(userdata) { - console.log("deleteUser", userdata) - this.openModal(userdata) - }, }, } diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index 92073e724..bfff46ad7 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -23,6 +23,7 @@ @unmute="unmuteUser" @block="blockUser" @unblock="unblockUser" + @delete="deleteUser" /> @@ -436,6 +437,16 @@ export default { this.$apollo.queries.User.refetch() } }, + async deleteUser(userdata) { + this.$store.commit('modal/SET_OPEN', { + name: 'delete', + data: { + id: userdata.id, + slug: userdata.slug, + name: userdata.name, + }, + }) + }, pinPost(post) { this.$apollo .mutate({
{{ $t('settings.deleteUserAccount.accountDescription') }}
+ {{ $t('settings.deleteUserAccount.accountDescription') }} +
{{ $t('settings.deleteUserAccount.accountWarning') }}
{{ $t('settings.deleteUserAccount.accountWarningAdmin') }}