[freeside-commits] branch FREESIDE_4_BRANCH updated. 80b60d8b0c9f18407e8b63ace60a59c9dd70bc9d

Jonathan Prykop jonathan at 420.am
Mon Aug 24 15:42:17 PDT 2015


The branch, FREESIDE_4_BRANCH has been updated
       via  80b60d8b0c9f18407e8b63ace60a59c9dd70bc9d (commit)
       via  415583a28981b3ce76344f583d8cb71ab847be25 (commit)
      from  e4f07ef831954aab40e8f5d97d3361ee34aaf2c5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 80b60d8b0c9f18407e8b63ace60a59c9dd70bc9d
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Aug 24 17:23:33 2015 -0500

    RT#14829: automatic payments triggered by bill now show up as Payment by fs_queue [fixed local CurrentUser]

diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm
index f7f0948..67d124d 100644
--- a/FS/FS/queue.pm
+++ b/FS/FS/queue.pm
@@ -364,19 +364,20 @@ sub update_statustext {
   #'';
 }
 
-=item access_user
-
-Returns FS::access_user object (if any) associated with this user.
-
-Returns nothing if not found.
-
-=cut
-
-sub access_user {
-  my $self = shift;
-  my $usernum = $self->usernum || return ();
-  return qsearchs('access_user',{ 'usernum' => $usernum }) || ();
-}
+# not needed in 4
+#=item access_user
+#
+#Returns FS::access_user object (if any) associated with this user.
+#
+#Returns nothing if not found.
+#
+#=cut
+#
+#sub access_user {
+#  my $self = shift;
+#  my $usernum = $self->usernum || return ();
+#  return qsearchs('access_user',{ 'usernum' => $usernum }) || ();
+#}
 
 =back
 
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index 398b03d..36871b2 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -218,13 +218,12 @@ while (1) {
       # don't put @args in the log, may expose passwords
       $log->info('starting job ('.$ljob->job.')');
       warn 'running "&'. $ljob->job. '('. join(', ', @args). ")\n" if $DEBUG;
-      # switch user only if a job user is available
-      my $oldCurrentUser = $FS::CurrentUser::CurrentUser;
-      my $jobuser = $ljob->access_user;
-      local $FS::CurrentUser::CurrentUser = $jobuser if $jobuser;
       local $FS::UID::AutoCommit = 0; # so that we can clean up failures
-      eval $eval; #throw away return value?  suppose so
-      $FS::CurrentUser::CurrentUser = $oldCurrentUser if $jobuser;
+      do {
+        # switch user only if a job user is available
+        local $FS::CurrentUser::CurrentUser = $ljob->access_user || $FS::CurrentUser::CurrentUser;
+        eval $eval; #throw away return value?  suppose so
+      };
       if ( $@ ) {
         dbh->rollback;
         my %hash = $ljob->hash;

commit 415583a28981b3ce76344f583d8cb71ab847be25
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Thu Aug 20 01:42:15 2015 -0500

    RT#14829: automatic payments triggered by bill now show up as Payment by fs_queue

diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 184c6c9..2ff92eb 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -4332,6 +4332,7 @@ sub tables_hashref {
         'custnum',        'int', 'NULL',      '', '', '',
         'secure',        'char', 'NULL',       1, '', '',
         'priority',       'int', 'NULL',      '', '', '',
+        'usernum',        'int', 'NULL',      '', '', '',
       ],
       'primary_key'  => 'jobnum',
       'unique'       => [],
@@ -4345,6 +4346,9 @@ sub tables_hashref {
                           { columns    => [ 'custnum' ],
                             table      => 'cust_main',
                           },
+                          { columns    => [ 'usernum' ],
+                            table      => 'access_user',
+                          },
                         ],
     },
 
diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm
index 1b52ac4..f7f0948 100644
--- a/FS/FS/queue.pm
+++ b/FS/FS/queue.pm
@@ -97,6 +97,10 @@ Optional link to customer (see L<FS::cust_main>).
 Secure flag, 'Y' indicates that when using encryption, the job needs to be
 run on a machine with the private key.
 
+=item usernum
+
+For access_user that created the job
+
 =cut
 
 =back
@@ -151,6 +155,8 @@ sub insert {
 
   $self->custnum( $args{'custnum'} ) if $args{'custnum'};
 
+  $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
+
   my $error = $self->SUPER::insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
@@ -235,6 +241,7 @@ sub check {
     || $self->ut_enum('status',['', qw( new locked failed done )])
     || $self->ut_anything('statustext')
     || $self->ut_numbern('svcnum')
+    || $self->ut_foreign_keyn('usernum', 'access_user', 'usernum')
   ;
   return $error if $error;
 
@@ -357,6 +364,20 @@ sub update_statustext {
   #'';
 }
 
+=item access_user
+
+Returns FS::access_user object (if any) associated with this user.
+
+Returns nothing if not found.
+
+=cut
+
+sub access_user {
+  my $self = shift;
+  my $usernum = $self->usernum || return ();
+  return qsearchs('access_user',{ 'usernum' => $usernum }) || ();
+}
+
 =back
 
 =head1 SUBROUTINES
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index 7c4cf1b..398b03d 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -218,8 +218,13 @@ while (1) {
       # don't put @args in the log, may expose passwords
       $log->info('starting job ('.$ljob->job.')');
       warn 'running "&'. $ljob->job. '('. join(', ', @args). ")\n" if $DEBUG;
+      # switch user only if a job user is available
+      my $oldCurrentUser = $FS::CurrentUser::CurrentUser;
+      my $jobuser = $ljob->access_user;
+      local $FS::CurrentUser::CurrentUser = $jobuser if $jobuser;
       local $FS::UID::AutoCommit = 0; # so that we can clean up failures
       eval $eval; #throw away return value?  suppose so
+      $FS::CurrentUser::CurrentUser = $oldCurrentUser if $jobuser;
       if ( $@ ) {
         dbh->rollback;
         my %hash = $ljob->hash;
diff --git a/httemplate/search/queue.html b/httemplate/search/queue.html
index 141c535..22032b1 100644
--- a/httemplate/search/queue.html
+++ b/httemplate/search/queue.html
@@ -13,6 +13,7 @@
                                'Date',
                                'Status',
                                'Account', # unless $hashref->{'svcnum'}
+                               'Employee',
                                '', # checkbox column
                              ],
                  'fields' => [
@@ -78,6 +79,11 @@
                                },
                                sub {
                                  my $queue = shift;
+                                 my $access_user = $queue->access_user;
+                                 return $access_user ? $access_user->username : '';
+                               },
+                               sub {
+                                 my $queue = shift;
                                  my $jobnum = $queue->jobnum;
                                  my $status = $queue->status;
                                  my $changable = $dangerous

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Schema.pm              |    4 ++++
 FS/FS/queue.pm               |   22 ++++++++++++++++++++++
 FS/bin/freeside-queued       |    6 +++++-
 httemplate/search/queue.html |    6 ++++++
 4 files changed, 37 insertions(+), 1 deletion(-)




More information about the freeside-commits mailing list