20170403000001_fixed_admin_user_permission_920.rb 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. # rubocop:disable Lint/BooleanSymbol
  2. class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.find_by(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. 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. ObjectManager::Attribute.add(
  362. force: true,
  363. object: 'TicketArticle',
  364. name: 'to',
  365. display: 'To',
  366. data_type: 'input',
  367. data_option: {
  368. type: 'text',
  369. maxlength: 1000,
  370. null: true,
  371. },
  372. editable: false,
  373. active: true,
  374. screens: {
  375. create_middle: {},
  376. edit: {
  377. 'ticket.agent' => {
  378. null: true,
  379. },
  380. },
  381. },
  382. to_create: false,
  383. to_migrate: false,
  384. to_delete: false,
  385. position: 300,
  386. )
  387. ObjectManager::Attribute.add(
  388. force: true,
  389. object: 'TicketArticle',
  390. name: 'cc',
  391. display: 'Cc',
  392. data_type: 'input',
  393. data_option: {
  394. type: 'text',
  395. maxlength: 1000,
  396. null: true,
  397. },
  398. editable: false,
  399. active: true,
  400. screens: {
  401. create_top: {},
  402. create_middle: {},
  403. edit: {
  404. 'ticket.agent' => {
  405. null: true,
  406. },
  407. },
  408. },
  409. to_create: false,
  410. to_migrate: false,
  411. to_delete: false,
  412. position: 400,
  413. )
  414. ObjectManager::Attribute.add(
  415. force: true,
  416. object: 'TicketArticle',
  417. name: 'body',
  418. display: 'Text',
  419. data_type: 'richtext',
  420. data_option: {
  421. type: 'richtext',
  422. maxlength: 20_000,
  423. upload: true,
  424. rows: 8,
  425. null: true,
  426. },
  427. editable: false,
  428. active: true,
  429. screens: {
  430. create_top: {
  431. '-all-' => {
  432. null: false,
  433. },
  434. },
  435. edit: {
  436. '-all-' => {
  437. null: true,
  438. },
  439. },
  440. },
  441. to_create: false,
  442. to_migrate: false,
  443. to_delete: false,
  444. position: 600,
  445. )
  446. ObjectManager::Attribute.add(
  447. force: true,
  448. object: 'User',
  449. name: 'password',
  450. display: 'Password',
  451. data_type: 'input',
  452. data_option: {
  453. type: 'password',
  454. maxlength: 100,
  455. null: true,
  456. autocomplete: 'off',
  457. item_class: 'formGroup--halfSize',
  458. },
  459. editable: false,
  460. active: true,
  461. screens: {
  462. signup: {
  463. '-all-' => {
  464. null: false,
  465. },
  466. },
  467. invite_agent: {},
  468. invite_customer: {},
  469. edit: {
  470. 'admin.user' => {
  471. null: true,
  472. },
  473. },
  474. view: {}
  475. },
  476. to_create: false,
  477. to_migrate: false,
  478. to_delete: false,
  479. position: 1400,
  480. )
  481. ObjectManager::Attribute.add(
  482. force: true,
  483. object: 'User',
  484. name: 'vip',
  485. display: 'VIP',
  486. data_type: 'boolean',
  487. data_option: {
  488. null: true,
  489. default: false,
  490. item_class: 'formGroup--halfSize',
  491. options: {
  492. false: 'no',
  493. true: 'yes',
  494. },
  495. translate: true,
  496. permission: ['admin.user', 'ticket.agent'],
  497. },
  498. editable: false,
  499. active: true,
  500. screens: {
  501. edit: {
  502. '-all-' => {
  503. null: true,
  504. },
  505. },
  506. view: {
  507. '-all-' => {
  508. shown: false,
  509. },
  510. },
  511. },
  512. to_create: false,
  513. to_migrate: false,
  514. to_delete: false,
  515. position: 1490,
  516. )
  517. ObjectManager::Attribute.add(
  518. force: true,
  519. object: 'User',
  520. name: 'role_ids',
  521. display: 'Permissions',
  522. data_type: 'user_permission',
  523. data_option: {
  524. null: false,
  525. item_class: 'checkbox',
  526. permission: ['admin.user'],
  527. },
  528. editable: false,
  529. active: true,
  530. screens: {
  531. signup: {},
  532. invite_agent: {
  533. '-all-' => {
  534. null: false,
  535. default: [Role.lookup(name: 'Agent').id],
  536. },
  537. },
  538. invite_customer: {},
  539. edit: {
  540. '-all-' => {
  541. null: true,
  542. },
  543. },
  544. view: {
  545. '-all-' => {
  546. shown: false,
  547. },
  548. },
  549. },
  550. to_create: false,
  551. to_migrate: false,
  552. to_delete: false,
  553. position: 1600,
  554. )
  555. ObjectManager::Attribute.add(
  556. force: true,
  557. object: 'User',
  558. name: 'active',
  559. display: 'Active',
  560. data_type: 'active',
  561. data_option: {
  562. null: true,
  563. default: true,
  564. permission: ['admin.user', 'ticket.agent'],
  565. },
  566. editable: false,
  567. active: true,
  568. screens: {
  569. signup: {},
  570. invite_agent: {},
  571. invite_customer: {},
  572. edit: {
  573. '-all-' => {
  574. null: false,
  575. },
  576. },
  577. view: {
  578. '-all-' => {
  579. shown: false,
  580. },
  581. },
  582. },
  583. to_create: false,
  584. to_migrate: false,
  585. to_delete: false,
  586. position: 1800,
  587. )
  588. ObjectManager::Attribute.add(
  589. force: true,
  590. object: 'Organization',
  591. name: 'shared',
  592. display: 'Shared organization',
  593. data_type: 'boolean',
  594. data_option: {
  595. null: true,
  596. default: true,
  597. note: 'Customers in the organization can view each other items.',
  598. item_class: 'formGroup--halfSize',
  599. options: {
  600. true: 'yes',
  601. false: 'no',
  602. },
  603. translate: true,
  604. permission: ['admin.organization'],
  605. },
  606. editable: false,
  607. active: true,
  608. screens: {
  609. edit: {
  610. '-all-' => {
  611. null: false,
  612. },
  613. },
  614. view: {
  615. '-all-' => {
  616. shown: true,
  617. },
  618. },
  619. },
  620. to_create: false,
  621. to_migrate: false,
  622. to_delete: false,
  623. position: 1400,
  624. )
  625. ObjectManager::Attribute.add(
  626. force: true,
  627. object: 'Organization',
  628. name: 'domain_assignment',
  629. display: 'Domain based assignment',
  630. data_type: 'boolean',
  631. data_option: {
  632. null: true,
  633. default: false,
  634. note: 'Assign Users based on users domain.',
  635. item_class: 'formGroup--halfSize',
  636. options: {
  637. true: 'yes',
  638. false: 'no',
  639. },
  640. translate: true,
  641. permission: ['admin.organization'],
  642. },
  643. editable: false,
  644. active: true,
  645. screens: {
  646. edit: {
  647. '-all-' => {
  648. null: false,
  649. },
  650. },
  651. view: {
  652. '-all-' => {
  653. shown: true,
  654. },
  655. },
  656. },
  657. to_create: false,
  658. to_migrate: false,
  659. to_delete: false,
  660. position: 1410,
  661. )
  662. ObjectManager::Attribute.add(
  663. force: true,
  664. object: 'Organization',
  665. name: 'active',
  666. display: 'Active',
  667. data_type: 'active',
  668. data_option: {
  669. null: true,
  670. default: true,
  671. permission: ['admin.organization'],
  672. },
  673. editable: false,
  674. active: true,
  675. screens: {
  676. edit: {
  677. '-all-' => {
  678. null: false,
  679. },
  680. },
  681. view: {
  682. '-all-' => {
  683. shown: false,
  684. },
  685. },
  686. },
  687. to_create: false,
  688. to_migrate: false,
  689. to_delete: false,
  690. position: 1800,
  691. )
  692. ObjectManager::Attribute.add(
  693. force: true,
  694. object: 'Group',
  695. name: 'active',
  696. display: 'Active',
  697. data_type: 'active',
  698. data_option: {
  699. null: true,
  700. default: true,
  701. permission: ['admin.group'],
  702. },
  703. editable: false,
  704. active: true,
  705. screens: {
  706. create: {
  707. '-all-' => {
  708. null: true,
  709. },
  710. },
  711. edit: {
  712. '-all-': {
  713. null: false,
  714. },
  715. },
  716. view: {
  717. '-all-' => {
  718. shown: false,
  719. },
  720. },
  721. },
  722. to_create: false,
  723. to_migrate: false,
  724. to_delete: false,
  725. position: 1800,
  726. )
  727. map = {
  728. Admin: 'admin',
  729. Agent: 'ticket.agent',
  730. Customer: 'ticket.customer',
  731. }
  732. ObjectManager::Attribute.all.each do |attribute|
  733. next if attribute.screens.blank?
  734. screens = {}
  735. attribute.screens.each do |screen, role_value|
  736. if role_value.blank?
  737. screens[screen] = role_value
  738. else
  739. screens[screen] = {}
  740. role_value.each do |role, value|
  741. if map[role.to_sym]
  742. screens[screen][map[role.to_sym]] = value
  743. else
  744. screens[screen][role] = value
  745. end
  746. end
  747. end
  748. end
  749. attribute.screens = screens
  750. attribute.save!
  751. end
  752. end
  753. end