Punishments.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div>
  3. <page-metadata title="Admin | Users | Punishments" />
  4. <div class="container">
  5. <advanced-table
  6. :column-default="columnDefault"
  7. :columns="columns"
  8. :filters="filters"
  9. data-action="punishments.getData"
  10. name="admin-punishments"
  11. max-width="1200"
  12. >
  13. <template #column-options="slotProps">
  14. <div class="row-options">
  15. <button
  16. class="button is-primary icon-with-button material-icons"
  17. @click="view(slotProps.item._id)"
  18. :disabled="slotProps.item.removed"
  19. content="View Punishment"
  20. v-tippy
  21. >
  22. open_in_full
  23. </button>
  24. </div>
  25. </template>
  26. <template #column-status="slotProps">
  27. <span>{{ slotProps.item.status }}</span>
  28. </template>
  29. <template #column-type="slotProps">
  30. <span
  31. :title="
  32. slotProps.item.type === 'banUserId'
  33. ? 'User ID'
  34. : 'IP Address'
  35. "
  36. >{{
  37. slotProps.item.type === "banUserId"
  38. ? "User ID"
  39. : "IP Address"
  40. }}</span
  41. >
  42. </template>
  43. <template #column-value="slotProps">
  44. <user-id-to-username
  45. v-if="slotProps.item.type === 'banUserId'"
  46. :user-id="slotProps.item.value"
  47. :alt="slotProps.item.value"
  48. :link="true"
  49. />
  50. <span v-else :title="slotProps.item.value">{{
  51. slotProps.item.value
  52. }}</span>
  53. </template>
  54. <template #column-reason="slotProps">
  55. <span :title="slotProps.item.reason">{{
  56. slotProps.item.reason
  57. }}</span>
  58. </template>
  59. <template #column-punishedBy="slotProps">
  60. <user-id-to-username
  61. :user-id="slotProps.item.punishedBy"
  62. :link="true"
  63. />
  64. </template>
  65. <template #column-punishedAt="slotProps">
  66. <span :title="new Date(slotProps.item.punishedAt)">{{
  67. getDateFormatted(slotProps.item.punishedAt)
  68. }}</span>
  69. </template>
  70. <template #column-expiresAt="slotProps">
  71. <span :title="new Date(slotProps.item.expiresAt)">{{
  72. getDateFormatted(slotProps.item.expiresAt)
  73. }}</span>
  74. </template>
  75. </advanced-table>
  76. <div class="card">
  77. <header class="card-header">
  78. <p>Ban an IP</p>
  79. </header>
  80. <div class="card-content">
  81. <label class="label">Expires In</label>
  82. <p class="control is-expanded select">
  83. <select v-model="ipBan.expiresAt">
  84. <option value="1h">1 Hour</option>
  85. <option value="12h">12 Hours</option>
  86. <option value="1d">1 Day</option>
  87. <option value="1w">1 Week</option>
  88. <option value="1m">1 Month</option>
  89. <option value="3m">3 Months</option>
  90. <option value="6m">6 Months</option>
  91. <option value="1y">1 Year</option>
  92. </select>
  93. </p>
  94. <label class="label">IP</label>
  95. <p class="control is-expanded">
  96. <input
  97. v-model="ipBan.ip"
  98. class="input"
  99. type="text"
  100. placeholder="IP address (xxx.xxx.xxx.xxx)"
  101. />
  102. </p>
  103. <label class="label">Reason</label>
  104. <p class="control is-expanded">
  105. <input
  106. v-model="ipBan.reason"
  107. class="input"
  108. type="text"
  109. placeholder="Reason"
  110. />
  111. </p>
  112. <button class="button is-primary" @click="banIP()">
  113. Ban IP
  114. </button>
  115. </div>
  116. </div>
  117. </div>
  118. <view-punishment
  119. v-if="modals.viewPunishment"
  120. :punishment-id="viewingPunishmentId"
  121. sector="admin"
  122. />
  123. </div>
  124. </template>
  125. <script>
  126. import { mapState, mapGetters, mapActions } from "vuex";
  127. import Toast from "toasters";
  128. import { defineAsyncComponent } from "vue";
  129. import AdvancedTable from "@/components/AdvancedTable.vue";
  130. export default {
  131. components: {
  132. ViewPunishment: defineAsyncComponent(() =>
  133. import("@/components/modals/ViewPunishment.vue")
  134. ),
  135. AdvancedTable
  136. },
  137. data() {
  138. return {
  139. viewingPunishmentId: "",
  140. ipBan: {
  141. expiresAt: "1h"
  142. },
  143. columnDefault: {
  144. sortable: true,
  145. hidable: true,
  146. defaultVisibility: "shown",
  147. draggable: true,
  148. resizable: true,
  149. minWidth: 150,
  150. maxWidth: 600
  151. },
  152. columns: [
  153. {
  154. name: "options",
  155. displayName: "Options",
  156. properties: ["_id"],
  157. sortable: false,
  158. hidable: false,
  159. resizable: false,
  160. minWidth: 76,
  161. defaultWidth: 76
  162. },
  163. {
  164. name: "status",
  165. displayName: "Status",
  166. properties: ["status"],
  167. sortable: false,
  168. defaultWidth: 150
  169. },
  170. {
  171. name: "type",
  172. displayName: "Type",
  173. properties: ["type"],
  174. sortProperty: "type"
  175. },
  176. {
  177. name: "value",
  178. displayName: "Value",
  179. properties: ["value"],
  180. sortProperty: "value",
  181. defaultWidth: 150
  182. },
  183. {
  184. name: "reason",
  185. displayName: "Reason",
  186. properties: ["reason"],
  187. sortProperty: "reason"
  188. },
  189. {
  190. name: "punishedBy",
  191. displayName: "Punished By",
  192. properties: ["punishedBy"],
  193. sortProperty: "punishedBy",
  194. defaultWidth: 200,
  195. defaultVisibility: "hidden"
  196. },
  197. {
  198. name: "punishedAt",
  199. displayName: "Punished At",
  200. properties: ["punishedAt"],
  201. sortProperty: "punishedAt",
  202. defaultWidth: 200,
  203. defaultVisibility: "hidden"
  204. },
  205. {
  206. name: "expiresAt",
  207. displayName: "Expires At",
  208. properties: ["expiresAt"],
  209. sortProperty: "verifiedAt",
  210. defaultWidth: 200,
  211. defaultVisibility: "hidden"
  212. }
  213. ],
  214. filters: [
  215. {
  216. name: "status",
  217. displayName: "Status",
  218. property: "status",
  219. filterTypes: ["exact"],
  220. defaultFilterType: "exact",
  221. dropdown: [
  222. ["Active", "Active"],
  223. ["Inactive", "Inactive"]
  224. ]
  225. },
  226. {
  227. name: "type",
  228. displayName: "Type",
  229. property: "type",
  230. filterTypes: ["exact"],
  231. defaultFilterType: "exact",
  232. dropdown: [
  233. ["banUserId", "User ID"],
  234. ["banUserIp", "IP Address"]
  235. ]
  236. },
  237. {
  238. name: "value",
  239. displayName: "Value",
  240. property: "value",
  241. filterTypes: ["contains", "exact", "regex"],
  242. defaultFilterType: "contains"
  243. },
  244. {
  245. name: "reason",
  246. displayName: "Reason",
  247. property: "reason",
  248. filterTypes: ["contains", "exact", "regex"],
  249. defaultFilterType: "contains"
  250. },
  251. {
  252. name: "punishedBy",
  253. displayName: "Punished By",
  254. property: "punishedBy",
  255. filterTypes: ["contains", "exact", "regex"],
  256. defaultFilterType: "contains"
  257. },
  258. {
  259. name: "punishedAt",
  260. displayName: "Punished At",
  261. property: "punishedAt",
  262. filterTypes: ["datetimeBefore", "datetimeAfter"],
  263. defaultFilterType: "datetimeBefore"
  264. },
  265. {
  266. name: "expiresAt",
  267. displayName: "Expires At",
  268. property: "expiresAt",
  269. filterTypes: ["datetimeBefore", "datetimeAfter"],
  270. defaultFilterType: "datetimeBefore"
  271. }
  272. ]
  273. };
  274. },
  275. computed: {
  276. ...mapState("modalVisibility", {
  277. modals: state => state.modals
  278. }),
  279. ...mapGetters({
  280. socket: "websockets/getSocket"
  281. })
  282. },
  283. methods: {
  284. view(punishmentId) {
  285. this.viewingPunishmentId = punishmentId;
  286. this.openModal("viewPunishment");
  287. },
  288. banIP() {
  289. this.socket.dispatch(
  290. "punishments.banIP",
  291. this.ipBan.ip,
  292. this.ipBan.reason,
  293. this.ipBan.expiresAt,
  294. res => {
  295. new Toast(res.message);
  296. }
  297. );
  298. },
  299. getDateFormatted(createdAt) {
  300. const date = new Date(createdAt);
  301. const year = date.getFullYear();
  302. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  303. const day = `${date.getDate()}`.padStart(2, 0);
  304. const hour = `${date.getHours()}`.padStart(2, 0);
  305. const minute = `${date.getMinutes()}`.padStart(2, 0);
  306. return `${year}-${month}-${day} ${hour}:${minute}`;
  307. },
  308. ...mapActions("modalVisibility", ["openModal"]),
  309. ...mapActions("admin/punishments", ["viewPunishment"])
  310. }
  311. };
  312. </script>
  313. <style lang="less" scoped>
  314. .night-mode {
  315. .card {
  316. background: var(--dark-grey-3);
  317. p,
  318. .label {
  319. color: var(--light-grey-2);
  320. }
  321. }
  322. }
  323. .card {
  324. display: flex;
  325. flex-grow: 1;
  326. flex-direction: column;
  327. padding: 20px;
  328. margin: 10px 0;
  329. border-radius: @border-radius;
  330. background-color: var(--white);
  331. color: var(--dark-grey);
  332. box-shadow: @box-shadow;
  333. .card-header {
  334. font-weight: 700;
  335. padding-bottom: 10px;
  336. }
  337. .button.is-primary {
  338. width: 100%;
  339. }
  340. }
  341. </style>