useTicketCreateView.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import { useApplicationStore } from '#shared/stores/application.ts'
  4. import { useSessionStore } from '#shared/stores/session.ts'
  5. import getUuid from '#shared/utils/getUuid.ts'
  6. import type { RouteLocationNormalized } from 'vue-router'
  7. export const useTicketCreateView = () => {
  8. const application = useApplicationStore()
  9. const session = useSessionStore()
  10. const ticketCreateEnabled = computed(() => {
  11. return (
  12. session.hasPermission('ticket.agent') ||
  13. (session.hasPermission('ticket.customer') &&
  14. application.config.customer_ticket_create)
  15. )
  16. })
  17. const isTicketCustomer = computed(() => {
  18. return (
  19. session.hasPermission('ticket.customer') &&
  20. !session.hasPermission('ticket.agent')
  21. )
  22. })
  23. const checkUniqueTicketCreateRoute = (to: RouteLocationNormalized) => {
  24. if (!to.params.tabId) {
  25. return {
  26. path: `/tickets/create/${getUuid()}`,
  27. query: to.query,
  28. }
  29. }
  30. return true
  31. }
  32. return {
  33. ticketCreateEnabled,
  34. isTicketCustomer,
  35. checkUniqueTicketCreateRoute,
  36. }
  37. }