"Fossies" - the Fresh Open Source Software Archive

Member "db/migrate/20170403000001_fixed_admin_user_permission_920.rb" (25 Mar 2021, 19099 Bytes) of package /linux/www/zammad-4.0.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "20170403000001_fixed_admin_user_permission_920.rb": 3.4.1_vs_3.5.0.

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