logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

moderation_tools.js (3740B)


  1. import { library } from '@fortawesome/fontawesome-svg-core'
  2. import { faChevronDown } from '@fortawesome/free-solid-svg-icons'
  3. import DialogModal from '../dialog_modal/dialog_modal.vue'
  4. import Popover from '../popover/popover.vue'
  5. library.add(faChevronDown)
  6. const FORCE_NSFW = 'mrf_tag:media-force-nsfw'
  7. const STRIP_MEDIA = 'mrf_tag:media-strip'
  8. const FORCE_UNLISTED = 'mrf_tag:force-unlisted'
  9. const DISABLE_REMOTE_SUBSCRIPTION = 'mrf_tag:disable-remote-subscription'
  10. const DISABLE_ANY_SUBSCRIPTION = 'mrf_tag:disable-any-subscription'
  11. const SANDBOX = 'mrf_tag:sandbox'
  12. const QUARANTINE = 'mrf_tag:quarantine'
  13. const ModerationTools = {
  14. props: [
  15. 'user'
  16. ],
  17. data () {
  18. return {
  19. tags: {
  20. FORCE_NSFW,
  21. STRIP_MEDIA,
  22. FORCE_UNLISTED,
  23. DISABLE_REMOTE_SUBSCRIPTION,
  24. DISABLE_ANY_SUBSCRIPTION,
  25. SANDBOX,
  26. QUARANTINE
  27. },
  28. showDeleteUserDialog: false,
  29. toggled: false
  30. }
  31. },
  32. components: {
  33. DialogModal,
  34. Popover
  35. },
  36. computed: {
  37. tagsSet () {
  38. return new Set(this.user.tags)
  39. },
  40. canGrantRole () {
  41. return this.user.is_local && !this.user.deactivated && this.$store.state.users.currentUser.role === 'admin'
  42. },
  43. canChangeActivationState () {
  44. return this.privileged('users_manage_activation_state')
  45. },
  46. canDeleteAccount () {
  47. return this.privileged('users_delete')
  48. },
  49. canUseTagPolicy () {
  50. return this.$store.state.instance.tagPolicyAvailable && this.privileged('users_manage_tags')
  51. }
  52. },
  53. methods: {
  54. hasTag (tagName) {
  55. return this.tagsSet.has(tagName)
  56. },
  57. privileged (privilege) {
  58. return this.$store.state.users.currentUser.privileges.includes(privilege)
  59. },
  60. toggleTag (tag) {
  61. const store = this.$store
  62. if (this.tagsSet.has(tag)) {
  63. store.state.api.backendInteractor.untagUser({ user: this.user, tag }).then(response => {
  64. if (!response.ok) { return }
  65. store.commit('untagUser', { user: this.user, tag })
  66. })
  67. } else {
  68. store.state.api.backendInteractor.tagUser({ user: this.user, tag }).then(response => {
  69. if (!response.ok) { return }
  70. store.commit('tagUser', { user: this.user, tag })
  71. })
  72. }
  73. },
  74. toggleRight (right) {
  75. const store = this.$store
  76. if (this.user.rights[right]) {
  77. store.state.api.backendInteractor.deleteRight({ user: this.user, right }).then(response => {
  78. if (!response.ok) { return }
  79. store.commit('updateRight', { user: this.user, right, value: false })
  80. })
  81. } else {
  82. store.state.api.backendInteractor.addRight({ user: this.user, right }).then(response => {
  83. if (!response.ok) { return }
  84. store.commit('updateRight', { user: this.user, right, value: true })
  85. })
  86. }
  87. },
  88. toggleActivationStatus () {
  89. this.$store.dispatch('toggleActivationStatus', { user: this.user })
  90. },
  91. deleteUserDialog (show) {
  92. this.showDeleteUserDialog = show
  93. },
  94. deleteUser () {
  95. const store = this.$store
  96. const user = this.user
  97. const { id, name } = user
  98. store.state.api.backendInteractor.deleteUser({ user })
  99. .then(e => {
  100. this.$store.dispatch('markStatusesAsDeleted', status => user.id === status.user.id)
  101. const isProfile = this.$route.name === 'external-user-profile' || this.$route.name === 'user-profile'
  102. const isTargetUser = this.$route.params.name === name || this.$route.params.id === id
  103. if (isProfile && isTargetUser) {
  104. window.history.back()
  105. }
  106. })
  107. },
  108. setToggled (value) {
  109. this.toggled = value
  110. }
  111. }
  112. }
  113. export default ModerationTools