mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
feat: DeleteUser for Admin added in the profile dropdown menu, deleted from the Admin user overview
This commit is contained in:
parent
fdc0f492ad
commit
9ab2d8395f
@ -68,7 +68,11 @@ const isAuthor = rule({
|
|||||||
const isDeletingOwnAccount = rule({
|
const isDeletingOwnAccount = rule({
|
||||||
cache: 'no_cache',
|
cache: 'no_cache',
|
||||||
})(async (parent, args, context, info) => {
|
})(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({
|
const noEmailFilter = rule({
|
||||||
@ -133,7 +137,7 @@ export default shield(
|
|||||||
CreateComment: isAuthenticated,
|
CreateComment: isAuthenticated,
|
||||||
UpdateComment: isAuthor,
|
UpdateComment: isAuthor,
|
||||||
DeleteComment: isAuthor,
|
DeleteComment: isAuthor,
|
||||||
DeleteUser: isDeletingOwnAccount,
|
DeleteUser: or(isDeletingOwnAccount, isAdmin),
|
||||||
requestPasswordReset: allow,
|
requestPasswordReset: allow,
|
||||||
resetPassword: allow,
|
resetPassword: allow,
|
||||||
AddPostEmotions: isAuthenticated,
|
AddPostEmotions: isAuthenticated,
|
||||||
|
|||||||
@ -174,6 +174,7 @@ export default {
|
|||||||
},
|
},
|
||||||
DeleteUser: async (object, params, context, resolveInfo) => {
|
DeleteUser: async (object, params, context, resolveInfo) => {
|
||||||
const { resource } = params
|
const { resource } = params
|
||||||
|
const { id } = params
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
try {
|
try {
|
||||||
if (resource && resource.length) {
|
if (resource && resource.length) {
|
||||||
@ -190,7 +191,7 @@ export default {
|
|||||||
RETURN author
|
RETURN author
|
||||||
`,
|
`,
|
||||||
{
|
{
|
||||||
userId: context.user.id,
|
userId: id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -212,7 +213,7 @@ export default {
|
|||||||
DETACH DELETE socialMedia
|
DETACH DELETE socialMedia
|
||||||
RETURN user
|
RETURN user
|
||||||
`,
|
`,
|
||||||
{ userId: context.user.id },
|
{ userId: id },
|
||||||
)
|
)
|
||||||
log(deleteUserTransactionResponse)
|
log(deleteUserTransactionResponse)
|
||||||
return deleteUserTransactionResponse.records.map(record => record.get('user').properties)
|
return deleteUserTransactionResponse.records.map(record => record.get('user').properties)
|
||||||
|
|||||||
@ -154,6 +154,15 @@ export default {
|
|||||||
path: '/settings',
|
path: '/settings',
|
||||||
icon: 'edit',
|
icon: 'edit',
|
||||||
})
|
})
|
||||||
|
if (this.isAdmin === true) {
|
||||||
|
routes.push({
|
||||||
|
label: this.$t(`settings.deleteUserAccount.name`),
|
||||||
|
callback: () => {
|
||||||
|
this.$emit('delete', this.resource)
|
||||||
|
},
|
||||||
|
icon: 'trash',
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.resource.isMuted) {
|
if (this.resource.isMuted) {
|
||||||
routes.push({
|
routes.push({
|
||||||
@ -189,6 +198,15 @@ export default {
|
|||||||
icon: 'user-times',
|
icon: 'user-times',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (this.isAdmin === true) {
|
||||||
|
routes.push({
|
||||||
|
label: this.$t(`settings.deleteUserAccount.name`),
|
||||||
|
callback: () => {
|
||||||
|
this.$emit('delete', this.resource)
|
||||||
|
},
|
||||||
|
icon: 'trash',
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,12 +4,14 @@
|
|||||||
<base-icon name="warning" />
|
<base-icon name="warning" />
|
||||||
{{ $t('settings.deleteUserAccount.name') }}
|
{{ $t('settings.deleteUserAccount.name') }}
|
||||||
</h2>
|
</h2>
|
||||||
<label>
|
<label v-show="!isAdmin">
|
||||||
{{ $t('settings.deleteUserAccount.pleaseConfirm', { confirm: currentUser.name }) }}
|
{{ $t('settings.deleteUserAccount.pleaseConfirm', { confirm: currentUser.name }) }}
|
||||||
</label>
|
</label>
|
||||||
<ds-input v-model="enableDeletionValue" />
|
<ds-input v-show="!isAdmin" v-model="enableDeletionValue" />
|
||||||
<p class="notice">{{ $t('settings.deleteUserAccount.accountDescription') }}</p>
|
<p v-show="enableDeletionValue" class="notice">
|
||||||
<label v-if="currentUser.contributionsCount" class="checkbox">
|
{{ $t('settings.deleteUserAccount.accountDescription') }}
|
||||||
|
</p>
|
||||||
|
<label v-if="!isAdmin && currentUser.contributionsCount" class="checkbox">
|
||||||
<input type="checkbox" v-model="deleteContributions" />
|
<input type="checkbox" v-model="deleteContributions" />
|
||||||
{{
|
{{
|
||||||
$t('settings.deleteUserAccount.contributionsCount', {
|
$t('settings.deleteUserAccount.contributionsCount', {
|
||||||
@ -17,7 +19,7 @@
|
|||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
</label>
|
</label>
|
||||||
<label v-if="currentUser.commentedCount" class="checkbox">
|
<label v-if="!isAdmin && currentUser.commentedCount" class="checkbox">
|
||||||
<input type="checkbox" v-model="deleteComments" />
|
<input type="checkbox" v-model="deleteComments" />
|
||||||
{{
|
{{
|
||||||
$t('settings.deleteUserAccount.commentedCount', {
|
$t('settings.deleteUserAccount.commentedCount', {
|
||||||
@ -25,11 +27,18 @@
|
|||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
</label>
|
</label>
|
||||||
<section v-if="deleteEnabled" class="warning">
|
<h2 v-else>
|
||||||
<p>{{ $t('settings.deleteUserAccount.accountWarning') }}</p>
|
{{ $t('settings.deleteUserAccount.infoAdmin') }}
|
||||||
|
</h2>
|
||||||
|
<section class="warning">
|
||||||
|
<p v-if="!isAdmin">{{ $t('settings.deleteUserAccount.accountWarning') }}</p>
|
||||||
|
<p v-else>{{ $t('settings.deleteUserAccount.accountWarningAdmin') }}</p>
|
||||||
</section>
|
</section>
|
||||||
<ds-text v-show="isAdmin || currentUser.role === 'admin'" color="danger">ACHTUNG! Du Bist Admin!!</ds-text>
|
<ds-text v-show="isAdmin || currentUser.role === 'admin'" color="danger">
|
||||||
|
{{ $t('settings.deleteUserAccount.accountWarningIsAdmin') }}
|
||||||
|
</ds-text>
|
||||||
<base-button
|
<base-button
|
||||||
|
v-show="!isAdmin"
|
||||||
icon="trash"
|
icon="trash"
|
||||||
danger
|
danger
|
||||||
filled
|
filled
|
||||||
@ -56,23 +65,12 @@ export default {
|
|||||||
isAdmin: this.$store.getters['auth/isAdmin'],
|
isAdmin: this.$store.getters['auth/isAdmin'],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
|
||||||
if (this.isAdmin === true) {
|
|
||||||
this.deleteContributions = true,
|
|
||||||
this.deleteComments = true
|
|
||||||
}
|
|
||||||
// console.log('isAdmin', isAdmin)
|
|
||||||
// console.log('this.deleteContributions', this.deleteContributions)
|
|
||||||
// console.log(' this.deleteComments', this.deleteComments)
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
currentUser: 'auth/user',
|
currentUser: 'auth/user',
|
||||||
}),
|
}),
|
||||||
deleteEnabled() {
|
deleteEnabled() {
|
||||||
if (this.isAdmin === true) {
|
|
||||||
return this.enableDeletionValue === this.currentUser.name
|
return this.enableDeletionValue === this.currentUser.name
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@ -4,9 +4,9 @@
|
|||||||
<!-- <p v-html="message" /> -->
|
<!-- <p v-html="message" /> -->
|
||||||
<delete-data />
|
<delete-data />
|
||||||
<template slot="footer">
|
<template slot="footer">
|
||||||
<base-button class="cancel" @click="cancel">löschen abbrechen</base-button>
|
<base-button class="cancel" @click="cancel">{{ $t('actions.cancel') }}</base-button>
|
||||||
<base-button danger filled class="confirm" icon="exclamation-circle" @click="confirm">
|
<base-button danger filled class="confirm" icon="exclamation-circle" @click="confirm">
|
||||||
User jetzt Löschen!
|
{{ $t('settings.deleteUserAccount.name') }}
|
||||||
</base-button>
|
</base-button>
|
||||||
</template>
|
</template>
|
||||||
</ds-modal>
|
</ds-modal>
|
||||||
@ -21,26 +21,21 @@ export default {
|
|||||||
DeleteData,
|
DeleteData,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
name: { type: String, default: 'jetzt löschen' },
|
slug: { type: String, required: true },
|
||||||
type: { type: String, required: true },
|
|
||||||
id: { type: String, required: true },
|
id: { type: String, required: true },
|
||||||
|
name: { type: String, required: true },
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
success: false,
|
success: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
isAdmin: this.$store.getters['auth/isAdmin'],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
title() {
|
title() {
|
||||||
return 'User Löschen'
|
return this.$props.name + ' (' + this.$props.slug + ')'
|
||||||
// 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 })
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -56,50 +51,25 @@ export default {
|
|||||||
try {
|
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 !!!
|
// 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.modalData.buttons.confirm.callback()
|
||||||
await this.$apollo.mutate({
|
this.$apollo
|
||||||
/* mutation: gql`
|
.mutate({
|
||||||
mutation($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
|
mutation: gql`
|
||||||
review(resourceId: $resourceId, disable: $disable, closed: $closed) {
|
mutation($id: ID!, $resource: [Deletable]) {
|
||||||
disable
|
DeleteUser(id: $id, resource: $resource) {
|
||||||
}
|
|
||||||
}
|
|
||||||
`, */
|
|
||||||
mutation: gql`
|
|
||||||
mutation {
|
|
||||||
DeleteUser(id: "u3", resource: [Post, Comment]) {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
slug
|
|
||||||
about
|
|
||||||
deleted
|
|
||||||
contributions {
|
|
||||||
id
|
id
|
||||||
content
|
|
||||||
contentExcerpt
|
|
||||||
deleted
|
|
||||||
comments {
|
|
||||||
id
|
|
||||||
content
|
|
||||||
contentExcerpt
|
|
||||||
deleted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
comments {
|
|
||||||
id
|
|
||||||
content
|
|
||||||
contentExcerpt
|
|
||||||
deleted
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
`,
|
||||||
`,
|
variables: { id: this.$props.id, resource: ['Post', 'Comment'] },
|
||||||
variables: { resourceId: this.id, disable: false, closed: false },
|
})
|
||||||
})
|
.then(() => {
|
||||||
this.$toast.success('user gelöscht')
|
this.$toast.success(this.$t('settings.deleteUserAccount.success'))
|
||||||
|
this.$router.history.push('/')
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
this.$toast.error(error.message)
|
||||||
|
})
|
||||||
this.isOpen = false
|
this.isOpen = false
|
||||||
setTimeout(() => {
|
|
||||||
this.$emit('close')
|
|
||||||
}, 1000)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.$toast.error(err.message)
|
this.$toast.error(err.message)
|
||||||
this.isOpen = false
|
this.isOpen = false
|
||||||
|
|||||||
@ -30,11 +30,11 @@
|
|||||||
:modalData="data.modalData"
|
:modalData="data.modalData"
|
||||||
@close="close"
|
@close="close"
|
||||||
/>
|
/>
|
||||||
<delete-modal
|
<delete-user-modal
|
||||||
v-if="open === 'delete'"
|
v-if="open === 'delete'"
|
||||||
:id="data.resource.id"
|
:id="data.id"
|
||||||
:type="data.type"
|
:slug="data.slug"
|
||||||
:name="name"
|
:name="data.name"
|
||||||
@close="close"
|
@close="close"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -45,7 +45,7 @@ import ConfirmModal from '~/components/Modal/ConfirmModal'
|
|||||||
import DisableModal from '~/components/Modal/DisableModal'
|
import DisableModal from '~/components/Modal/DisableModal'
|
||||||
import ReleaseModal from '~/components/ReleaseModal/ReleaseModal.vue'
|
import ReleaseModal from '~/components/ReleaseModal/ReleaseModal.vue'
|
||||||
import ReportModal from '~/components/Modal/ReportModal'
|
import ReportModal from '~/components/Modal/ReportModal'
|
||||||
import DeleteModal from '~/components/DeleteUserModal/DeleteUserModal.vue'
|
import DeleteUserModal from '~/components/DeleteUserModal/DeleteUserModal.vue'
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -55,7 +55,7 @@ export default {
|
|||||||
ReleaseModal,
|
ReleaseModal,
|
||||||
ReportModal,
|
ReportModal,
|
||||||
ConfirmModal,
|
ConfirmModal,
|
||||||
DeleteModal,
|
DeleteUserModal,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
|
|||||||
@ -639,9 +639,12 @@
|
|||||||
"deleteUserAccount": {
|
"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.",
|
"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!",
|
"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",
|
"commentedCount": "Meine {count} Kommentare löschen",
|
||||||
"contributionsCount": "Meine {count} Beiträge 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.",
|
"pleaseConfirm": "Zerstörerische Aktion! Gib „{confirm}“ ein, um zu bestätigen.",
|
||||||
"success": "Konto erfolgreich gelöscht!"
|
"success": "Konto erfolgreich gelöscht!"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -639,8 +639,11 @@
|
|||||||
"deleteUserAccount": {
|
"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.",
|
"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!",
|
"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",
|
"commentedCount": "Delete my {count} comments",
|
||||||
"contributionsCount": "Delete my {count} posts",
|
"contributionsCount": "Delete my {count} posts",
|
||||||
|
"infoAdmin": "All contributions and comments of the user are additionally deleted!",
|
||||||
"name": "Delete user account",
|
"name": "Delete user account",
|
||||||
"pleaseConfirm": "Destructive action! Type “{confirm}” to confirm.",
|
"pleaseConfirm": "Destructive action! Type “{confirm}” to confirm.",
|
||||||
"success": "Account successfully deleted!"
|
"success": "Account successfully deleted!"
|
||||||
|
|||||||
@ -48,11 +48,6 @@
|
|||||||
<template slot="createdAt" slot-scope="scope">
|
<template slot="createdAt" slot-scope="scope">
|
||||||
{{ scope.row.createdAt | dateTime }}
|
{{ scope.row.createdAt | dateTime }}
|
||||||
</template>
|
</template>
|
||||||
<template slot="delete" slot-scope="scope">
|
|
||||||
<div @click="deleteUser({ id: scope.row.id, slug: scope.row.slug })">
|
|
||||||
<ds-icon name="trash"></ds-icon>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</ds-table>
|
</ds-table>
|
||||||
<pagination-buttons :hasNext="hasNext" :hasPrevious="hasPrevious" @next="next" @back="back" />
|
<pagination-buttons :hasNext="hasNext" :hasPrevious="hasPrevious" @next="next" @back="back" />
|
||||||
</base-card>
|
</base-card>
|
||||||
@ -116,10 +111,6 @@ export default {
|
|||||||
label: this.$t('admin.users.table.columns.role'),
|
label: this.$t('admin.users.table.columns.role'),
|
||||||
align: 'right',
|
align: 'right',
|
||||||
},
|
},
|
||||||
delete: {
|
|
||||||
label: '-',
|
|
||||||
align: 'right',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -164,17 +155,6 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
openModal(userdata) {
|
|
||||||
console.log("openModal", userdata)
|
|
||||||
this.$store.commit('modal/SET_OPEN', {
|
|
||||||
name: 'delete',
|
|
||||||
data: {
|
|
||||||
id: 'sss',
|
|
||||||
type: 'dfdd',
|
|
||||||
name: {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
back() {
|
back() {
|
||||||
this.offset = Math.max(this.offset - this.pageSize, 0)
|
this.offset = Math.max(this.offset - this.pageSize, 0)
|
||||||
},
|
},
|
||||||
@ -194,10 +174,6 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteUser(userdata) {
|
|
||||||
console.log("deleteUser", userdata)
|
|
||||||
this.openModal(userdata)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
@unmute="unmuteUser"
|
@unmute="unmuteUser"
|
||||||
@block="blockUser"
|
@block="blockUser"
|
||||||
@unblock="unblockUser"
|
@unblock="unblockUser"
|
||||||
|
@delete="deleteUser"
|
||||||
/>
|
/>
|
||||||
</client-only>
|
</client-only>
|
||||||
<ds-space margin="small">
|
<ds-space margin="small">
|
||||||
@ -436,6 +437,16 @@ export default {
|
|||||||
this.$apollo.queries.User.refetch()
|
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) {
|
pinPost(post) {
|
||||||
this.$apollo
|
this.$apollo
|
||||||
.mutate({
|
.mutate({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user