RT ACL for freeside-daily, #13853
authormark <mark>
Fri, 7 Oct 2011 23:20:13 +0000 (23:20 +0000)
committermark <mark>
Fri, 7 Oct 2011 23:20:13 +0000 (23:20 +0000)
FS/FS/Cron/rt_tasks.pm
FS/FS/TicketSystem.pm

index 6658b47..4977eb2 100644 (file)
@@ -31,7 +31,6 @@ sub rt_daily {
   my $system = $FS::TicketSystem::system;
   return if $system ne 'RT_Internal';
 
-  FS::TicketSystem->init;
   $DEBUG = 1 if $opt{'v'};
   RT::Config->Set( LogToScreen => 'debug' ) if $DEBUG;
  
@@ -42,6 +41,7 @@ sub rt_daily {
     return;
   }
 
+  FS::TicketSystem->init;
   my $session = FS::TicketSystem->session();
   my $CurrentUser = $session->{'CurrentUser'}
     or die "Failed to create RT session";
@@ -69,7 +69,6 @@ sub rt_daily {
   $queues->UnLimit;
   while (my $queue = $queues->Next) {
     warn "Queue '".$queue->Name."'\n" if $DEBUG;
-    my $CurrentUser = $queue->CurrentUser;
     my %opt = @_;
     my $tickets = RT::Tickets->new($CurrentUser);
     my $search = RT::Search::ActiveTicketsInQueue->new(
index b6cee41..77d0dae 100644 (file)
@@ -87,29 +87,31 @@ sub _upgrade_data {
   # bypass RT ACLs--we're going to do lots of things
   my $CurrentUser = $RT::SystemUser;
 
-  # selfservice user
-  my $User = RT::User->new($CurrentUser);
-  $User->Load('%%%SELFSERVICE_USER%%%');
-  if (!defined($User->Id)) {
-    my ($val, $msg) = $User->Create(
-      'Name' => '%%%SELFSERVICE_USER%%%',
-      'Gecos' => '%%%SELFSERVICE_USER%%%',
-      'Privileged' => 1,
-      # any other fields needed?
-    );
-    die $msg if !$val;
-  }
-  my $Principal = $User->PrincipalObj; # can this ever fail?
-  my @rights = ( qw(ShowTicket SeeQueue ModifyTicket ReplyToTicket 
-                    CreateTicket SeeCustomField) );
-  foreach (@rights) {
-    next if $Principal->HasRight( 'Right' => $_, Object => $RT::System );
-    my ($val, $msg) = $Principal->GrantRight(
-      'Right' => $_,
-      'Object' => $RT::System,
-    );
-    die $msg if !$val;
-  }
+  # selfservice and cron users
+  foreach my $username ('%%%SELFSERVICE_USER', 'fs_daily') {
+    my $User = RT::User->new($CurrentUser);
+    $User->Load($username);
+    if (!defined($User->Id)) {
+      my ($val, $msg) = $User->Create(
+        'Name' => $username,
+        'Gecos' => $username,
+        'Privileged' => 1,
+        # any other fields needed?
+      );
+      die $msg if !$val;
+    }
+    my $Principal = $User->PrincipalObj; # can this ever fail?
+    my @rights = ( qw(ShowTicket SeeQueue ModifyTicket ReplyToTicket 
+                      CreateTicket SeeCustomField) );
+    foreach (@rights) {
+      next if $Principal->HasRight( 'Right' => $_, Object => $RT::System );
+      my ($val, $msg) = $Principal->GrantRight(
+        'Right' => $_,
+        'Object' => $RT::System,
+      );
+      die $msg if !$val;
+    }
+  } #foreach $username
 
   # EscalateQueue custom field and friends
   my $CF = RT::CustomField->new($CurrentUser);