object_manager_attribute.rb 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. # Copyright (C) 2012-2023 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. trait :required_screen do
  38. screens do
  39. {
  40. 'create_middle' =>
  41. {
  42. 'ticket.customer' => {
  43. shown: true,
  44. required: true,
  45. item_class: 'column'
  46. },
  47. 'ticket.agent' => {
  48. shown: true,
  49. required: true,
  50. item_class: 'column'
  51. },
  52. 'admin.organization' => {
  53. shown: true,
  54. required: true,
  55. },
  56. 'admin.group' => {
  57. shown: true,
  58. required: true,
  59. item_class: 'column'
  60. },
  61. },
  62. 'edit' =>
  63. {
  64. 'ticket.customer' => {
  65. shown: true,
  66. required: true
  67. },
  68. 'ticket.agent' => {
  69. shown: true,
  70. required: true
  71. },
  72. 'admin.organization' => {
  73. shown: true,
  74. required: true,
  75. },
  76. 'admin.group' => {
  77. shown: true,
  78. required: true,
  79. item_class: 'column'
  80. },
  81. }
  82. }
  83. end
  84. end
  85. end
  86. factory :object_manager_attribute_text, parent: :object_manager_attribute do
  87. transient do
  88. data_option_maxlength { 200 }
  89. end
  90. default { '' }
  91. data_type { 'input' }
  92. data_option do
  93. {
  94. 'type' => 'text',
  95. 'maxlength' => data_option_maxlength,
  96. 'null' => true,
  97. 'translate' => false,
  98. 'default' => default,
  99. 'options' => {},
  100. 'relation' => '',
  101. }
  102. end
  103. end
  104. factory :object_manager_attribute_textarea, parent: :object_manager_attribute do
  105. default { '' }
  106. data_type { 'textarea' }
  107. data_option do
  108. {
  109. 'type' => 'textarea',
  110. 'maxlength' => 255,
  111. 'rows' => 4,
  112. 'null' => true,
  113. 'translate' => false,
  114. 'default' => default,
  115. 'options' => {},
  116. 'relation' => '',
  117. }
  118. end
  119. end
  120. factory :object_manager_attribute_integer, parent: :object_manager_attribute do
  121. default { 0 }
  122. data_type { 'integer' }
  123. data_option do
  124. {
  125. 'default' => default,
  126. 'min' => 0,
  127. 'max' => 9999,
  128. }
  129. end
  130. end
  131. factory :object_manager_attribute_boolean, parent: :object_manager_attribute do
  132. default { false }
  133. data_type { 'boolean' }
  134. data_option do
  135. {
  136. default: default,
  137. options: {
  138. true => 'yes',
  139. false => 'no',
  140. }
  141. }
  142. end
  143. end
  144. factory :object_manager_attribute_date, parent: :object_manager_attribute do
  145. default { 24 }
  146. name { 'date_attribute' }
  147. data_type { 'date' }
  148. data_option do
  149. {
  150. 'diff' => default,
  151. 'null' => true,
  152. }
  153. end
  154. end
  155. factory :object_manager_attribute_datetime, parent: :object_manager_attribute do
  156. default { 24 }
  157. name { 'datetime_attribute' }
  158. data_type { 'datetime' }
  159. data_option do
  160. {
  161. 'future' => true,
  162. 'past' => true,
  163. 'diff' => default,
  164. 'null' => true,
  165. }
  166. end
  167. end
  168. factory :object_manager_attribute_select, parent: :object_manager_attribute do
  169. transient do
  170. data_option_options do
  171. {
  172. 'key_1' => 'value_1',
  173. 'key_2' => 'value_2',
  174. 'key_3' => 'value_3',
  175. }
  176. end
  177. end
  178. default { '' }
  179. data_type { 'select' }
  180. data_option do
  181. {
  182. 'default' => default,
  183. 'options' => data_option_options,
  184. 'relation' => '',
  185. 'nulloption' => true,
  186. 'multiple' => false,
  187. 'null' => true,
  188. 'translate' => true,
  189. 'maxlength' => 255
  190. }
  191. end
  192. end
  193. factory :object_manager_attribute_multiselect, parent: :object_manager_attribute do
  194. transient do
  195. data_option_options do
  196. {
  197. 'key_1' => 'value_1',
  198. 'key_2' => 'value_2',
  199. 'key_3' => 'value_3',
  200. }
  201. end
  202. end
  203. default { [] }
  204. data_type { 'multiselect' }
  205. data_option do
  206. {
  207. 'default' => default,
  208. 'options' => data_option_options,
  209. 'relation' => '',
  210. 'nulloption' => true,
  211. 'multiple' => true,
  212. 'null' => true,
  213. 'translate' => true,
  214. 'maxlength' => 255
  215. }
  216. end
  217. end
  218. factory :object_manager_attribute_tree_select, parent: :object_manager_attribute do
  219. default { '' }
  220. data_type { 'tree_select' }
  221. data_option do
  222. {
  223. 'options' => [
  224. {
  225. 'name' => 'Incident',
  226. 'value' => 'Incident',
  227. 'children' => [
  228. {
  229. 'name' => 'Hardware',
  230. 'value' => 'Incident::Hardware',
  231. 'children' => [
  232. {
  233. 'name' => 'Monitor',
  234. 'value' => 'Incident::Hardware::Monitor'
  235. },
  236. {
  237. 'name' => 'Mouse',
  238. 'value' => 'Incident::Hardware::Mouse'
  239. },
  240. {
  241. 'name' => 'Keyboard',
  242. 'value' => 'Incident::Hardware::Keyboard'
  243. }
  244. ]
  245. },
  246. {
  247. 'name' => 'Softwareproblem',
  248. 'value' => 'Incident::Softwareproblem',
  249. 'children' => [
  250. {
  251. 'name' => 'CRM',
  252. 'value' => 'Incident::Softwareproblem::CRM'
  253. },
  254. {
  255. 'name' => 'EDI',
  256. 'value' => 'Incident::Softwareproblem::EDI'
  257. },
  258. {
  259. 'name' => 'SAP',
  260. 'value' => 'Incident::Softwareproblem::SAP',
  261. 'children' => [
  262. {
  263. 'name' => 'Authentication',
  264. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  265. },
  266. {
  267. 'name' => 'Not reachable',
  268. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  269. }
  270. ]
  271. },
  272. {
  273. 'name' => 'MS Office',
  274. 'value' => 'Incident::Softwareproblem::MS Office',
  275. 'children' => [
  276. {
  277. 'name' => 'Excel',
  278. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  279. },
  280. {
  281. 'name' => 'PowerPoint',
  282. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  283. },
  284. {
  285. 'name' => 'Word',
  286. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  287. },
  288. {
  289. 'name' => 'Outlook',
  290. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  291. }
  292. ]
  293. }
  294. ]
  295. }
  296. ]
  297. },
  298. {
  299. 'name' => 'Service request',
  300. 'value' => 'Service request',
  301. 'children' => [
  302. {
  303. 'name' => 'New software requirement',
  304. 'value' => 'Service request::New software requirement'
  305. },
  306. {
  307. 'name' => 'New hardware',
  308. 'value' => 'Service request::New hardware'
  309. },
  310. {
  311. 'name' => 'Consulting',
  312. 'value' => 'Service request::Consulting'
  313. }
  314. ]
  315. },
  316. {
  317. 'name' => 'Change request',
  318. 'value' => 'Change request'
  319. }
  320. ],
  321. 'default' => '',
  322. 'null' => true,
  323. 'relation' => '',
  324. 'maxlength' => 255,
  325. 'nulloption' => true,
  326. }
  327. end
  328. end
  329. factory :object_manager_attribute_multi_tree_select, parent: :object_manager_attribute do
  330. default { [] }
  331. data_type { 'multi_tree_select' }
  332. data_option do
  333. {
  334. 'options' => [
  335. {
  336. 'name' => 'Incident',
  337. 'value' => 'Incident',
  338. 'children' => [
  339. {
  340. 'name' => 'Hardware',
  341. 'value' => 'Incident::Hardware',
  342. 'children' => [
  343. {
  344. 'name' => 'Monitor',
  345. 'value' => 'Incident::Hardware::Monitor'
  346. },
  347. {
  348. 'name' => 'Mouse',
  349. 'value' => 'Incident::Hardware::Mouse'
  350. },
  351. {
  352. 'name' => 'Keyboard',
  353. 'value' => 'Incident::Hardware::Keyboard'
  354. }
  355. ]
  356. },
  357. {
  358. 'name' => 'Softwareproblem',
  359. 'value' => 'Incident::Softwareproblem',
  360. 'children' => [
  361. {
  362. 'name' => 'CRM',
  363. 'value' => 'Incident::Softwareproblem::CRM'
  364. },
  365. {
  366. 'name' => 'EDI',
  367. 'value' => 'Incident::Softwareproblem::EDI'
  368. },
  369. {
  370. 'name' => 'SAP',
  371. 'value' => 'Incident::Softwareproblem::SAP',
  372. 'children' => [
  373. {
  374. 'name' => 'Authentication',
  375. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  376. },
  377. {
  378. 'name' => 'Not reachable',
  379. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  380. }
  381. ]
  382. },
  383. {
  384. 'name' => 'MS Office',
  385. 'value' => 'Incident::Softwareproblem::MS Office',
  386. 'children' => [
  387. {
  388. 'name' => 'Excel',
  389. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  390. },
  391. {
  392. 'name' => 'PowerPoint',
  393. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  394. },
  395. {
  396. 'name' => 'Word',
  397. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  398. },
  399. {
  400. 'name' => 'Outlook',
  401. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  402. }
  403. ]
  404. }
  405. ]
  406. }
  407. ]
  408. },
  409. {
  410. 'name' => 'Service request',
  411. 'value' => 'Service request',
  412. 'children' => [
  413. {
  414. 'name' => 'New software requirement',
  415. 'value' => 'Service request::New software requirement'
  416. },
  417. {
  418. 'name' => 'New hardware',
  419. 'value' => 'Service request::New hardware'
  420. },
  421. {
  422. 'name' => 'Consulting',
  423. 'value' => 'Service request::Consulting'
  424. }
  425. ]
  426. },
  427. {
  428. 'name' => 'Change request',
  429. 'value' => 'Change request'
  430. }
  431. ],
  432. 'default' => '',
  433. 'null' => true,
  434. 'relation' => '',
  435. 'maxlength' => 255,
  436. 'nulloption' => true,
  437. 'multiple' => true,
  438. }
  439. end
  440. end
  441. end