object_manager_attribute.rb 7.7 KB

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