bug: deleteUser on old status, currentUserCounts are retrieved additionally, admin cannot delete himself via his user settings

This commit is contained in:
ogerly 2020-04-29 10:04:54 +02:00
parent 9aacb22a58
commit 7e5a7f5d42
5 changed files with 50 additions and 16 deletions

View File

@ -45,7 +45,7 @@ describe('DeleteData.vue', () => {
}
getters = {
'auth/user': () => {
return { id: 'u343', name: deleteAccountName, contributionsCount: 2, commentedCount: 3 }
return { id: 'u343', name: deleteAccountName }
},
}
actions = { 'auth/logout': jest.fn() }

View File

@ -1,5 +1,5 @@
<template>
<base-card class="delete-data">
<base-card v-if="currentUser.role !== 'admin'" class="delete-data">
<h2 class="title">
<base-icon name="warning" />
{{ $t('settings.deleteUserAccount.name') }}
@ -9,23 +9,31 @@
</label>
<ds-input v-model="enableDeletionValue" />
<p class="notice">{{ $t('settings.deleteUserAccount.accountDescription') }}</p>
<label v-if="currentUser.contributionsCount" class="checkbox">
<label class="checkbox">
<input type="checkbox" v-model="deleteContributions" />
{{
$t('settings.deleteUserAccount.contributionsCount', {
count: currentUser.contributionsCount,
})
$t(
'settings.deleteUserAccount.contributionsCount',
{
count: currentUserCount.contributionsCount,
},
currentUserCount.contributionsCount,
)
}}
</label>
<label v-if="currentUser.commentedCount" class="checkbox">
<label class="checkbox">
<input type="checkbox" v-model="deleteComments" />
{{
$t('settings.deleteUserAccount.commentedCount', {
count: currentUser.commentedCount,
})
$t(
'settings.deleteUserAccount.commentedCount',
{
count: currentUserCount.commentedCount,
},
currentUserCount.commentedCount,
)
}}
</label>
<section v-if="deleteEnabled" class="warning">
<section class="warning">
<p>{{ $t('settings.deleteUserAccount.accountWarning') }}</p>
</section>
<base-button
@ -39,11 +47,15 @@
{{ $t('settings.deleteUserAccount.name') }}
</base-button>
</base-card>
<base-card v-else class="delete-data">
:) {{ $t('settings.deleteUserAccount.adminInfo') }}
</base-card>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
import { mapActions, mapGetters } from 'vuex'
import gql from 'graphql-tag'
import { currentUserCountQuery } from '~/graphql/User'
export default {
name: 'DeleteData',
@ -52,8 +64,19 @@ export default {
deleteContributions: false,
deleteComments: false,
enableDeletionValue: null,
currentUserCount: [],
}
},
apollo: {
currentUser: {
query() {
return currentUserCountQuery()
},
update(currentUser) {
this.currentUserCount = currentUser.currentUser
},
},
},
computed: {
...mapGetters({
currentUser: 'auth/user',

View File

@ -283,3 +283,12 @@ export const currentUserQuery = gql`
}
}
`
export const currentUserCountQuery = () => gql`
${userCountsFragment}
query {
currentUser {
...userCounts
}
}
`

View File

@ -630,10 +630,11 @@
"success": "Deine Daten wurden erfolgreich aktualisiert!"
},
"deleteUserAccount": {
"adminInfo": "Der Kapitän verlässt immer als letzter das Schiff! Du bist Admin dieses Netzwerkes, du kannst dich auf diese weise nicht löschen! ;) ",
"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!",
"commentedCount": "Meine {count} Kommentare löschen",
"contributionsCount": "Meine {count} Beiträge löschen",
"commentedCount": "Meinen {count} Kommentar löschen ::: Meine {count} Kommentare löschen",
"contributionsCount": "Meinen {count} Beitrag löschen ::: Meine {count} Beiträge löschen",
"name": "Benutzerkonto löschen",
"pleaseConfirm": "Zerstörerische Aktion! Gib „{confirm}“ ein, um zu bestätigen.",
"success": "Konto erfolgreich gelöscht!"

View File

@ -630,10 +630,11 @@
"success": "Your data was successfully updated!"
},
"deleteUserAccount": {
"adminInfo": "The captain is always the last to leave the ship! You are admin of this network, you cannot delete yourself this way! ;) ",
"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!",
"commentedCount": "Delete my {count} comments",
"contributionsCount": "Delete my {count} posts",
"commentedCount": "Delete my {count} comment ::: Delete my {count} comments",
"contributionsCount": "Delete my {count} post ::: Delete my {count} posts",
"name": "Delete user account",
"pleaseConfirm": "Destructive action! Type “{confirm}” to confirm.",
"success": "Account successfully deleted!"