From: levinse Date: Wed, 15 Dec 2010 15:09:45 +0000 (+0000) Subject: self-service improvements, RT10883 X-Git-Tag: TORRUS_1_0_9~18 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=aaace663fe7ff34479a707f3976c32010e4a1845 self-service improvements, RT10883 --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 3fc51b37e..181c994c4 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -171,6 +171,13 @@ sub login { ); return { error => 'User not found.' } unless $svc_acct; + if($conf->exists('selfservice_server-login_svcpart')) { + my @svcpart = $conf->config('selfservice_server-login_svcpart'); + my $svcpart = $svc_acct->cust_svc->svcpart; + return { error => 'Invalid user.' } + unless grep($_ eq $svcpart, @svcpart); + } + return { error => 'Incorrect password.' } unless $svc_acct->check_password($p->{'password'}); @@ -915,9 +922,42 @@ sub list_pkgs { my $cust_main = qsearchs('cust_main', $search ) or return { 'error' => "unknown custnum $custnum" }; - #return { 'cust_pkg' => [ map { $_->hashref } $cust_main->ncancelled_pkgs ] }; - my $conf = new FS::Conf; + +# the duplication below is necessary: +# 1. to maintain the current buggy behaviour wrt the cust_pkg and part_pkg +# hashes overwriting each other (setup and no_auto fields). Fixing that is a +# non-backwards-compatible change breaking the software of anyone using the API +# instead of the stock selfservice +# 2. to return cancelled packages as well - for wholesale and non-wholesale + if( $conf->exists('selfservice_server-view-wholesale') ) { + return { 'svcnum' => $session->{'svcnum'}, + 'custnum' => $custnum, + 'cust_pkg' => [ map { + { $_->hash, + part_pkg => [ map $_->hashref, $_->part_pkg ], + part_svc => + [ map $_->hashref, $_->available_part_svc ], + cust_svc => + [ map { my $ref = { $_->hash, + label => [ $_->label ], + }; + $ref->{_password} = $_->svc_x->_password + if $context eq 'agent' + && $conf->exists('agent-showpasswords') + && $_->part_svc->svcdb eq 'svc_acct'; + $ref; + } $_->cust_svc + ], + }; + } $cust_main->cust_pkg + ], + 'small_custview' => + small_custview( $cust_main, $conf->config('countrydefault') ), + 'wholesale_view' => 1, + 'date_format' => $conf->config('date_format') || '%m/%d/%Y', + }; + } { 'svcnum' => $session->{'svcnum'}, 'custnum' => $custnum, diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 072982ab4..ba0bc5b6d 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2270,6 +2270,21 @@ and customer address. Include units.', }, { + 'key' => 'selfservice_server-login_svcpart', + 'section' => 'self-service', + 'description' => 'If specified, only allow the specified svcparts to login to self-service.', + 'type' => 'select-part_svc', + 'multiple' => 1, + }, + + { + 'key' => 'selfservice_server-view-wholesale', + 'section' => 'self-service', + 'description' => 'If enabled, use a wholesale package view in the self-service.', + 'type' => 'checkbox', + }, + + { 'key' => 'selfservice-agent_signup', 'section' => 'self-service', 'description' => 'Allow agent signup via self-service.', diff --git a/fs_selfservice/FS-SelfService/cgi/provision.html b/fs_selfservice/FS-SelfService/cgi/provision.html index 7c0f861e4..10d17f537 100644 --- a/fs_selfservice/FS-SelfService/cgi/provision.html +++ b/fs_selfservice/FS-SelfService/cgi/provision.html @@ -1,6 +1,11 @@ -<%= $url = "$selfurl?session=$session_id;action="; ''; %> -<%= include('header', 'Setup my services') %> +<%= $url = "$selfurl?session=$session_id;action="; + $heading1 = "Setup my services"; + $heading1 = "Package list" if $wholesale_view; + $provision_list = "provision_list"; + $provision_list = "ws_list" if $wholesale_view; + ''; %> +<%= include('header', $heading1) %> -<%= include('provision_list') %> +<%= include($provision_list) %> <%= include('footer') %> diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 25d61aca6..0ef4e9aad 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -615,6 +615,8 @@ sub logout { sub provision { my $result = list_pkgs( 'session_id' => $session_id ); die $result->{'error'} if exists $result->{'error'} && $result->{'error'}; + $result->{'pkgpart'} = $cgi->param('pkgpart') if $cgi->param('pkgpart'); + $result->{'filter'} = $cgi->param('filter') if $cgi->param('filter'); $result; } diff --git a/fs_selfservice/FS-SelfService/cgi/ws_list.html b/fs_selfservice/FS-SelfService/cgi/ws_list.html new file mode 100644 index 000000000..7b62db452 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/ws_list.html @@ -0,0 +1,72 @@ +<%= + +sub ws_pkglink { + my($cat,$count,$link) = (shift,shift,shift); + return "0 $cat
" unless $count->{$cat}; + return qq! $count->{$cat} $cat
!; +} + +sub ws_pkgstatus { + my $pkg = shift; + $status = "unbilled"; + $status = "active" if ( $pkg->{setup} && !$pkg->{cancel} + && !$pkg->{susp} ); + $status = "suspended" if ( $pkg->{susp} && !$pkg->{cancel} ); + $status = "cancelled" if $pkg->{cancel}; + $status; +} + +sub pdate { + my($field,$date_format) = (shift,shift); + return "".Date::Format::time2str($date_format,$field)."" + if $field > 0; + ''; +} + +if ( $pkgpart ) { + $OUT .= qq! !; + $OUT .= ""; + $OUT .= ""; + $OUT .= ""; + foreach my $pkg ( @cust_pkg ) { + my $part_pkg = $pkg->{part_pkg}[0]; + $status = ws_pkgstatus($pkg); + if($pkg->{pkgpart} == $pkgpart && ($filter eq $status || !$filter) ) { + $OUT .= ""; + $OUT .= pdate($pkg->{setup},$date_format); + $OUT .= pdate($pkg->{last_bill},$date_format); + $OUT .= pdate($pkg->{bill},$date_format); + $OUT .= pdate($pkg->{adjourn},$date_format); + $OUT .= pdate($pkg->{susp},$date_format); + $OUT .= pdate($pkg->{expire},$date_format); + $OUT .= pdate($pkg->{contract_end},$date_format); + $OUT .= pdate($pkg->{cancel},$date_format); + $OUT .= ""; + } + } + $OUT .= "
PackageStatusSetupLast BillNext BillAdjournSuspendExpireContract EndCancel
$part_pkg->{pkg}$status
"; +} +else { + my %pkgparts; + foreach my $pkg ( @cust_pkg ) { + my $status = ws_pkgstatus($pkg); + $pkgparts{$pkg->{pkgpart}}{$status}++; + my $part_pkg = $pkg->{part_pkg}[0]; + $pkgparts{$pkg->{pkgpart}}{pkg} = $part_pkg->{pkg}; + } + + $OUT .= qq! !; + my($pkgpart,$counts); + while(($pkgpart,$count) = each %pkgparts){ + my $link = "${url}provision;pkgpart=$pkgpart"; + $OUT .= qq! "; + } + $OUT .= "
PackageStatus
$count->{pkg} !; + $OUT .= ws_pkglink("unbilled",$count,$link); + $OUT .= ws_pkglink("active",$count,$link); + $OUT .= ws_pkglink("suspended",$count,$link); + $OUT .= ws_pkglink("cancelled",$count,$link); + $OUT .= "
"; +} + +%>