pleroma-fe/src/components/moderation_tools/moderation_tools.js

150 lines
4.1 KiB
JavaScript
Raw Normal View History

2019-02-18 17:49:32 +03:00
import DialogModal from '../dialog_modal/dialog_modal.vue'
2020-02-28 16:39:47 +00:00
import Popover from '../popover/popover.vue'
2019-02-18 17:49:32 +03:00
2026-01-29 20:40:00 +02:00
import { useInstanceStore } from 'src/stores/instance.js'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faChevronDown } from '@fortawesome/free-solid-svg-icons'
library.add(faChevronDown)
2019-02-18 17:49:32 +03:00
const FORCE_NSFW = 'mrf_tag:media-force-nsfw'
const STRIP_MEDIA = 'mrf_tag:media-strip'
const FORCE_UNLISTED = 'mrf_tag:force-unlisted'
const DISABLE_REMOTE_SUBSCRIPTION = 'mrf_tag:disable-remote-subscription'
const DISABLE_ANY_SUBSCRIPTION = 'mrf_tag:disable-any-subscription'
const SANDBOX = 'mrf_tag:sandbox'
const QUARANTINE = 'mrf_tag:quarantine'
const ModerationTools = {
2026-01-06 16:22:52 +02:00
props: ['user'],
data() {
2019-02-18 17:49:32 +03:00
return {
tags: {
FORCE_NSFW,
STRIP_MEDIA,
FORCE_UNLISTED,
DISABLE_REMOTE_SUBSCRIPTION,
DISABLE_ANY_SUBSCRIPTION,
SANDBOX,
2026-01-06 16:22:52 +02:00
QUARANTINE,
2019-02-18 17:49:32 +03:00
},
2020-02-28 16:39:47 +00:00
showDeleteUserDialog: false,
2026-01-06 16:22:52 +02:00
toggled: false,
2019-02-18 17:49:32 +03:00
}
},
components: {
2020-02-28 16:39:47 +00:00
DialogModal,
2026-01-06 16:22:52 +02:00
Popover,
2019-02-18 17:49:32 +03:00
},
computed: {
2026-01-06 16:22:52 +02:00
tagsSet() {
2019-02-18 17:49:32 +03:00
return new Set(this.user.tags)
},
2026-01-06 16:22:52 +02:00
canGrantRole() {
return (
this.user.is_local &&
!this.user.deactivated &&
this.$store.state.users.currentUser.role === 'admin'
)
},
2026-01-06 16:22:52 +02:00
canChangeActivationState() {
return this.privileged('users_manage_activation_state')
},
2026-01-06 16:22:52 +02:00
canDeleteAccount() {
return this.privileged('users_delete')
},
2026-01-06 16:22:52 +02:00
canUseTagPolicy() {
return (
2026-01-29 20:33:59 +02:00
useInstanceStore().featureSet.tagPolicyAvailable &&
2026-01-06 16:22:52 +02:00
this.privileged('users_manage_tags')
)
},
2019-02-18 17:49:32 +03:00
},
methods: {
2026-01-06 16:22:52 +02:00
hasTag(tagName) {
2019-02-18 17:49:32 +03:00
return this.tagsSet.has(tagName)
},
2026-01-06 16:22:52 +02:00
privileged(privilege) {
return this.$store.state.users.currentUser.privileges.includes(privilege)
},
2026-01-06 16:22:52 +02:00
toggleTag(tag) {
2019-02-18 17:49:32 +03:00
const store = this.$store
if (this.tagsSet.has(tag)) {
2026-01-06 16:22:52 +02:00
store.state.api.backendInteractor
.untagUser({ user: this.user, tag })
.then((response) => {
if (!response.ok) {
return
}
store.commit('untagUser', { user: this.user, tag })
})
2019-02-18 17:49:32 +03:00
} else {
2026-01-06 16:22:52 +02:00
store.state.api.backendInteractor
.tagUser({ user: this.user, tag })
.then((response) => {
if (!response.ok) {
return
}
store.commit('tagUser', { user: this.user, tag })
})
2019-02-18 17:49:32 +03:00
}
},
2026-01-06 16:22:52 +02:00
toggleRight(right) {
2019-02-18 17:49:32 +03:00
const store = this.$store
if (this.user.rights[right]) {
2026-01-06 16:22:52 +02:00
store.state.api.backendInteractor
.deleteRight({ user: this.user, right })
.then((response) => {
if (!response.ok) {
return
}
store.commit('updateRight', {
user: this.user,
right,
value: false,
})
})
2019-02-18 17:49:32 +03:00
} else {
2026-01-06 16:22:52 +02:00
store.state.api.backendInteractor
.addRight({ user: this.user, right })
.then((response) => {
if (!response.ok) {
return
}
store.commit('updateRight', { user: this.user, right, value: true })
})
2019-02-18 17:49:32 +03:00
}
},
2026-01-06 16:22:52 +02:00
toggleActivationStatus() {
this.$store.dispatch('toggleActivationStatus', { user: this.user })
2019-02-18 17:49:32 +03:00
},
2026-01-06 16:22:52 +02:00
deleteUserDialog(show) {
2019-02-18 17:49:32 +03:00
this.showDeleteUserDialog = show
},
2026-01-06 16:22:52 +02:00
deleteUser() {
2019-02-18 17:49:32 +03:00
const store = this.$store
const user = this.user
2019-07-05 10:02:14 +03:00
const { id, name } = user
2026-01-06 16:22:52 +02:00
store.state.api.backendInteractor.deleteUser({ user }).then(() => {
this.$store.dispatch(
'markStatusesAsDeleted',
(status) => user.id === status.user.id,
)
const isProfile =
this.$route.name === 'external-user-profile' ||
this.$route.name === 'user-profile'
const isTargetUser =
this.$route.params.name === name || this.$route.params.id === id
if (isProfile && isTargetUser) {
window.history.back()
}
})
2020-02-28 16:39:47 +00:00
},
2026-01-06 16:22:52 +02:00
setToggled(value) {
2020-02-28 16:39:47 +00:00
this.toggled = value
2026-01-06 16:22:52 +02:00
},
},
2019-02-18 17:49:32 +03:00
}
export default ModerationTools