20170403000001_fixed_admin_user_permission_920.rb 19 KB

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