Skip to content

Commit

Permalink
Merge branch '17-Admin-Remove-user-profile' of https://github.com/Hum…
Browse files Browse the repository at this point in the history
…an-Connection/Human-Connection into 17-Admin-Remove-user-profile
  • Loading branch information
ogerly committed Jul 31, 2020
2 parents 1ce43af + c517c0f commit d2e6280
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 7 deletions.
5 changes: 0 additions & 5 deletions backend/src/schema/types/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ type Mutation {
unfollowUser(id: ID!): User
}

enum Deletable {
Post
Comment
}

enum ShoutTypeEnum {
Post
}
Expand Down
5 changes: 5 additions & 0 deletions backend/src/schema/types/type/User.gql
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ type Query {
)
}

enum Deletable {
Post
Comment
}

type Mutation {
UpdateUser (
id: ID!
Expand Down
18 changes: 18 additions & 0 deletions webapp/components/ContentMenu/ContentMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,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({
Expand Down Expand Up @@ -191,6 +200,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',
})
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions webapp/components/DeleteData/DeleteData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
{{ $t('settings.deleteUserAccount.pleaseConfirm', { confirm: currentUser.name }) }}
</label>
<ds-input v-model="enableDeletionValue" />
<p class="notice">{{ $t('settings.deleteUserAccount.accountDescription') }}</p>
<p v-show="enableDeletionValue" class="notice">
{{ $t('settings.deleteUserAccount.accountDescription') }}
</p>
<label v-if="currentUser.contributionsCount" class="checkbox">
<input type="checkbox" v-model="deleteContributions" />
{{
Expand All @@ -25,7 +27,7 @@
})
}}
</label>
<section v-if="deleteEnabled" class="warning">
<section class="warning">
<p>{{ $t('settings.deleteUserAccount.accountWarning') }}</p>
</section>
<base-button
Expand Down
3 changes: 3 additions & 0 deletions webapp/components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
:modalData="data.modalData"
@close="close"
/>
<delete-user-modal v-if="open === 'delete'" :userdata="data.userdata" @close="close" />
</div>
</template>

