object_manager_attribute.rb 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. FactoryBot.define do
  3. factory :object_manager_attribute, class: 'ObjectManager::Attribute' do
  4. transient do
  5. object_name { 'Ticket' }
  6. additional_data_options { nil }
  7. default { nil }
  8. end
  9. object_lookup_id { ObjectLookup.by_name(object_name) }
  10. sequence(:name) { |n| "internal_name#{n}" }
  11. sequence(:display) { |n| "Display Name #{n}" }
  12. data_option_new { {} }
  13. editable { true }
  14. active { true }
  15. add_attribute(:to_create) { true }
  16. to_migrate { true }
  17. to_delete { false }
  18. to_config { false }
  19. position { 15 }
  20. updated_by_id { 1 }
  21. created_by_id { 1 }
  22. screens do
  23. {
  24. 'create_top' => {
  25. '-all-' => {
  26. 'null' => false
  27. }
  28. },
  29. 'edit' => {}
  30. }
  31. end
  32. callback(:after_stub, :before_create) do |object, context|
  33. next if context.additional_data_options.blank?
  34. object.data_option ||= {}
  35. object.data_option.merge! context.additional_data_options
  36. end
  37. end
  38. factory :object_manager_attribute_text, parent: :object_manager_attribute do
  39. default { '' }
  40. data_type { 'input' }
  41. data_option do
  42. {
  43. 'type' => 'text',
  44. 'maxlength' => 200,
  45. 'null' => true,
  46. 'translate' => false,
  47. 'default' => default,
  48. 'options' => {},
  49. 'relation' => '',
  50. }
  51. end
  52. end
  53. factory :object_manager_attribute_textarea, parent: :object_manager_attribute do
  54. data_type { 'textarea' }
  55. data_option do
  56. {
  57. 'type' => 'textarea',
  58. 'maxlength' => 255,
  59. 'null' => true,
  60. 'translate' => false,
  61. 'default' => default || '',
  62. 'options' => {},
  63. 'relation' => '',
  64. }
  65. end
  66. end
  67. factory :object_manager_attribute_integer, parent: :object_manager_attribute do
  68. default { 0 }
  69. data_type { 'integer' }
  70. data_option do
  71. {
  72. 'default' => default,
  73. 'min' => 0,
  74. 'max' => 9999,
  75. }
  76. end
  77. end
  78. factory :object_manager_attribute_boolean, parent: :object_manager_attribute do
  79. default { false }
  80. data_type { 'boolean' }
  81. data_option do
  82. {
  83. default: default,
  84. options: {
  85. true => 'yes',
  86. false => 'no',
  87. }
  88. }
  89. end
  90. end
  91. factory :object_manager_attribute_date, parent: :object_manager_attribute do
  92. default { 24 }
  93. name { 'date_attribute' }
  94. data_type { 'date' }
  95. data_option do
  96. {
  97. 'diff' => default,
  98. 'null' => true,
  99. }
  100. end
  101. end
  102. factory :object_manager_attribute_datetime, parent: :object_manager_attribute do
  103. default { 24 }
  104. name { 'datetime_attribute' }
  105. data_type { 'datetime' }
  106. data_option do
  107. {
  108. 'future' => true,
  109. 'past' => true,
  110. 'diff' => default,
  111. 'null' => true,
  112. }
  113. end
  114. end
  115. factory :object_manager_attribute_select, parent: :object_manager_attribute do
  116. default { '' }
  117. data_type { 'select' }
  118. data_option do
  119. {
  120. 'default' => default,
  121. 'options' => {
  122. 'key_1' => 'value_1',
  123. 'key_2' => 'value_2',
  124. 'key_3' => 'value_3',
  125. },
  126. 'relation' => '',
  127. 'nulloption' => true,
  128. 'multiple' => false,
  129. 'null' => true,
  130. 'translate' => true,
  131. 'maxlength' => 255
  132. }
  133. end
  134. end
  135. factory :object_manager_attribute_tree_select, parent: :object_manager_attribute do
  136. default { '' }
  137. data_type { 'tree_select' }
  138. data_option do
  139. {
  140. 'options' => [
  141. {
  142. 'name' => 'Incident',
  143. 'value' => 'Incident',
  144. 'children' => [
  145. {
  146. 'name' => 'Hardware',
  147. 'value' => 'Incident::Hardware',
  148. 'children' => [
  149. {
  150. 'name' => 'Monitor',
  151. 'value' => 'Incident::Hardware::Monitor'
  152. },
  153. {
  154. 'name' => 'Mouse',
  155. 'value' => 'Incident::Hardware::Mouse'
  156. },
  157. {
  158. 'name' => 'Keyboard',
  159. 'value' => 'Incident::Hardware::Keyboard'
  160. }
  161. ]
  162. },
  163. {
  164. 'name' => 'Softwareproblem',
  165. 'value' => 'Incident::Softwareproblem',
  166. 'children' => [
  167. {
  168. 'name' => 'CRM',
  169. 'value' => 'Incident::Softwareproblem::CRM'
  170. },
  171. {
  172. 'name' => 'EDI',
  173. 'value' => 'Incident::Softwareproblem::EDI'
  174. },
  175. {
  176. 'name' => 'SAP',
  177. 'value' => 'Incident::Softwareproblem::SAP',
  178. 'children' => [
  179. {
  180. 'name' => 'Authentication',
  181. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  182. },
  183. {
  184. 'name' => 'Not reachable',
  185. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  186. }
  187. ]
  188. },
  189. {
  190. 'name' => 'MS Office',
  191. 'value' => 'Incident::Softwareproblem::MS Office',
  192. 'children' => [
  193. {
  194. 'name' => 'Excel',
  195. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  196. },
  197. {
  198. 'name' => 'PowerPoint',
  199. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  200. },
  201. {
  202. 'name' => 'Word',
  203. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  204. },
  205. {
  206. 'name' => 'Outlook',
  207. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  208. }
  209. ]
  210. }
  211. ]
  212. }
  213. ]
  214. },
  215. {
  216. 'name' => 'Service request',
  217. 'value' => 'Service request',
  218. 'children' => [
  219. {
  220. 'name' => 'New software requirement',
  221. 'value' => 'Service request::New software requirement'
  222. },
  223. {
  224. 'name' => 'New hardware',
  225. 'value' => 'Service request::New hardware'
  226. },
  227. {
  228. 'name' => 'Consulting',
  229. 'value' => 'Service request::Consulting'
  230. }
  231. ]
  232. },
  233. {
  234. 'name' => 'Change request',
  235. 'value' => 'Change request'
  236. }
  237. ],
  238. 'default' => '',
  239. 'null' => true,
  240. 'relation' => '',
  241. 'maxlength' => 255,
  242. 'nulloption' => true,
  243. }
  244. end
  245. end
  246. factory :required_screen, class: Hash do
  247. create_middle do
  248. {
  249. 'ticket.customer' => {
  250. shown: true,
  251. required: true,
  252. item_class: 'column'
  253. },
  254. 'ticket.agent' => {
  255. shown: true,
  256. required: true,
  257. item_class: 'column'
  258. },
  259. 'admin.organization' => {
  260. shown: true,
  261. required: true,
  262. },
  263. 'admin.group' => {
  264. shown: true,
  265. required: true,
  266. item_class: 'column'
  267. },
  268. }
  269. end
  270. edit do
  271. {
  272. 'ticket.customer' => {
  273. shown: true,
  274. required: true
  275. },
  276. 'ticket.agent' => {
  277. shown: true,
  278. required: true
  279. },
  280. 'admin.organization' => {
  281. shown: true,
  282. required: true,
  283. },
  284. 'admin.group' => {
  285. shown: true,
  286. required: true,
  287. item_class: 'column'
  288. },
  289. }
  290. end
  291. end
  292. end