fix ACL upgrade, RT#17056
[freeside.git] / FS / FS / access_right.pm
index 341055b..fc01746 100644 (file)
@@ -183,18 +183,45 @@ sub _upgrade_data { # class method
   my @all_groups = qsearch('access_group', {});
 
   my %onetime = (
-    'List customers' => 'List all customers',
-    'List packages'  => 'Summarize packages',
+    'List customers'   => 'List all customers',
+    'List packages'    => 'Summarize packages',
+    'Post payment'     => 'Backdate payment',
+    'List services'    => [ 'Services: Accounts',
+                            'Services: Domains',
+                            'Services: Certificates',
+                            'Services: Mail forwards',
+                            'Services: Virtual hosting services',
+                            'Services: Wireless broadband services',
+                            'Services: DSLs',
+                            'Services: Dish services',
+                            'Services: Hardware',
+                            'Services: Phone numbers',
+                            'Services: PBXs',
+                            'Services: Ports',
+                            'Services: Mailing lists',
+                            'Services: External services',
+                          ],
+    'List rating data' => [ 'Usage: RADIUS sessions',
+                            'Usage: Call Detail Records (CDRs)',
+                            'Usage: Unrateable CDRs',
+                          ],
   );
 
   foreach my $old_acl ( keys %onetime ) {
-    my $new_acl = $onetime{$old_acl}; #support arrayref too?
-    ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/ /_/g;
-    next if FS::upgrade_journal->is_done($journal);
 
-    # grant $new_acl to all groups who have $old_acl
-    for my $group (@all_groups) {
-      if ( $group->access_right($old_acl) ) {
+    my @new_acl = ref($onetime{$old_acl})
+                    ? @{ $onetime{$old_acl} }
+                    :  ( $onetime{$old_acl} );
+
+    foreach my $new_acl ( @new_acl ) {
+
+      ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/\W/_/g;
+      next if FS::upgrade_journal->is_done($journal);
+
+      # grant $new_acl to all groups who have $old_acl
+      for my $group (@all_groups) {
+        next unless $group->access_right($old_acl);
+        next if     $group->access_right($new_acl);
         my $access_right = FS::access_right->new( {
             'righttype'   => 'FS::access_group',
             'rightobjnum' => $group->groupnum,
@@ -203,9 +230,11 @@ sub _upgrade_data { # class method
         my $error = $access_right->insert;
         die $error if $error;
       }
-    }
     
-    FS::upgrade_journal->set_done($journal);
+      FS::upgrade_journal->set_done($journal);
+
+    }
+
   }
 
   ### ACL_download_report_data