RADIUS group enhancements, overlimit_groups changes, etc. RT13432
authorlevinse <levinse>
Fri, 1 Jul 2011 06:54:03 +0000 (06:54 +0000)
committerlevinse <levinse>
Fri, 1 Jul 2011 06:54:03 +0000 (06:54 +0000)
FS/FS/Conf.pm
FS/FS/Upgrade.pm
FS/FS/part_export.pm
FS/FS/part_export/phone_sqlradius.pm
FS/FS/part_export/sqlradius.pm
FS/FS/radius_group.pm
FS/FS/svc_acct.pm
httemplate/config/config-view.cgi
httemplate/edit/svc_acct.cgi
httemplate/elements/select-radius_group.html

index 170d884..4ff3aa7 100644 (file)
@@ -2856,8 +2856,21 @@ and customer address. Include units.',
     'key'         => 'overlimit_groups',
     'section'     => '',
     'description' => 'RADIUS group (or comma-separated groups) to assign to svc_acct which has exceeded its bandwidth or time limit.',
-    'type'        => 'text',
+    'type'        => 'select-sub',
     'per_agent'   => 1,
+    'multiple'    => 1,
+    'options_sub' => sub { require FS::Record;
+                           require FS::radius_group;
+                          map { $_->groupnum => $_->long_description }
+                               FS::Record::qsearch('radius_group', {} );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::radius_group;
+                          my $radius_group = FS::Record::qsearchs(
+                            'radius_group', { 'groupnum' => shift }
+                          );
+               $radius_group ? $radius_group->long_description : '';
+                        },
   },
 
   {
index ca6036e..3ea554e 100644 (file)
@@ -6,7 +6,7 @@ use Exporter;
 use Tie::IxHash;
 use FS::UID qw( dbh driver_name );
 use FS::Conf;
-use FS::Record qw(qsearchs str2time_sql);
+use FS::Record qw(qsearchs qsearch str2time_sql);
 
 use FS::svc_domain;
 $FS::svc_domain::whois_hack = 1;
@@ -47,6 +47,35 @@ sub upgrade_config {
     if $conf->exists('payment_receipt_email')
     || $conf->config('payment_receipt_msgnum');
 
+  upgrade_overlimit_groups($conf);
+  map { upgrade_overlimit_groups($conf,$_->agentnum) } qsearch('agent', {});
+  
+}
+
+sub upgrade_overlimit_groups {
+    my $conf = shift;
+    my $agentnum = shift;
+    my @groups = $conf->config('overlimit_groups',$agentnum); 
+    if(scalar(@groups)) {
+        my $groups = join(',',@groups);
+        my @groupnums;
+        my $error = '';
+        if ( $groups !~ /^[\d,]+$/ ) {
+            foreach my $groupname ( @groups ) {
+                my $g = qsearchs('radius_group', { 'groupname' => $groupname } );
+                unless ( $g ) {
+                    $g = new FS::radius_group {
+                                    'groupname' => $groupname,
+                                    'description' => $groupname,
+                                    };
+                    $error = $g->insert;
+                    die $error if $error;
+                }
+                push @groupnums, $g->groupnum;
+            }
+            $conf->set('overlimit_groups',join("\n",@groupnums),$agentnum);
+        }
+    }
 }
 
 =item upgrade
@@ -194,6 +223,7 @@ sub upgrade_data {
     # migrate to radius_group and groupnum instead of groupname
     'radius_usergroup' => [],
     'part_svc'         => [],
+    'part_export'      => [],
 
   ;
 
index d3068df..890c522 100644 (file)
@@ -431,6 +431,34 @@ sub export_info {
   my $r = { map { %{$exports{$_}} } keys %exports };
 }
 
+
+sub _upgrade_data {  #class method
+  my ($class, %opts) = @_;
+
+  my @part_export_option = qsearch('part_export_option', { 'optionname' => 'overlimit_groups' });
+  foreach my $opt ( @part_export_option ) {
+    next if $opt->optionvalue =~ /^[\d\s]+$/ || !$opt->optionvalue;
+    my @groupnames = split(' ',$opt->optionvalue);
+    my @groupnums;
+    my $error = '';
+    foreach my $groupname ( @groupnames ) {
+        my $g = qsearchs('radius_group', { 'groupname' => $groupname } );
+        unless ( $g ) {
+            $g = new FS::radius_group {
+                            'groupname' => $groupname,
+                            'description' => $groupname,
+                            };
+            $error = $g->insert;
+            die $error if $error;
+        }
+        push @groupnums, $g->groupnum;
+    }
+    $opt->optionvalue(join(' ',@groupnums));
+    $error = $opt->replace;
+    die $error if $error;
+  }
+}
+
 #=item exporttype2svcdb EXPORTTYPE
 #
 #Returns the applicable I<svcdb> for an I<exporttype>.
index 24f7845..0816efa 100644 (file)
@@ -36,13 +36,6 @@ tie %options, 'Tie::IxHash',
   #  label => 'Show the Called-Station-ID on session reports',
   #},
 
-  #N/A
-  #'overlimit_groups' => { label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit', } ,
-  #'groups_susp_reason' => { label =>
-  #                           'Radius group mapping to reason (via template user) (svcnum|username|username@domain  reasonnum|reason)',
-  #                          type  => 'textarea',
-  #                        },
-
 ;
 
 %info = (
index d1663dc..4dea80e 100644 (file)
@@ -14,6 +14,7 @@ use Carp qw( cluck );
 
 $DEBUG = 0;
 
+my %groups;
 tie %options, 'Tie::IxHash',
   'datasrc'  => { label=>'DBI data source ' },
   'username' => { label=>'Database username' },
@@ -47,7 +48,21 @@ tie %options, 'Tie::IxHash',
     type  => 'checkbox',
     label => 'Show the Called-Station-ID on session reports',
   },
-  'overlimit_groups' => { label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit (if not overridden by overlimit_groups global or per-agent config)', } ,
+  'overlimit_groups' => {
+      label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit (if not overridden by overlimit_groups global or per-agent config)', 
+      type  => 'select',
+      multi => 1,
+      option_label  => sub {
+        $groups{$_[0]};
+      },
+      option_values => sub {
+        %groups = (
+              map { $_->groupnum, $_->long_description } 
+                  qsearch('radius_group', {}),
+            );
+            sort keys (%groups);
+      },
+   } ,
   'groups_susp_reason' => { label =>
                              'Radius group mapping to reason (via template user) (svcnum|username|username@domain  reasonnum|reason)',
                             type  => 'textarea',
index 96de294..eeb291b 100644 (file)
@@ -112,6 +112,19 @@ sub check {
   $self->SUPER::check;
 }
 
+=item long_description
+
+Returns a description for this group consisting of its description field, 
+if any, and the RADIUS group name.
+
+=cut
+
+sub long_description {
+    my $self = shift;
+    $self->description ? $self->description . " (". $self->groupname . ")"
+                       : $self->groupname;
+}
+
 =back
 
 =head1 BUGS
index e8c797a..7ef8ed3 100644 (file)
@@ -2227,20 +2227,19 @@ sub _op_overlimit {
 
   my $cust_pkg = $self->cust_svc->cust_pkg;
 
-  my $conf_overlimit =
+  my @conf_overlimit =
     $cust_pkg
       ? $conf->config('overlimit_groups', $cust_pkg->cust_main->agentnum )
       : $conf->config('overlimit_groups');
 
   foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
 
-    my $groups = $conf_overlimit || $part_export->option('overlimit_groups');
-    next unless $groups;
-
-    my $gref = &{ $self->_fieldhandlers->{'usergroup'} }( $self, $groups );
+    my @groups = scalar(@conf_overlimit) ? @conf_overlimit
+                                         : split(' ',$part_export->option('overlimit_groups'));
+    next unless scalar(@groups);
 
     my $other = new FS::svc_acct $self->hashref;
-    $other->usergroup( $gref );
+    $other->usergroup(\@groups);
 
     my($new,$old);
     if ($action eq 'suspend') {
index 4c90ebb..e7cadbe 100644 (file)
@@ -207,8 +207,16 @@ Click on a configuration value to change it.
 
             <tr>
               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
+%               if ( $i->multiple ) {
+                    <% join('<BR>',
+                        map { $_ . ": " . &{ $i->option_sub }($_) }
+                                            $conf->config($i->key,$agentnum)
+                        )
+                    %>
+%               } else {
                 <% $conf->config($i->key, $agentnum) %>: 
                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
+%               }
               </td>
             </tr>
 
index 8fda250..66b58e2 100755 (executable)
@@ -452,7 +452,7 @@ my $part_svc_usergroup = $part_svc->part_svc_column('usergroup');
 my @groupnames; # only used for display of Fixed RADIUS groups
 if ( $part_svc_usergroup->columnflag eq 'F' ) {
   @groups = split(',',$part_svc_usergroup->columnvalue);
-  @groupnames = map { $_->description . " (" . $_->groupname . ")" } 
+  @groupnames = map { $_->long_description } 
                     qsearch({ 'table'         => 'radius_group',
                            'extra_sql'     => "where groupnum in (".$part_svc_usergroup->columnvalue.")",
                         }) if length($part_svc_usergroup->columnvalue);
index eeaf5ac..e1e3c59 100644 (file)
@@ -10,7 +10,7 @@
 
 my %opt = @_;
 
-my %groups = map { $_->groupnum => $_->description . " (" . $_->groupname . ")" }
+my %groups = map { $_->groupnum => $_->long_description }
                                                     qsearch('radius_group', {});
 my @sel_groups = split(/,/,$opt{'curr_value'});