20230426143104_add_ticket_duplicate_detection.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class AddTicketDuplicateDetection < ActiveRecord::Migration[6.1]
  3. def change
  4. return if !Setting.exists?(name: 'system_init_done')
  5. Setting.create_if_not_exists(
  6. title: 'Detect Duplicate Ticket Creation',
  7. name: 'ticket_duplicate_detection',
  8. area: 'Web::TicketDuplicateDetection',
  9. description: 'Enables a warning to users during ticket creation if there is an existing ticket with the same attributes.',
  10. options: {
  11. form: [
  12. {
  13. display: '',
  14. null: true,
  15. name: 'ticket_duplicate_detection',
  16. tag: 'boolean',
  17. options: {
  18. true => 'yes',
  19. false => 'no',
  20. },
  21. },
  22. ],
  23. },
  24. preferences: {
  25. authentication: true,
  26. permission: ['admin.ticket_duplicate_detection'],
  27. },
  28. state: false,
  29. frontend: true
  30. )
  31. Setting.create_if_not_exists(
  32. title: 'Attributes to compare',
  33. name: 'ticket_duplicate_detection_attributes',
  34. area: 'Web::TicketDuplicateDetection',
  35. description: 'Defines which ticket attributes are checked before creating a ticket.',
  36. options: {
  37. form: [
  38. {},
  39. ],
  40. },
  41. preferences: {
  42. authentication: true,
  43. permission: ['admin.ticket_duplicate_detection'],
  44. },
  45. state: [],
  46. frontend: true
  47. )
  48. Setting.create_if_not_exists(
  49. title: 'Warning title',
  50. name: 'ticket_duplicate_detection_title',
  51. area: 'Web::TicketDuplicateDetection',
  52. description: 'Defines the warning title that is shown when a matching ticket is present.',
  53. options: {
  54. form: [
  55. {},
  56. ],
  57. },
  58. preferences: {
  59. authentication: true,
  60. permission: ['admin.ticket_duplicate_detection'],
  61. },
  62. state: 'Similar tickets found',
  63. frontend: true
  64. )
  65. Setting.create_if_not_exists(
  66. title: 'Warning message',
  67. name: 'ticket_duplicate_detection_body',
  68. area: 'Web::TicketDuplicateDetection',
  69. description: 'Defines the warning message that is shown when a matching ticket is present.',
  70. options: {
  71. form: [
  72. {},
  73. ],
  74. },
  75. preferences: {
  76. authentication: true,
  77. permission: ['admin.ticket_duplicate_detection'],
  78. },
  79. state: 'Tickets with the same attributes were found.',
  80. frontend: true
  81. )
  82. Setting.create_if_not_exists(
  83. title: 'Show to user roles',
  84. name: 'ticket_duplicate_detection_role_ids',
  85. area: 'Web::TicketDuplicateDetection',
  86. description: 'Defines which user roles will receive a warning in case of matching tickets.',
  87. options: {
  88. form: [
  89. {},
  90. ],
  91. },
  92. preferences: {
  93. authentication: true,
  94. permission: ['admin.ticket_duplicate_detection'],
  95. },
  96. state: [2],
  97. frontend: true
  98. )
  99. Setting.create_if_not_exists(
  100. title: 'Show matching tickets in the warning',
  101. name: 'ticket_duplicate_detection_show_tickets',
  102. area: 'Web::TicketDuplicateDetection',
  103. description: 'Defines whether the matching tickets are shown in case of already existing tickets.',
  104. options: {
  105. form: [
  106. {},
  107. ],
  108. },
  109. preferences: {
  110. authentication: true,
  111. permission: ['admin.ticket_duplicate_detection'],
  112. },
  113. state: true,
  114. frontend: true
  115. )
  116. Setting.create_if_not_exists(
  117. title: 'Permission level for looking up tickets',
  118. name: 'ticket_duplicate_detection_permission_level',
  119. area: 'Web::TicketDuplicateDetection',
  120. description: 'Defines the permission level used for lookups.',
  121. options: {
  122. form: [
  123. {},
  124. ],
  125. },
  126. preferences: {
  127. authentication: true,
  128. permission: ['admin.ticket_duplicate_detection'],
  129. },
  130. state: 'user',
  131. frontend: true
  132. )
  133. Setting.create_if_not_exists(
  134. title: 'Match tickets in following states',
  135. name: 'ticket_duplicate_detection_search',
  136. area: 'Web::TicketDuplicateDetection',
  137. description: 'Defines the ticket states used for lookups.',
  138. options: {
  139. form: [
  140. {},
  141. ],
  142. },
  143. state: 'all',
  144. preferences: {
  145. authentication: true,
  146. permission: ['admin.ticket_duplicate_detection']
  147. },
  148. frontend: true
  149. )
  150. CoreWorkflow.create_if_not_exists(
  151. name: 'base - ticket duplicate detection with same attributes',
  152. object: 'Ticket',
  153. condition_saved: {
  154. 'custom.module': {
  155. operator: 'match all modules',
  156. value: [
  157. 'CoreWorkflow::Custom::TicketDuplicateDetection',
  158. ],
  159. },
  160. },
  161. perform: {
  162. 'custom.module': {
  163. execute: ['CoreWorkflow::Custom::TicketDuplicateDetection']
  164. },
  165. },
  166. changeable: false,
  167. created_by_id: 1,
  168. updated_by_id: 1,
  169. )
  170. end
  171. end