object_manager_attribute.rb 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://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. transient do
  117. data_option_options do
  118. {
  119. 'key_1' => 'value_1',
  120. 'key_2' => 'value_2',
  121. 'key_3' => 'value_3',
  122. }
  123. end
  124. end
  125. default { '' }
  126. data_type { 'select' }
  127. data_option do
  128. {
  129. 'default' => default,
  130. 'options' => data_option_options,
  131. 'relation' => '',
  132. 'nulloption' => true,
  133. 'multiple' => false,
  134. 'null' => true,
  135. 'translate' => true,
  136. 'maxlength' => 255
  137. }
  138. end
  139. end
  140. factory :object_manager_attribute_multiselect, parent: :object_manager_attribute do
  141. default { '' }
  142. data_type { 'multiselect' }
  143. data_option do
  144. {
  145. 'default' => default,
  146. 'options' => {
  147. 'key_1' => 'value_1',
  148. 'key_2' => 'value_2',
  149. 'key_3' => 'value_3',
  150. },
  151. 'relation' => '',
  152. 'nulloption' => true,
  153. 'multiple' => true,
  154. 'null' => true,
  155. 'translate' => true,
  156. 'maxlength' => 255
  157. }
  158. end
  159. end
  160. factory :object_manager_attribute_tree_select, parent: :object_manager_attribute do
  161. default { '' }
  162. data_type { 'tree_select' }
  163. data_option do
  164. {
  165. 'options' => [
  166. {
  167. 'name' => 'Incident',
  168. 'value' => 'Incident',
  169. 'children' => [
  170. {
  171. 'name' => 'Hardware',
  172. 'value' => 'Incident::Hardware',
  173. 'children' => [
  174. {
  175. 'name' => 'Monitor',
  176. 'value' => 'Incident::Hardware::Monitor'
  177. },
  178. {
  179. 'name' => 'Mouse',
  180. 'value' => 'Incident::Hardware::Mouse'
  181. },
  182. {
  183. 'name' => 'Keyboard',
  184. 'value' => 'Incident::Hardware::Keyboard'
  185. }
  186. ]
  187. },
  188. {
  189. 'name' => 'Softwareproblem',
  190. 'value' => 'Incident::Softwareproblem',
  191. 'children' => [
  192. {
  193. 'name' => 'CRM',
  194. 'value' => 'Incident::Softwareproblem::CRM'
  195. },
  196. {
  197. 'name' => 'EDI',
  198. 'value' => 'Incident::Softwareproblem::EDI'
  199. },
  200. {
  201. 'name' => 'SAP',
  202. 'value' => 'Incident::Softwareproblem::SAP',
  203. 'children' => [
  204. {
  205. 'name' => 'Authentication',
  206. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  207. },
  208. {
  209. 'name' => 'Not reachable',
  210. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  211. }
  212. ]
  213. },
  214. {
  215. 'name' => 'MS Office',
  216. 'value' => 'Incident::Softwareproblem::MS Office',
  217. 'children' => [
  218. {
  219. 'name' => 'Excel',
  220. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  221. },
  222. {
  223. 'name' => 'PowerPoint',
  224. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  225. },
  226. {
  227. 'name' => 'Word',
  228. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  229. },
  230. {
  231. 'name' => 'Outlook',
  232. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  233. }
  234. ]
  235. }
  236. ]
  237. }
  238. ]
  239. },
  240. {
  241. 'name' => 'Service request',
  242. 'value' => 'Service request',
  243. 'children' => [
  244. {
  245. 'name' => 'New software requirement',
  246. 'value' => 'Service request::New software requirement'
  247. },
  248. {
  249. 'name' => 'New hardware',
  250. 'value' => 'Service request::New hardware'
  251. },
  252. {
  253. 'name' => 'Consulting',
  254. 'value' => 'Service request::Consulting'
  255. }
  256. ]
  257. },
  258. {
  259. 'name' => 'Change request',
  260. 'value' => 'Change request'
  261. }
  262. ],
  263. 'default' => '',
  264. 'null' => true,
  265. 'relation' => '',
  266. 'maxlength' => 255,
  267. 'nulloption' => true,
  268. }
  269. end
  270. end
  271. factory :required_screen, class: Hash do
  272. create_middle do
  273. {
  274. 'ticket.customer' => {
  275. shown: true,
  276. required: true,
  277. item_class: 'column'
  278. },
  279. 'ticket.agent' => {
  280. shown: true,
  281. required: true,
  282. item_class: 'column'
  283. },
  284. 'admin.organization' => {
  285. shown: true,
  286. required: true,
  287. },
  288. 'admin.group' => {
  289. shown: true,
  290. required: true,
  291. item_class: 'column'
  292. },
  293. }
  294. end
  295. edit do
  296. {
  297. 'ticket.customer' => {
  298. shown: true,
  299. required: true
  300. },
  301. 'ticket.agent' => {
  302. shown: true,
  303. required: true
  304. },
  305. 'admin.organization' => {
  306. shown: true,
  307. required: true,
  308. },
  309. 'admin.group' => {
  310. shown: true,
  311. required: true,
  312. item_class: 'column'
  313. },
  314. }
  315. end
  316. end
  317. end