support one right to many rights one-time upgrade, RT#17056
[freeside.git] / FS / FS / access_right.pm
index d2a39aa..815c6d9 100644 (file)
@@ -182,23 +182,39 @@ sub _upgrade_data { # class method
 
   my @all_groups = qsearch('access_group', {});
 
-  ### ACL_list_all_customers
-  if ( !FS::upgrade_journal->is_done('ACL_list_all_customers') ) {
+  my %onetime = (
+    'List customers' => 'List all customers',
+    'List packages'  => 'Summarize packages',
+  );
 
-    # grant "List all customers" to all users who have "List customers"
-    for my $group (@all_groups) {
-      if ( $group->access_right('List customers') ) {
-        my $access_right = FS::access_right->new( {
-            'righttype'   => 'FS::access_group',
-            'rightobjnum' => $group->groupnum,
-            'rightname'   => 'List all customers',
-        } );
-        my $error = $access_right->insert;
-        die $error if $error;
+  foreach my $old_acl ( keys %onetime ) {
+
+    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/ /_/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 $access_right = FS::access_right->new( {
+              'righttype'   => 'FS::access_group',
+              'rightobjnum' => $group->groupnum,
+              'rightname'   => $new_acl,
+          } );
+          my $error = $access_right->insert;
+          die $error if $error;
+        }
       }
-    }
     
-    FS::upgrade_journal->set_done('ACL_list_all_customers');
+      FS::upgrade_journal->set_done($journal);
+
+    }
+
   }
 
   ### ACL_download_report_data