auto-create selfservice user in RT, #13199
authormark <mark>
Fri, 8 Jul 2011 22:17:29 +0000 (22:17 +0000)
committermark <mark>
Fri, 8 Jul 2011 22:17:29 +0000 (22:17 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/TicketSystem.pm
Makefile

index a788a5c..014434a 100644 (file)
@@ -321,7 +321,7 @@ sub customer_info {
     $return{'require_address2'} = '';
   }
 
-  if ( $conf->exists('ticket_system') ) {
+  if ( $FS::TicketSystem::system ) {
     warn "$me customer_info: initializing ticket system\n" if $DEBUG;
     FS::TicketSystem->init();
   }
index 9d11ff4..a6daf7e 100644 (file)
@@ -35,8 +35,31 @@ sub _upgrade_data {
   
   FS::TicketSystem->init;
   my $session = FS::TicketSystem->session();
-  my $CurrentUser = $session->{'CurrentUser'}
-    or die 'freeside-upgrade must run as a valid RT user';
+  # 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) );
+  foreach (@rights) {
+    next if $Principal->HasRight( 'Right' => $_, Object => $RT::System );
+    my ($val, $msg) = $Principal->GrantRight(
+      'Right' => $_,
+      'Object' => $RT::System,
+    );
+    die $msg if !$val;
+  }
 
   # EscalateQueue custom field and friends
   my $CF = RT::CustomField->new($CurrentUser);
index f743797..a454d08 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -193,6 +193,7 @@ perl-modules:
          s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
          s'%%%RT_PATH%%%'${RT_PATH}'g; \
          s'%%%MASONDATA%%%'${MASONDATA}'g;\
+         s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
        " blib/lib/FS/*.pm;\
        perl -p -i -e "\
          s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\