Expand All @@ -38,6 +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/Modal/DeleteUserModal.vue'
import { mapGetters } from 'vuex'
export default {
Expand All @@ -47,6 +49,7 @@ export default {
ReleaseModal,
ReportModal,
ConfirmModal,
DeleteUserModal,
},
computed: {
...mapGetters({
Expand Down
178 changes: 178 additions & 0 deletions webapp/components/Modal/DeleteUserModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<template>
<ds-modal :title="title" :is-open="isOpen" @cancel="cancel">
<transition name="ds-transition-fade">
<ds-flex v-if="success" class="hc-modal-success" centered>
<sweetalert-icon icon="success" />
</ds-flex>
</transition>
<div>
<ds-section>
<ds-flex>
<ds-flex-item>
<user-teaser :user="userdata" />
</ds-flex-item>
<ds-flex-item>
<ds-text size="small">
{{ $t('modals.deleteUser.created') }}:
<br />
<relative-date-time :date-time="userdata.createdAt" />
</ds-text>
</ds-flex-item>
<ds-flex-item>
<ds-number
size="small"
:count="userdata.contributionsCount"
:label="$t('common.post', null, userdata.contributionsCount)"
/>
</ds-flex-item>
<ds-flex-item>
<ds-number
size="small"
:count="userdata.commentedCount"
:label="$t('common.comment', null, userdata.commentedCount)"
/>
</ds-flex-item>
</ds-flex>
</ds-section>
</div>

<template slot="footer">
<base-button class="cancel" @click="cancel">{{ $t('actions.cancel') }}</base-button>
<base-button danger filled class="confirm" icon="exclamation-circle" @click="openModal">
{{ $t('settings.deleteUserAccount.name') }}
</base-button>
</template>
</ds-modal>
</template>

<script>
import gql from 'graphql-tag'
import { mapMutations } from 'vuex'
import { SweetalertIcon } from 'vue-sweetalert-icons'
import RelativeDateTime from '~/components/RelativeDateTime'
import UserTeaser from '~/components/UserTeaser/UserTeaser'
export default {
name: 'DeleteUserModal',
components: {
UserTeaser,
SweetalertIcon,
RelativeDateTime,
},
props: {
userdata: { type: Object, required: true },
},
data() {
return {
isOpen: true,
success: false,
loading: false,
isAdmin: this.$store.getters['auth/isAdmin'],
}
},
computed: {
title() {
return this.$t('settings.deleteUserAccount.name')
},
modalData(userdata) {
return function (userdata) {
return {
name: 'confirm',
data: {
type: userdata.name,
resource: userdata,
modalData: {
titleIdent: this.$t('settings.deleteUserAccount.accountWarningIsAdmin'),
messageIdent: this.$t('settings.deleteUserAccount.infoAdmin'),
messageParams: {},
buttons: {
confirm: {
danger: true,
icon: 'trash',
textIdent: this.$t('settings.deleteUserAccount.confirmDeleting'),
callback: () => {
this.confirm(userdata)
},
},
cancel: {
icon: 'close',
textIdent: this.$t('actions.cancel'),
callback: () => {},
},
},
},
},
}
}
},
},
methods: {
...mapMutations({
commitModalData: 'modal/SET_OPEN',
}),
openModal() {
this.commitModalData(this.modalData(this.userdata))
},
cancel() {
// 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.cancel.callback()
this.isOpen = false
setTimeout(() => {
this.$emit('close')
}, 1000)
},
async confirm() {
this.$apollo
.mutate({
mutation: gql`
mutation($id: ID!, $resource: [Deletable]) {
DeleteUser(id: $id, resource: $resource) {
id
}
}
`,
variables: { id: this.userdata.id, resource: ['Post', 'Comment'] },
})
.then(({ _data }) => {
this.success = true
this.$toast.success(this.$t('settings.deleteUserAccount.success'))
setTimeout(() => {
this.isOpen = false
setTimeout(() => {
this.success = false
this.$emit('close')
this.$router.history.replace('/')
}, 500)
}, 1500)
this.loading = false
})
.catch((err) => {
this.$emit('close')
this.success = false
this.$toast.error(err.message)
this.isOpen = false
this.loading = false
})
},
},
}
</script>

<style lang="scss">
.ds-modal {
max-width: 600px !important;
}
.hc-modal-success {
pointer-events: none;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #fff;
opacity: 1;
z-index: $z-index-modal;
border-radius: $border-radius-x-large;
}
</style>
9 changes: 9 additions & 0 deletions webapp/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@
"questions": "Bei Fragen oder Problemen erreichst Du uns per E-Mail an",
"title": "Human Connection befindet sich in der Wartung"
},
"modals": {
"deleteUser": {
"created": "Erstellt"
}
},
"moderation": {
"name": "Moderation",
"reports": {
Expand Down Expand Up @@ -632,8 +637,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 löschst jetzt ein Benutzerkonto!",
"commentedCount": "Meine {count} Kommentare löschen",
"confirmDeleting": "Benutzerkonto jetzt löschen",
"contributionsCount": "Meine {count} Beiträge 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!"
Expand Down
9 changes: 9 additions & 0 deletions webapp/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@
"questions": "Any Questions or concerns, send an e-mail to",
"title": "Human Connection is under maintenance"
},
"modals": {
"deleteUser": {
"created": "Created"
}
},
"moderation": {
"name": "Moderation",
"reports": {
Expand Down Expand Up @@ -632,8 +637,12 @@
"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 about to delete a user account!",
"commentedCount": "Delete my {count} comments",
"confirmDeleting": "Delete user account now",
"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!"
Expand Down
9 changes: 9 additions & 0 deletions webapp/pages/profile/_id/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@unmute="unmuteUser"
@block="blockUser"
@unblock="unblockUser"
@delete="deleteUser"
/>
</client-only>
<ds-space margin="small">
Expand Down Expand Up @@ -385,6 +386,14 @@ export default {
this.$apollo.queries.User.refetch()
}
},
async deleteUser(userdata) {
this.$store.commit('modal/SET_OPEN', {
name: 'delete',
data: {
userdata: userdata,
},
})
},
pinPost(post) {
this.$apollo
.mutate({
Expand Down

0 comments on commit d2e6280

Please sign in to comment.