Punishments.vue 7.5 KB

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