20170403000001_fixed_admin_user_permission_920.rb 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. ObjectManager::Attribute.add(
  7. force: true,
  8. object: 'Ticket',
  9. name: 'customer_id',
  10. display: 'Customer',
  11. data_type: 'user_autocompletion',
  12. data_option: {
  13. relation: 'User',
  14. autocapitalize: false,
  15. multiple: false,
  16. guess: true,
  17. null: false,
  18. limit: 200,
  19. placeholder: 'Enter Person or Organization/Company',
  20. minLengt: 2,
  21. translate: false,
  22. permission: ['ticket.agent'],
  23. },
  24. editable: false,
  25. active: true,
  26. screens: {
  27. create_top: {
  28. '-all-' => {
  29. null: false,
  30. },
  31. },
  32. edit: {},
  33. },
  34. to_create: false,
  35. to_migrate: false,
  36. to_delete: false,
  37. position: 10,
  38. )
  39. ObjectManager::Attribute.add(
  40. force: true,
  41. object: 'Ticket',
  42. name: 'type',
  43. display: 'Type',
  44. data_type: 'select',
  45. data_option: {
  46. default: '',
  47. options: {
  48. 'Incident' => 'Incident',
  49. 'Problem' => 'Problem',
  50. 'Request for Change' => 'Request for Change',
  51. },
  52. nulloption: true,
  53. multiple: false,
  54. null: true,
  55. translate: true,
  56. },
  57. editable: true,
  58. active: false,
  59. screens: {
  60. create_middle: {
  61. '-all-' => {
  62. null: false,
  63. item_class: 'column',
  64. },
  65. },
  66. edit: {
  67. 'ticket.agent' => {
  68. null: false,
  69. },
  70. },
  71. },
  72. to_create: false,
  73. to_migrate: false,
  74. to_delete: false,
  75. position: 20,
  76. )
  77. ObjectManager::Attribute.add(
  78. force: true,
  79. object: 'Ticket',
  80. name: 'group_id',
  81. display: 'Group',
  82. data_type: 'select',
  83. data_option: {
  84. default: '',
  85. relation: 'Group',
  86. relation_condition: { access: 'full' },
  87. nulloption: true,
  88. multiple: false,
  89. null: false,
  90. translate: false,
  91. only_shown_if_selectable: true,
  92. permission: ['ticket.agent', 'ticket.customer'],
  93. },
  94. editable: false,
  95. active: true,
  96. screens: {
  97. create_middle: {
  98. '-all-' => {
  99. null: false,
  100. item_class: 'column',
  101. },
  102. },
  103. edit: {
  104. 'ticket.agent' => {
  105. null: false,
  106. },
  107. },
  108. },
  109. to_create: false,
  110. to_migrate: false,
  111. to_delete: false,
  112. position: 25,
  113. )
  114. ObjectManager::Attribute.add(
  115. force: true,
  116. object: 'Ticket',
  117. name: 'owner_id',
  118. display: 'Owner',
  119. data_type: 'select',
  120. data_option: {
  121. default: '',
  122. relation: 'User',
  123. relation_condition: { roles: 'Agent' },
  124. nulloption: true,
  125. multiple: false,
  126. null: true,
  127. translate: false,
  128. permission: ['ticket.agent'],
  129. },
  130. editable: false,
  131. active: true,
  132. screens: {
  133. create_middle: {
  134. '-all-' => {
  135. null: true,
  136. item_class: 'column',
  137. },
  138. },
  139. edit: {
  140. '-all-' => {
  141. null: true,
  142. },
  143. },
  144. },
  145. to_create: false,
  146. to_migrate: false,
  147. to_delete: false,
  148. position: 30,
  149. )
  150. ObjectManager::Attribute.add(
  151. force: true,
  152. object: 'Ticket',
  153. name: 'state_id',
  154. display: 'State',
  155. data_type: 'select',
  156. data_option: {
  157. relation: 'TicketState',
  158. nulloption: true,
  159. multiple: false,
  160. null: false,
  161. default: Ticket::State.find_by(default_follow_up: true).id,
  162. translate: true,
  163. filter: Ticket::State.by_category(:viewable).pluck(:id),
  164. },
  165. editable: false,
  166. active: true,
  167. screens: {
  168. create_middle: {
  169. 'ticket.agent' => {
  170. null: false,
  171. item_class: 'column',
  172. filter: Ticket::State.by_category(:viewable_agent_new).pluck(:id),
  173. },
  174. 'ticket.customer' => {
  175. item_class: 'column',
  176. nulloption: false,
  177. null: true,
  178. filter: Ticket::State.by_category(:viewable_customer_new).pluck(:id),
  179. default: Ticket::State.find_by(name: 'new').id,
  180. },
  181. },
  182. edit: {
  183. 'ticket.agent' => {
  184. nulloption: false,
  185. null: false,
  186. filter: Ticket::State.by_category(:viewable_agent_edit).pluck(:id),
  187. },
  188. 'ticket.customer' => {
  189. nulloption: false,
  190. null: true,
  191. filter: Ticket::State.by_category(:viewable_customer_edit).pluck(:id),
  192. default: Ticket::State.find_by(name: 'open').id,
  193. },
  194. },
  195. },
  196. to_create: false,
  197. to_migrate: false,
  198. to_delete: false,
  199. position: 40,
  200. )
  201. ObjectManager::Attribute.add(
  202. force: true,
  203. object: 'Ticket',
  204. name: 'pending_time',
  205. display: 'Pending till',
  206. data_type: 'datetime',
  207. data_option: {
  208. future: true,
  209. past: false,
  210. diff: 24,
  211. null: true,
  212. translate: true,
  213. required_if: {
  214. state_id: Ticket::State.by_category(:pending).pluck(:id),
  215. },
  216. shown_if: {
  217. state_id: Ticket::State.by_category(:pending).pluck(:id),
  218. },
  219. },
  220. editable: false,
  221. active: true,
  222. screens: {
  223. create_middle: {
  224. '-all-' => {
  225. null: false,
  226. item_class: 'column',
  227. },
  228. },
  229. edit: {
  230. '-all-' => {
  231. null: false,
  232. },
  233. },
  234. },
  235. to_create: false,
  236. to_migrate: false,
  237. to_delete: false,
  238. position: 41,
  239. )
  240. ObjectManager::Attribute.add(
  241. force: true,
  242. object: 'Ticket',
  243. name: 'priority_id',
  244. display: 'Priority',
  245. data_type: 'select',
  246. data_option: {
  247. relation: 'TicketPriority',
  248. nulloption: false,
  249. multiple: false,
  250. null: false,
  251. default: Ticket::Priority.find_by(default_create: true).id,
  252. translate: true,
  253. },
  254. editable: false,
  255. active: true,
  256. screens: {
  257. create_middle: {
  258. 'ticket.agent' => {
  259. null: false,
  260. item_class: 'column',
  261. },
  262. },
  263. edit: {
  264. 'ticket.agent' => {
  265. null: false,
  266. },
  267. },
  268. },
  269. to_create: false,
  270. to_migrate: false,
  271. to_delete: false,
  272. position: 80,
  273. )
  274. ObjectManager::Attribute.add(
  275. force: true,
  276. object: 'Ticket',
  277. name: 'tags',
  278. display: 'Tags',
  279. data_type: 'tag',
  280. data_option: {
  281. type: 'text',
  282. null: true,
  283. translate: false,
  284. },
  285. editable: false,
  286. active: true,
  287. screens: {
  288. create_bottom: {
  289. 'ticket.agent' => {
  290. null: true,
  291. },
  292. },
  293. edit: {},
  294. },
  295. to_create: false,
  296. to_migrate: false,
  297. to_delete: false,
  298. position: 900,
  299. )
  300. ObjectManager::Attribute.add(
  301. force: true,
  302. object: 'TicketArticle',
  303. name: 'type_id',
  304. display: 'Type',
  305. data_type: 'select',
  306. data_option: {
  307. relation: 'TicketArticleType',
  308. nulloption: false,
  309. multiple: false,
  310. null: false,
  311. default: Ticket::Article::Type.lookup(name: 'note').id,
  312. translate: true,
  313. },
  314. editable: false,
  315. active: true,
  316. screens: {
  317. create_middle: {},
  318. edit: {
  319. 'ticket.agent' => {
  320. null: false,
  321. },
  322. },
  323. },
  324. to_create: false,
  325. to_migrate: false,
  326. to_delete: false,
  327. position: 100,
  328. )
  329. # rubocop:disable Lint/BooleanSymbol
  330. ObjectManager::Attribute.add(
  331. force: true,
  332. object: 'TicketArticle',
  333. name: 'internal',
  334. display: 'Visibility',
  335. data_type: 'select',
  336. data_option: {
  337. options: {
  338. true: 'internal',
  339. false: 'public'
  340. },
  341. nulloption: false,
  342. multiple: false,
  343. null: true,
  344. default: false,
  345. translate: true,
  346. },
  347. editable: false,
  348. active: true,
  349. screens: {
  350. create_middle: {},
  351. edit: {
  352. 'ticket.agent' => {
  353. null: false,
  354. },
  355. },
  356. },
  357. to_create: false,
  358. to_migrate: false,
  359. to_delete: false,
  360. position: 200,
  361. )
  362. # rubocop:enable Lint/BooleanSymbol
  363. ObjectManager::Attribute.add(
  364. force: true,
  365. object: 'TicketArticle',
  366. name: 'to',
  367. display: 'To',
  368. data_type: 'input',
  369. data_option: {
  370. type: 'text',
  371. maxlength: 1000,
  372. null: true,
  373. },
  374. editable: false,
  375. active: true,
  376. screens: {
  377. create_middle: {},
  378. edit: {
  379. 'ticket.agent' => {
  380. null: true,
  381. },
  382. },
  383. },
  384. to_create: false,
  385. to_migrate: false,
  386. to_delete: false,
  387. position: 300,
  388. )
  389. ObjectManager::Attribute.add(
  390. force: true,
  391. object: 'TicketArticle',
  392. name: 'cc',
  393. display: 'Cc',
  394. data_type: 'input',
  395. data_option: {
  396. type: 'text',
  397. maxlength: 1000,
  398. null: true,
  399. },
  400. editable: false,
  401. active: true,
  402. screens: {
  403. create_top: {},
  404. create_middle: {},
  405. edit: {
  406. 'ticket.agent' => {
  407. null: true,
  408. },
  409. },
  410. },
  411. to_create: false,
  412. to_migrate: false,
  413. to_delete: false,
  414. position: 400,
  415. )
  416. ObjectManager::Attribute.add(
  417. force: true,
  418. object: 'TicketArticle',
  419. name: 'body',
  420. display: 'Text',
  421. data_type: 'richtext',
  422. data_option: {
  423. type: 'richtext',
  424. maxlength: 20_000,
  425. upload: true,
  426. rows: 8,
  427. null: true,
  428. },
  429. editable: false,
  430. active: true,
  431. screens: {
  432. create_top: {
  433. '-all-' => {
  434. null: false,
  435. },
  436. },
  437. edit: {
  438. '-all-' => {
  439. null: true,
  440. },
  441. },
  442. },
  443. to_create: false,
  444. to_migrate: false,
  445. to_delete: false,
  446. position: 600,
  447. )
  448. ObjectManager::Attribute.add(
  449. force: true,
  450. object: 'User',
  451. name: 'password',
  452. display: 'Password',
  453. data_type: 'input',
  454. data_option: {
  455. type: 'password',
  456. maxlength: 100,
  457. null: true,
  458. autocomplete: 'off',
  459. item_class: 'formGroup--halfSize',
  460. },
  461. editable: false,
  462. active: true,
  463. screens: {
  464. signup: {
  465. '-all-' => {
  466. null: false,
  467. },
  468. },
  469. invite_agent: {},
  470. invite_customer: {},
  471. edit: {
  472. 'admin.user' => {
  473. null: true,
  474. },
  475. },
  476. view: {}
  477. },
  478. to_create: false,
  479. to_migrate: false,
  480. to_delete: false,
  481. position: 1400,
  482. )
  483. # rubocop:disable Lint/BooleanSymbol
  484. ObjectManager::Attribute.add(
  485. force: true,
  486. object: 'User',
  487. name: 'vip',
  488. display: 'VIP',
  489. data_type: 'boolean',
  490. data_option: {
  491. null: true,
  492. default: false,
  493. item_class: 'formGroup--halfSize',
  494. options: {
  495. false: 'no',
  496. true: 'yes',
  497. },
  498. translate: true,
  499. permission: ['admin.user', 'ticket.agent'],
  500. },
  501. editable: false,
  502. active: true,
  503. screens: {
  504. edit: {
  505. '-all-' => {
  506. null: true,
  507. },
  508. },
  509. view: {
  510. '-all-' => {
  511. shown: false,
  512. },
  513. },
  514. },
  515. to_create: false,
  516. to_migrate: false,
  517. to_delete: false,
  518. position: 1490,
  519. )
  520. # rubocop:enable Lint/BooleanSymbol
  521. ObjectManager::Attribute.add(
  522. force: true,
  523. object: 'User',
  524. name: 'role_ids',
  525. display: 'Permissions',
  526. data_type: 'user_permission',
  527. data_option: {
  528. null: false,
  529. item_class: 'checkbox',
  530. permission: ['admin.user'],
  531. },
  532. editable: false,
  533. active: true,
  534. screens: {
  535. signup: {},
  536. invite_agent: {
  537. '-all-' => {
  538. null: false,
  539. default: [Role.lookup(name: 'Agent').id],
  540. },
  541. },
  542. invite_customer: {},
  543. edit: {
  544. '-all-' => {
  545. null: true,
  546. },
  547. },
  548. view: {
  549. '-all-' => {
  550. shown: false,
  551. },
  552. },
  553. },
  554. to_create: false,
  555. to_migrate: false,
  556. to_delete: false,
  557. position: 1600,
  558. )
  559. ObjectManager::Attribute.add(
  560. force: true,
  561. object: 'User',
  562. name: 'active',
  563. display: 'Active',
  564. data_type: 'active',
  565. data_option: {
  566. null: true,
  567. default: true,
  568. permission: ['admin.user', 'ticket.agent'],
  569. },
  570. editable: false,
  571. active: true,
  572. screens: {
  573. signup: {},
  574. invite_agent: {},
  575. invite_customer: {},
  576. edit: {
  577. '-all-' => {
  578. null: false,
  579. },
  580. },
  581. view: {
  582. '-all-' => {
  583. shown: false,
  584. },
  585. },
  586. },
  587. to_create: false,
  588. to_migrate: false,
  589. to_delete: false,
  590. position: 1800,
  591. )
  592. # rubocop:disable Lint/BooleanSymbol
  593. ObjectManager::Attribute.add(
  594. force: true,
  595. object: 'Organization',
  596. name: 'shared',
  597. display: 'Shared organization',
  598. data_type: 'boolean',
  599. data_option: {
  600. null: true,
  601. default: true,
  602. note: 'Customers in the organization can view each other items.',
  603. item_class: 'formGroup--halfSize',
  604. options: {
  605. true: 'yes',
  606. false: 'no',
  607. },
  608. translate: true,
  609. permission: ['admin.organization'],
  610. },
  611. editable: false,
  612. active: true,
  613. screens: {
  614. edit: {
  615. '-all-' => {
  616. null: false,
  617. },
  618. },
  619. view: {
  620. '-all-' => {
  621. shown: true,
  622. },
  623. },
  624. },
  625. to_create: false,
  626. to_migrate: false,
  627. to_delete: false,
  628. position: 1400,
  629. )
  630. ObjectManager::Attribute.add(
  631. force: true,
  632. object: 'Organization',
  633. name: 'domain_assignment',
  634. display: 'Domain based assignment',
  635. data_type: 'boolean',
  636. data_option: {
  637. null: true,
  638. default: false,
  639. note: 'Assign Users based on users domain.',
  640. item_class: 'formGroup--halfSize',
  641. options: {
  642. true: 'yes',
  643. false: 'no',
  644. },
  645. translate: true,
  646. permission: ['admin.organization'],
  647. },
  648. editable: false,
  649. active: true,
  650. screens: {
  651. edit: {
  652. '-all-' => {
  653. null: false,
  654. },
  655. },
  656. view: {
  657. '-all-' => {
  658. shown: true,
  659. },
  660. },
  661. },
  662. to_create: false,
  663. to_migrate: false,
  664. to_delete: false,
  665. position: 1410,
  666. )
  667. # rubocop:enable Lint/BooleanSymbol
  668. ObjectManager::Attribute.add(
  669. force: true,
  670. object: 'Organization',
  671. name: 'active',
  672. display: 'Active',
  673. data_type: 'active',
  674. data_option: {
  675. null: true,
  676. default: true,
  677. permission: ['admin.organization'],
  678. },
  679. editable: false,
  680. active: true,
  681. screens: {
  682. edit: {
  683. '-all-' => {
  684. null: false,
  685. },
  686. },
  687. view: {
  688. '-all-' => {
  689. shown: false,
  690. },
  691. },
  692. },
  693. to_create: false,
  694. to_migrate: false,
  695. to_delete: false,
  696. position: 1800,
  697. )
  698. ObjectManager::Attribute.add(
  699. force: true,
  700. object: 'Group',
  701. name: 'active',
  702. display: 'Active',
  703. data_type: 'active',
  704. data_option: {
  705. null: true,
  706. default: true,
  707. permission: ['admin.group'],
  708. },
  709. editable: false,
  710. active: true,
  711. screens: {
  712. create: {
  713. '-all-' => {
  714. null: true,
  715. },
  716. },
  717. edit: {
  718. '-all-': {
  719. null: false,
  720. },
  721. },
  722. view: {
  723. '-all-' => {
  724. shown: false,
  725. },
  726. },
  727. },
  728. to_create: false,
  729. to_migrate: false,
  730. to_delete: false,
  731. position: 1800,
  732. )
  733. map = {
  734. Admin: 'admin',
  735. Agent: 'ticket.agent',
  736. Customer: 'ticket.customer',
  737. }
  738. ObjectManager::Attribute.all.each do |attribute|
  739. next if attribute.screens.blank?
  740. screens = {}
  741. attribute.screens.each do |screen, role_value|
  742. if role_value.blank?
  743. screens[screen] = role_value
  744. else
  745. screens[screen] = {}
  746. role_value.each do |role, value|
  747. if map[role.to_sym]
  748. screens[screen][map[role.to_sym]] = value
  749. else
  750. screens[screen][role] = value
  751. end
  752. end
  753. end
  754. end
  755. attribute.screens = screens
  756. attribute.save!
  757. end
  758. end
  759. end