AdminModerationBannedUsers.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class='admin_moderation'>
  3. <div class='admin_moderation__tabs'>
  4. <div class='tab_button' @click='$router.push("reports")'>Reports</div>
  5. <div class='tab_button tab_button--selected'>Banned users</div>
  6. </div>
  7. <div class='admin_moderation__header'>
  8. <div>
  9. Remove or edit banned users below, or add a new ban
  10. </div>
  11. <button class='button button--blue' @click='toggleShowAddNewBanModal'>Add new ban</button>
  12. </div>
  13. <table class='admin_moderation__table'>
  14. <tr>
  15. <th>User</th>
  16. <th>Ban type</th>
  17. <th>Date banned</th>
  18. <th>Message</th>
  19. </tr>
  20. <tr v-for='ban in bans'>
  21. <td>{{ban.User.username}}</td>
  22. <td>{{ban.type}}</td>
  23. <td>{{ban.createdAt | formatDate}}</td>
  24. <td>
  25. <template v-if='ban.message'>{{ban.message}}</template>
  26. <i v-else>No message given</i>
  27. </td>
  28. </tr>
  29. </table>
  30. <modal-window v-model='showAddNewBanModal' width='30rem'>
  31. <div class='admin_moderation__add_new_ban_modal'>
  32. <h2>Ban or block a user</h2>
  33. <p>Search for the user to ban, then select the relevant ban type for the user</p>
  34. <div>
  35. <fancy-input placeholder='Username to ban' v-model='username' width='15rem' :large='true'></fancy-input>
  36. </div>
  37. <div>
  38. <fancy-input placeholder='Message to user (optional)' v-model='message' width='15rem' :large='true'></fancy-input>
  39. </div>
  40. <div>
  41. <select-button
  42. :options='options'
  43. name='test'
  44. v-model='selectedOption'
  45. >
  46. </select-button>
  47. </div>
  48. <div>
  49. <button class='button button--modal' @click='toggleShowAddNewBanModal'>Cancel</button>
  50. <button class='button button--modal button--green' @click='addBan'>Add ban</button>
  51. </div>
  52. </div>
  53. </modal-window>
  54. </div>
  55. </template>
  56. <script>
  57. import TabView from '../TabView'
  58. import ModalWindow from '../ModalWindow'
  59. import FancyInput from '../FancyInput'
  60. import SelectButton from '../SelectButton'
  61. import MenuButton from '../MenuButton'
  62. import AvatarIcon from '../AvatarIcon'
  63. import ConfirmModal from '../ConfirmModal'
  64. import AjaxErrorHandler from '../../assets/js/errorHandler'
  65. export default {
  66. name: 'AdminDashboard',
  67. components: {
  68. TabView,
  69. ModalWindow,
  70. FancyInput,
  71. SelectButton,
  72. MenuButton,
  73. AvatarIcon,
  74. ConfirmModal
  75. },
  76. data () {
  77. return {
  78. showAddNewBanModal: false,
  79. username: '',
  80. message: '',
  81. options: [
  82. { name: "Select a ban type", disabled: true },
  83. { name: "Block user's known ip addresses", value: "ip" },
  84. { name: "Ban from creating new threads", value: "thread"},
  85. { name: "Ban from replying to threads", value: "post"},
  86. { name: "Ban from creating threads and posting", value: "both"}
  87. ],
  88. selectedOption: 0,
  89. bans_: []
  90. }
  91. },
  92. computed: {
  93. bans () {
  94. return this.bans_.map(ban => {
  95. if(ban.ipBlock) {
  96. ban.type = 'IP block'
  97. } else if (ban.canCreateThreads && !ban.canCreatePosts) {
  98. ban.type = 'Posting replies'
  99. } else if(ban.canCreatePosts && !ban.canCreateThreads) {
  100. ban.type = 'Creating threads'
  101. } else {
  102. ban.type = 'Posting replies and creating threads'
  103. }
  104. return ban
  105. })
  106. }
  107. },
  108. methods: {
  109. toggleShowAddNewBanModal () {
  110. this.showAddNewBanModal = !this.showAddNewBanModal
  111. },
  112. addBan () {
  113. let obj = { username: this.username }
  114. if(this.message.trim().length) {
  115. obj.message = this.message
  116. }
  117. if(this.selectedOption === 'both') {
  118. obj.canCreatePosts = false
  119. obj.canCreateThreads = false
  120. } else if(this.selectedOption === 'thread') {
  121. obj.canCreateThreads = false
  122. } else if(this.selectedOption === 'post') {
  123. obj.canCreatePosts = false
  124. }
  125. this.axios
  126. .post('/api/v1/ban', obj)
  127. .then(res => {
  128. this.bans_.push(res.data)
  129. this.toggleShowAddNewBanModal()
  130. })
  131. .catch(AjaxErrorHandler(this.$store))
  132. }
  133. },
  134. mounted () {
  135. this.$store.dispatch('setTitle', 'admin | moderation')
  136. this.axios
  137. .get('/api/v1/ban')
  138. .then(res => {
  139. this.bans_ = res.data
  140. })
  141. .catch(AjaxErrorHandler(this.$store))
  142. }
  143. }
  144. </script>
  145. <style lang='scss' scoped>
  146. @import '../../assets/scss/variables.scss';
  147. .admin_moderation {
  148. padding: 1rem;
  149. padding-top: 0.5rem;
  150. @at-root #{&}__tabs {
  151. margin-bottom: 1rem;
  152. }
  153. @at-root #{&}__header {
  154. display: flex;
  155. justify-content: space-between;
  156. align-items: center;
  157. }
  158. @at-root #{&}__add_new_ban_modal {
  159. padding: 1rem;
  160. h2 {
  161. padding: 0;
  162. margin: 0;
  163. margin-bottom: -0.5rem;
  164. }
  165. }
  166. @at-root #{&}__table {
  167. width: calc(100%);
  168. overflow: hidden;
  169. margin-top: 1rem;
  170. padding: 0.5rem;
  171. background-color: #fff;
  172. border-radius: 0.25rem;
  173. border-collapse: collapse;
  174. @extend .shadow_border;
  175. td, th {
  176. padding: 0.5rem;
  177. }
  178. th {
  179. text-align: left;
  180. }
  181. tr:nth-child(even) {
  182. background-color: $color__lightgray--darker;
  183. }
  184. }
  185. }
  186. </style>