object_manager_attribute.rb 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. # Copyright (C) 2012-2024 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. trait :shown_screen do
  86. screens do
  87. {
  88. 'create_middle' =>
  89. {
  90. '-all-' => {
  91. shown: true
  92. }
  93. },
  94. 'edit' =>
  95. {
  96. '-all-' => {
  97. shown: true
  98. }
  99. }
  100. }
  101. end
  102. end
  103. end
  104. factory :object_manager_attribute_text, parent: :object_manager_attribute do
  105. transient do
  106. data_option_maxlength { 200 }
  107. end
  108. default { '' }
  109. data_type { 'input' }
  110. data_option do
  111. {
  112. 'type' => 'text',
  113. 'maxlength' => data_option_maxlength,
  114. 'null' => true,
  115. 'translate' => false,
  116. 'default' => default,
  117. 'options' => {},
  118. 'relation' => '',
  119. }
  120. end
  121. end
  122. factory :object_manager_attribute_textarea, parent: :object_manager_attribute do
  123. default { '' }
  124. data_type { 'textarea' }
  125. data_option do
  126. {
  127. 'type' => 'textarea',
  128. 'maxlength' => 255,
  129. 'rows' => 4,
  130. 'null' => true,
  131. 'translate' => false,
  132. 'default' => default,
  133. 'options' => {},
  134. 'relation' => '',
  135. }
  136. end
  137. end
  138. factory :object_manager_attribute_integer, parent: :object_manager_attribute do
  139. default { 0 }
  140. data_type { 'integer' }
  141. data_option do
  142. {
  143. 'default' => default,
  144. 'min' => 0,
  145. 'max' => 9999,
  146. }
  147. end
  148. end
  149. factory :object_manager_attribute_boolean, parent: :object_manager_attribute do
  150. default { false }
  151. data_type { 'boolean' }
  152. data_option do
  153. {
  154. default: default,
  155. options: {
  156. true => 'yes',
  157. false => 'no',
  158. }
  159. }
  160. end
  161. end
  162. factory :object_manager_attribute_date, parent: :object_manager_attribute do
  163. default { 24 }
  164. name { 'date_attribute' }
  165. data_type { 'date' }
  166. data_option do
  167. {
  168. 'diff' => default,
  169. 'null' => true,
  170. }
  171. end
  172. end
  173. factory :object_manager_attribute_datetime, parent: :object_manager_attribute do
  174. default { 24 }
  175. name { 'datetime_attribute' }
  176. data_type { 'datetime' }
  177. data_option do
  178. {
  179. 'future' => true,
  180. 'past' => true,
  181. 'diff' => default,
  182. 'null' => true,
  183. }
  184. end
  185. end
  186. factory :object_manager_attribute_select, parent: :object_manager_attribute do
  187. transient do
  188. data_option_options do
  189. {
  190. 'key_1' => 'value_1',
  191. 'key_2' => 'value_2',
  192. 'key_3' => 'value_3',
  193. }
  194. end
  195. end
  196. default { '' }
  197. data_type { 'select' }
  198. data_option do
  199. {
  200. 'default' => default,
  201. 'options' => data_option_options,
  202. 'relation' => '',
  203. 'nulloption' => true,
  204. 'multiple' => false,
  205. 'null' => true,
  206. 'translate' => true,
  207. 'maxlength' => 255
  208. }
  209. end
  210. end
  211. factory :object_manager_attribute_multiselect, parent: :object_manager_attribute do
  212. transient do
  213. data_option_options do
  214. {
  215. 'key_1' => 'value_1',
  216. 'key_2' => 'value_2',
  217. 'key_3' => 'value_3',
  218. }
  219. end
  220. end
  221. default { [] }
  222. data_type { 'multiselect' }
  223. data_option do
  224. {
  225. 'default' => default,
  226. 'options' => data_option_options,
  227. 'relation' => '',
  228. 'nulloption' => true,
  229. 'multiple' => true,
  230. 'null' => true,
  231. 'translate' => true,
  232. 'maxlength' => 255
  233. }
  234. end
  235. end
  236. factory :object_manager_attribute_tree_select, parent: :object_manager_attribute do
  237. default { '' }
  238. data_type { 'tree_select' }
  239. data_option do
  240. {
  241. 'options' => [
  242. {
  243. 'name' => 'Incident',
  244. 'value' => 'Incident',
  245. 'children' => [
  246. {
  247. 'name' => 'Hardware',
  248. 'value' => 'Incident::Hardware',
  249. 'children' => [
  250. {
  251. 'name' => 'Monitor',
  252. 'value' => 'Incident::Hardware::Monitor'
  253. },
  254. {
  255. 'name' => 'Mouse',
  256. 'value' => 'Incident::Hardware::Mouse'
  257. },
  258. {
  259. 'name' => 'Keyboard',
  260. 'value' => 'Incident::Hardware::Keyboard'
  261. }
  262. ]
  263. },
  264. {
  265. 'name' => 'Softwareproblem',
  266. 'value' => 'Incident::Softwareproblem',
  267. 'children' => [
  268. {
  269. 'name' => 'CRM',
  270. 'value' => 'Incident::Softwareproblem::CRM'
  271. },
  272. {
  273. 'name' => 'EDI',
  274. 'value' => 'Incident::Softwareproblem::EDI'
  275. },
  276. {
  277. 'name' => 'SAP',
  278. 'value' => 'Incident::Softwareproblem::SAP',
  279. 'children' => [
  280. {
  281. 'name' => 'Authentication',
  282. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  283. },
  284. {
  285. 'name' => 'Not reachable',
  286. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  287. }
  288. ]
  289. },
  290. {
  291. 'name' => 'MS Office',
  292. 'value' => 'Incident::Softwareproblem::MS Office',
  293. 'children' => [
  294. {
  295. 'name' => 'Excel',
  296. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  297. },
  298. {
  299. 'name' => 'PowerPoint',
  300. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  301. },
  302. {
  303. 'name' => 'Word',
  304. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  305. },
  306. {
  307. 'name' => 'Outlook',
  308. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  309. }
  310. ]
  311. }
  312. ]
  313. }
  314. ]
  315. },
  316. {
  317. 'name' => 'Service request',
  318. 'value' => 'Service request',
  319. 'children' => [
  320. {
  321. 'name' => 'New software requirement',
  322. 'value' => 'Service request::New software requirement'
  323. },
  324. {
  325. 'name' => 'New hardware',
  326. 'value' => 'Service request::New hardware'
  327. },
  328. {
  329. 'name' => 'Consulting',
  330. 'value' => 'Service request::Consulting'
  331. }
  332. ]
  333. },
  334. {
  335. 'name' => 'Change request',
  336. 'value' => 'Change request'
  337. }
  338. ],
  339. 'default' => '',
  340. 'null' => true,
  341. 'relation' => '',
  342. 'maxlength' => 255,
  343. 'nulloption' => true,
  344. }
  345. end
  346. end
  347. factory :object_manager_attribute_multi_tree_select, parent: :object_manager_attribute do
  348. default { [] }
  349. data_type { 'multi_tree_select' }
  350. data_option do
  351. {
  352. 'options' => [
  353. {
  354. 'name' => 'Incident',
  355. 'value' => 'Incident',
  356. 'children' => [
  357. {
  358. 'name' => 'Hardware',
  359. 'value' => 'Incident::Hardware',
  360. 'children' => [
  361. {
  362. 'name' => 'Monitor',
  363. 'value' => 'Incident::Hardware::Monitor'
  364. },
  365. {
  366. 'name' => 'Mouse',
  367. 'value' => 'Incident::Hardware::Mouse'
  368. },
  369. {
  370. 'name' => 'Keyboard',
  371. 'value' => 'Incident::Hardware::Keyboard'
  372. }
  373. ]
  374. },
  375. {
  376. 'name' => 'Softwareproblem',
  377. 'value' => 'Incident::Softwareproblem',
  378. 'children' => [
  379. {
  380. 'name' => 'CRM',
  381. 'value' => 'Incident::Softwareproblem::CRM'
  382. },
  383. {
  384. 'name' => 'EDI',
  385. 'value' => 'Incident::Softwareproblem::EDI'
  386. },
  387. {
  388. 'name' => 'SAP',
  389. 'value' => 'Incident::Softwareproblem::SAP',
  390. 'children' => [
  391. {
  392. 'name' => 'Authentication',
  393. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  394. },
  395. {
  396. 'name' => 'Not reachable',
  397. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  398. }
  399. ]
  400. },
  401. {
  402. 'name' => 'MS Office',
  403. 'value' => 'Incident::Softwareproblem::MS Office',
  404. 'children' => [
  405. {
  406. 'name' => 'Excel',
  407. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  408. },
  409. {
  410. 'name' => 'PowerPoint',
  411. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  412. },
  413. {
  414. 'name' => 'Word',
  415. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  416. },
  417. {
  418. 'name' => 'Outlook',
  419. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  420. }
  421. ]
  422. }
  423. ]
  424. }
  425. ]
  426. },
  427. {
  428. 'name' => 'Service request',
  429. 'value' => 'Service request',
  430. 'children' => [
  431. {
  432. 'name' => 'New software requirement',
  433. 'value' => 'Service request::New software requirement'
  434. },
  435. {
  436. 'name' => 'New hardware',
  437. 'value' => 'Service request::New hardware'
  438. },
  439. {
  440. 'name' => 'Consulting',
  441. 'value' => 'Service request::Consulting'
  442. }
  443. ]
  444. },
  445. {
  446. 'name' => 'Change request',
  447. 'value' => 'Change request'
  448. }
  449. ],
  450. 'default' => '',
  451. 'null' => true,
  452. 'relation' => '',
  453. 'maxlength' => 255,
  454. 'nulloption' => true,
  455. 'multiple' => true,
  456. }
  457. end
  458. end
  459. factory :object_manager_attribute_user_autocompletion, parent: :object_manager_attribute do
  460. default { '' }
  461. data_type { 'user_autocompletion' }
  462. data_option do
  463. {
  464. 'relation' => 'User',
  465. 'autocapitalize' => false,
  466. 'multiple' => false,
  467. 'guess' => true,
  468. 'null' => false,
  469. 'limit' => 200,
  470. 'placeholder' => 'Enter Person or Organization/Company',
  471. 'minLengt' => 2,
  472. 'translate' => false,
  473. 'permission' => ['ticket.agent']
  474. }
  475. end
  476. end
  477. factory :object_manager_attribute_organization_autocompletion, parent: :object_manager_attribute do
  478. default { '' }
  479. data_type { 'autocompletion_ajax_customer_organization' }
  480. data_option do
  481. {
  482. 'relation' => 'Organization',
  483. 'autocapitalize' => false,
  484. 'multiple' => false,
  485. 'null' => true,
  486. 'translate' => false,
  487. 'permission' => ['ticket.agent', 'ticket.customer']
  488. }
  489. end
  490. end
  491. factory :object_manager_attribute_autocompletion_ajax_external_data_source, parent: :object_manager_attribute do
  492. transient do
  493. search_url { 'http://example.search?q=#{search.term}' } # rubocop:disable Lint/InterpolationCheck
  494. list_key { 'list' }
  495. value_key { 'id' }
  496. label_key { 'name' }
  497. linktemplate { '' }
  498. end
  499. default { [] }
  500. data_type { 'autocompletion_ajax_external_data_source' }
  501. data_option do
  502. {
  503. 'null' => true,
  504. 'search_url' => search_url,
  505. 'search_result_list_key' => list_key,
  506. 'search_result_value_key' => value_key,
  507. 'search_result_label_key' => label_key,
  508. 'linktemplate' => linktemplate,
  509. }
  510. end
  511. trait :elastic_search do
  512. transient do
  513. search_url { "#{Setting.get('es_url')}/#{Setting.get('es_index')}_test_user/_search?q=\#{search.term}&sort=id" }
  514. list_key { 'hits.hits' }
  515. value_key { '_id' }
  516. label_key { '_source.email' }
  517. linktemplate { "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#user/profile/\#{#{object_name.downcase}.#{name}}" }
  518. end
  519. end
  520. end
  521. end