[freeside-commits] branch master updated. e94760d804c5638ecbd1487e8c3a2797f0034846

Ivan ivan at 420.am
Fri Jan 25 02:05:48 PST 2013


The branch, master has been updated
       via  e94760d804c5638ecbd1487e8c3a2797f0034846 (commit)
      from  658a793422919736368e1f0a29b0f448ef362908 (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 e94760d804c5638ecbd1487e8c3a2797f0034846
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Jan 25 02:05:47 2013 -0800

    add vacation msg retrieval and addition/deletion to self-service API, RT#20896

diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 6ce6586..789e370 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -45,7 +45,7 @@ use FS::payby;
 use FS::acct_rt_transaction;
 use FS::msg_template;
 
-$DEBUG = 0;
+$DEBUG = 1;
 $me = '[FS::ClientAPI::MyAccount]';
 
 use vars qw( @cust_main_editable_fields @location_editable_fields );
@@ -1787,27 +1787,14 @@ sub svc_status_hash {
 
 }
 
-sub set_svc_status_hash {
-  my $p = shift;
+sub set_svc_status_hash    { _svc_method_X(shift, 'export_setstatus') }
+sub set_svc_status_listadd { _svc_method_X(shift, 'export_setstatus_listadd') }
+sub set_svc_status_listdel { _svc_method_X(shift, 'export_setstatus_listdel') }
+sub set_svc_status_vacationadd { _svc_method_X(shift, 'export_setstatus_vacationadd') }
+sub set_svc_status_vacationdel { _svc_method_X(shift, 'export_setstatus_vacationdel') }
 
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  #XXX only svc_acct for now
-  my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
-    or return { 'error' => "Service not found" };
-
-  warn "set_svc_status_hash ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
-    if $DEBUG;
-  my $error = $svc_x->export_setstatus($p); #$p? returns error?
-  return { 'error' => $error } if $error;
-
-  return {}; #? { 'error' => '' }
-
-}
-
-sub set_svc_status_listadd {
-  my $p = shift;
+sub _svc_method_X {
+  my( $p, $method ) = @_;
 
   my($context, $session, $custnum) = _custoragent_session_custnum($p);
   return { 'error' => $session } if $context eq 'error';
@@ -1816,35 +1803,15 @@ sub set_svc_status_listadd {
   my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
     or return { 'error' => "Service not found" };
 
-  warn "set_svc_status_listadd ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
+  warn "$method ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
     if $DEBUG;
-  my $error = $svc_x->export_setstatus_listadd($p); #$p? returns error?
+  my $error = $svc_x->$method($p); #$p? returns error?
   return { 'error' => $error } if $error;
 
   return {}; #? { 'error' => '' }
 
 }
 
-sub set_svc_status_listdel {
-  my $p = shift;
-
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  #XXX only svc_acct for now
-  my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
-    or return { 'error' => "Service not found" };
-
-  warn "set_svc_status_listdel ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
-    if $DEBUG;
-  my $error = $svc_x->export_setstatus_listdel($p); #$p? returns error?
-  return { 'error' => $error } if $error;
-
-  return {}; #? { 'error' => '' }
-
-}
-
-
 sub acct_forward_info {
   my $p = shift;
 
diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm
index 086a7b0..d720db2 100644
--- a/FS/FS/ClientAPI_XMLRPC.pm
+++ b/FS/FS/ClientAPI_XMLRPC.pm
@@ -131,6 +131,8 @@ sub ss2clientapi {
   'set_svc_status_hash'       => 'MyAccount/set_svc_status_hash',
   'set_svc_status_listadd'    => 'MyAccount/set_svc_status_listadd',
   'set_svc_status_listdel'    => 'MyAccount/set_svc_status_listdel',
+  'set_svc_status_vacationadd'=> 'MyAccount/set_svc_status_vacationadd',
+  'set_svc_status_vacationdel'=> 'MyAccount/set_svc_status_vacationdel',
   'acct_forward_info'         => 'MyAccount/acct_forward_info',
   'process_acct_forward'      => 'MyAccount/process_acct_forward',
   'list_dsl_devices'          => 'MyAccount/list_dsl_devices',   
diff --git a/FS/FS/part_export/http_status.pm b/FS/FS/part_export/http_status.pm
index da32ec4..80139e7 100644
--- a/FS/FS/part_export/http_status.pm
+++ b/FS/FS/part_export/http_status.pm
@@ -4,6 +4,7 @@ use base qw( FS::part_export );
 use strict;
 use warnings;
 use vars qw( %info $DEBUG );
+use URI::Escape;
 use LWP::UserAgent;
 use HTTP::Request::Common;
 use Email::Valid;
@@ -14,6 +15,9 @@ tie my %options, 'Tie::IxHash',
   'blacklist_del_url' => { label => 'Optional blacklist delete URL', },
   'whitelist_add_url' => { label => 'Optional whitelist add URL', },
   'whitelist_del_url' => { label => 'Optional whitelist delete URL', },
+  'vacation_add_url'  => { label => 'Optional vacation message add URL', },
+  'vacation_del_url'  => { label => 'Optional vacation message delete URL', },
+
   #'user'     => { label => 'Username', default=>'' },
   #'password' => { label => 'Password', default => '' },
 ;
@@ -26,11 +30,12 @@ tie my %options, 'Tie::IxHash',
   'notes'   => <<'END'
 Fields from the service can be substituted in the URL as $field.
 
-Optionally, spam black/whitelist addresses may be via HTTP or HTTPS as well.
+Optionally, spam black/whitelist addresees and a vacation message may be
+modified via HTTP or HTTPS as well.
 END
 );
 
-$DEBUG = 0;
+$DEBUG = 1;
 
 sub rebless { shift; }
 
@@ -39,6 +44,12 @@ our %addl_fields = (
   'svc_dsl'  => [qw( gateway_access_or_phonenum ) ],
 );
 
+#some NOPs for required subroutines, to avoid throwing the exceptions in the
+# part_export.pm fallbacks
+sub _export_insert  { '' };
+sub _export_replace { '' };
+sub _export_delete  { '' };
+
 sub export_getstatus {
   my( $self, $svc_x, $htmlref, $hashref ) = @_;
 
@@ -84,11 +95,23 @@ sub export_getstatus {
       my @fields = $csv->fields;
       my %hash = map { $_ => shift(@fields) } @header;
 
-      if ( $hash{'wb_value'} =~ /^[WA]/i ) { #Whitelist/Allow
-        push @{ $hashref->{'whitelist'} }, $hash{'from'};
-      } else { # if ( $hash{'wb_value'} =~ /^[BD]/i ) { #Blacklist/Deny
-        push @{ $hashref->{'blacklist'} }, $hash{'from'};
+      if ( defined $hash{'wb_value'} ) {
+        if ( $hash{'wb_value'} =~ /^[WA]/i ) { #Whitelist/Allow
+          push @{ $hashref->{'whitelist'} }, $hash{'from'};
+        } else { # if ( $hash{'wb_value'} =~ /^[BD]/i ) { #Blacklist/Deny
+          push @{ $hashref->{'blacklist'} }, $hash{'from'};
+        }
       }
+
+      for (qw( created enddate )) {
+        $hash{$_} = '' if $hash{$_} =~ /^0000-/;
+        $hash{$_} = (split(' ', $hash{$_}))[0];
+      }
+
+      next unless $hash{'active'};
+      $hashref->{"vacation_$_"} = $hash{$_} || ''
+        foreach qw( active subject body created enddate );
+
     }
 
   } #else { die 'guru meditation #295'; }
@@ -138,6 +161,52 @@ sub export_setstatus_listX {
 
 }
 
+sub export_setstatus_vacationadd {
+  my( $self, $svc_x, $hr ) = @_;
+  $self->export_setstatus_vacationX( $svc_x, 'add', $hr );
+}
+
+sub export_setstatus_vacationdel {
+  my( $self, $svc_x, $hr ) = @_;
+  $self->export_setstatus_vacationX( $svc_x, 'del', $hr );
+}
+
+sub export_setstatus_vacationX {
+  my( $self, $svc_x, $action, $hr ) = @_;
+
+  my $option = 'vacation_'. $action. '_url';
+
+  my $subject = uri_escape($hr->{subject});
+  my $body    = uri_escape($hr->{body});
+  for (qw( created enddate )) {
+    if ( $hr->{$_} =~ /^(\d{4}-\d{2}-\d{2})$/ ) {
+      $hr->{$_} = $1;
+    } else {
+      $hr->{$_} = '';
+    }
+  }
+  my $created = $hr->{created};
+  my $enddate = $hr->{enddate};
+
+  #some false laziness w/export_getstatus above
+  my $url;
+  my $urlopt = $self->option($option) or return; #DIFF
+  no strict 'vars';
+  {
+    no strict 'refs';
+    ${$_} = $svc_x->getfield($_) foreach $svc_x->fields;
+    ${$_} = $svc_x->$_()         foreach @{ $addl_fields{ $svc_x->table } };
+    $url = eval(qq("$urlopt"));
+  }
+
+  my $req = HTTP::Request::Common::GET( $url );
+  my $ua = LWP::UserAgent->new;
+  my $response = $ua->request($req);
+
+  die $response->code. ' '. $response->message if $response->is_error;
+
+}
+
 1;
 
 1;
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index 4efdc23..ef37351 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -1082,31 +1082,17 @@ otherwise returns false.
 
 =cut
 
-sub export_setstatus {
-  my( $self, @args ) = @_;
-  my $error = $self->export('setstatus', @args);
+sub export_setstatus { shift->_export_setstatus_X('setstatus', @_) }
+sub export_setstatus_listadd { shift->_export_setstatus_X('setstatus_listadd', @_) }
+sub export_setstatus_listdel { shift->_export_setstatus_X('setstatus_listdel', @_) }
+sub export_setstatus_vacationadd { shift->_export_setstatus_X('setstatus_vacationadd', @_) }
+sub export_setstatus_vacationdel { shift->_export_setstatus_X('setstatus_vacationdel', @_) }
+
+sub _export_setstatus_X {
+  my( $self, $method, @args ) = @_;
+  my $error = $self->export($method, @args);
   if ( $error ) {
-    warn "error running export_setstatus: $error";
-    return $error;
-  }
-  '';
-}
-
-sub export_setstatus_listadd {
-  my( $self, @args ) = @_;
-  my $error = $self->export('setstatus_listadd', @args);
-  if ( $error ) {
-    warn "error running export_setstatus: $error";
-    return $error;
-  }
-  '';
-}
-
-sub export_setstatus_listdel {
-  my( $self, @args ) = @_;
-  my $error = $self->export('setstatus_listdel', @args);
-  if ( $error ) {
-    warn "error running export_setstatus: $error";
+    warn "error running export_$method: $error";
     return $error;
   }
   '';
diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm
index 5437abd..651a8f5 100644
--- a/fs_selfservice/FS-SelfService/SelfService.pm
+++ b/fs_selfservice/FS-SelfService/SelfService.pm
@@ -59,6 +59,8 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'set_svc_status_hash'       => 'MyAccount/set_svc_status_hash',
   'set_svc_status_listadd'    => 'MyAccount/set_svc_status_listadd',
   'set_svc_status_listdel'    => 'MyAccount/set_svc_status_listdel',
+  'set_svc_status_vacationadd'=> 'MyAccount/set_svc_status_vacationadd',
+  'set_svc_status_vacationdel'=> 'MyAccount/set_svc_status_vacationdel',
   'acct_forward_info'         => 'MyAccount/acct_forward_info',
   'process_acct_forward'      => 'MyAccount/process_acct_forward',
   'list_dsl_devices'          => 'MyAccount/list_dsl_devices',   

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

Summary of changes:
 FS/FS/ClientAPI/MyAccount.pm                 |   53 +++--------------
 FS/FS/ClientAPI_XMLRPC.pm                    |    2 +
 FS/FS/part_export/http_status.pm             |   81 ++++++++++++++++++++++++--
 FS/FS/svc_Common.pm                          |   34 +++--------
 fs_selfservice/FS-SelfService/SelfService.pm |    2 +
 5 files changed, 99 insertions(+), 73 deletions(-)




More information about the freeside-commits mailing list