[freeside-commits] freeside/FS/FS svc_Radius_Mixin.pm, NONE, 1.1 Conf.pm, 1.485, 1.486 nas.pm, 1.11, 1.12 part_export.pm, 1.110, 1.111 part_svc.pm, 1.45, 1.46 radius_usergroup.pm, 1.3, 1.4 svc_acct.pm, 1.318, 1.319 svc_broadband.pm, 1.25, 1.26
Mark Wells
mark at wavetail.420.am
Thu Nov 10 13:40:06 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv22579/FS/FS
Modified Files:
Conf.pm nas.pm part_export.pm part_svc.pm radius_usergroup.pm
svc_acct.pm svc_broadband.pm
Added Files:
svc_Radius_Mixin.pm
Log Message:
RADIUS groups for svc_broadband, #14695
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.485
retrieving revision 1.486
diff -u -w -d -r1.485 -r1.486
--- Conf.pm 8 Nov 2011 04:17:02 -0000 1.485
+++ Conf.pm 10 Nov 2011 21:40:03 -0000 1.486
@@ -2297,6 +2297,13 @@
},
{
+ 'key' => 'svc_broadband-radius',
+ 'section' => '',
+ 'description' => 'Enable RADIUS groups for broadband services.',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'svc_acct-alldomains',
'section' => '',
'description' => 'Allow accounts to select any domain in the database. Normally accounts can only select from the domain set in the service definition and those purchased by the customer.',
Index: nas.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/nas.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -d -r1.11 -r1.12
--- nas.pm 31 Oct 2011 19:20:15 -0000 1.11
+++ nas.pm 10 Nov 2011 21:40:04 -0000 1.12
@@ -87,8 +87,11 @@
my $dbh = dbh;
my $self = shift;
- my $error = $self->process_m2m([])
- || $self->SUPER::delete;
+ my $error = $self->process_m2m(
+ link_table => 'export_nas',
+ target_table => 'part_export',
+ params => []
+ ) || $self->SUPER::delete;
if ( $error ) {
$dbh->rollback;
Index: svc_broadband.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_broadband.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -w -d -r1.25 -r1.26
--- svc_broadband.pm 25 Oct 2011 00:19:05 -0000 1.25
+++ svc_broadband.pm 10 Nov 2011 21:40:04 -0000 1.26
@@ -9,7 +9,7 @@
use FS::part_svc_router;
use NetAddr::IP;
- at ISA = qw( FS::svc_Common );
+ at ISA = qw( FS::svc_Radius_Mixin FS::svc_Common );
$FS::UID::callback{'FS::svc_broadband'} = sub {
$conf = new FS::Conf;
@@ -115,6 +115,15 @@
'longitude' => 'Longitude',
'altitude' => 'Altitude',
'vlan_profile' => 'VLAN profile',
+ 'usergroup' => {
+ label => 'RADIUS groups',
+ type => 'select-radius_group.html',
+ #select_table => 'radius_group',
+ #select_key => 'groupnum',
+ #select_label => 'groupname',
+ disable_inventory => 1,
+ multiple => 1,
+ },
},
};
}
--- NEW FILE: svc_Radius_Mixin.pm ---
package FS::svc_Radius_Mixin;
use strict;
use base qw(FS::m2m_Common FS::svc_Common);
use FS::Record qw(qsearch);
use FS::radius_group;
use FS::radius_usergroup;
use Carp qw(confess);
=head1 NAME
FS::svc_Radius_Mixin - partial base class for services with RADIUS groups
=cut
sub insert {
my $self = shift;
$self->SUPER::insert(@_)
|| $self->process_m2m(
'link_table' => 'radius_usergroup',
'target_table' => 'radius_group',
'params' => $self->usergroup,
);
}
sub replace {
my $new = shift;
my $old = shift;
$old = $new->replace_old if !defined($old);
$old->usergroup; # make sure this is cached for exports
$new->process_m2m(
'link_table' => 'radius_usergroup',
'target_table' => 'radius_group',
'params' => $new->usergroup,
) || $new->SUPER::replace($old, @_);
}
sub delete {
my $self = shift;
$self->SUPER::delete(@_)
|| $self->process_m2m(
'link_table' => 'radius_usergroup',
'target_table' => 'radius_group',
'params' => [],
);
}
sub usergroup {
my $self = shift;
my $value = shift;
if ( defined $value ) {
if ( ref $value ) {
return $self->set('usergroup', $value);
}
else {
return $self->set('usergroup', [ split(/\s*,\s*/, $value) ]);
}
}
$self->get('usergroup') ||
# if no argument is passed and usergroup is not set already,
# fetch this service's group assignments
$self->set('usergroup',
[ map { $_->groupnum }
qsearch('radius_usergroup', { svcnum => $self->svcnum }) ]
);
}
sub _fieldhandlers {
{
'usergroup' => \&usergroup
}
}
=item radius_groups METHOD
Returns a list of RADIUS groups for this service (see L<FS::radius_usergroup>).
METHOD is the field to return, and can be any method on L<FS::radius_group>.
Useful values for METHOD include 'groupnum', 'groupname', and
'long_description'. Defaults to 'groupname' for historical reasons.
=cut
sub radius_groups {
my $self = shift;
my $method = shift || 'groupname';
my $groups = join(',', @{$self->usergroup}) || return ();
my @groups = qsearch({'table' => 'radius_group',
'extra_sql' => "where groupnum in ($groups)"});
return map {$_->$method} @groups;
}
1;
Index: part_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_svc.pm,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -w -d -r1.45 -r1.46
--- part_svc.pm 28 Oct 2011 06:44:26 -0000 1.45
+++ part_svc.pm 10 Nov 2011 21:40:04 -0000 1.46
@@ -192,6 +192,8 @@
}
}
+ # XXX shouldn't this update fixed values?
+
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
@@ -714,11 +716,6 @@
my $old = qsearchs('part_svc', { 'svcpart' => $param->{'svcpart'} })
if $param->{'svcpart'};
- $param->{'svc_acct__usergroup'} =
- ref($param->{'svc_acct__usergroup'})
- ? join(',', @{$param->{'svc_acct__usergroup'}} )
- : $param->{'svc_acct__usergroup'};
-
#unmunge cgp_accessmodes (falze laziness-ish w/edit/process/svc_acct.cgi)
$param->{'svc_acct__cgp_accessmodes'} ||=
join(' ', sort
@@ -737,14 +734,17 @@
} ( fields('part_svc'),
map { my $svcdb = $_;
my @fields = fields($svcdb);
- push @fields, 'usergroup' if $svcdb eq 'svc_acct'; #kludge
+ push @fields, 'usergroup' if $svcdb eq 'svc_acct'
+ or $svcdb eq 'svc_broadband'; #kludge
map {
my $f = $svcdb.'__'.$_;
- if ( $param->{ $f.'_flag' } =~ /^[MAH]$/ ) {
+ my $flag = $param->{ $f.'_flag' } || ''; #silence warnings
+ if ( $flag =~ /^[MAH]$/ ) {
$param->{ $f } = delete( $param->{ $f.'_classnum' } );
}
- if ( $param->{ $f.'_flag' } =~ /^S$/ ) {
+ if ( $flag =~ /^S$/
+ or $_ eq 'usergroup' ) {
$param->{ $f } = ref($param->{ $f })
? join(',', @{$param->{ $f }} )
: $param->{ $f };
Index: part_export.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export.pm,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -w -d -r1.110 -r1.111
--- part_export.pm 31 Oct 2011 19:20:15 -0000 1.110
+++ part_export.pm 10 Nov 2011 21:40:04 -0000 1.111
@@ -128,7 +128,12 @@
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $error = $self->SUPER::delete;
+ # clean up export_nas records
+ my $error = $self->process_m2m(
+ 'link_table' => 'export_nas',
+ 'target_table' => 'nas',
+ 'params' => [],
+ ) || $self->SUPER::delete;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.318
retrieving revision 1.319
diff -u -w -d -r1.318 -r1.319
--- svc_acct.pm 25 Oct 2011 00:19:05 -0000 1.318
+++ svc_acct.pm 10 Nov 2011 21:40:04 -0000 1.319
@@ -1,7 +1,10 @@
package FS::svc_acct;
use strict;
-use base qw( FS::svc_Domain_Mixin FS::svc_CGP_Mixin FS::svc_CGPRule_Mixin
+use base qw( FS::svc_Domain_Mixin
+ FS::svc_CGP_Mixin
+ FS::svc_CGPRule_Mixin
+ FS::svc_Radius_Mixin
FS::svc_Common );
use vars qw( $DEBUG $me $conf $skip_fuzzyfiles
$dir_prefix @shells $usernamemin
@@ -339,6 +342,7 @@
type => 'select-radius_group.html',
disable_inventory => 1,
disable_select => 1,
+ multiple => 1,
},
'seconds' => { label => 'Seconds',
label_sort => 'with Time Remaining',
@@ -531,22 +535,6 @@
sub table_dupcheck_fields { ( 'username', 'domsvc' ); }
-sub _fieldhandlers {
- {
- #false laziness with edit/svc_acct.cgi
- 'usergroup' => sub {
- my( $self, $groups ) = @_;
- if ( ref($groups) eq 'ARRAY' ) {
- $groups;
- } elsif ( length($groups) ) {
- [ split(/\s*,\s*/, $groups) ];
- } else {
- [];
- }
- },
- };
-}
-
sub last_login {
shift->_lastlog('in', @_);
}
@@ -699,7 +687,7 @@
my $dbh = dbh;
my @jobnums;
- my $error = $self->SUPER::insert(
+ my $error = $self->SUPER::insert( # usergroup is here
'jobnums' => \@jobnums,
'child_objects' => $self->child_objects,
%options,
@@ -709,20 +697,6 @@
return $error;
}
- if ( $self->usergroup ) {
- foreach my $groupnum ( @{$self->usergroup} ) {
- my $radius_usergroup = new FS::radius_usergroup ( {
- svcnum => $self->svcnum,
- groupnum => $groupnum,
- } );
- my $error = $radius_usergroup->insert;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
- }
- }
-
unless ( $skip_fuzzyfiles ) {
$error = $self->queue_fuzzyfiles_update;
if ( $error ) {
@@ -935,21 +909,11 @@
}
}
- my $error = $self->SUPER::delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
-
- foreach my $radius_usergroup (
- qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
- ) {
- my $error = $radius_usergroup->delete;
+ my $error = $self->SUPER::delete; # usergroup here
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
- }
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
@@ -1011,49 +975,7 @@
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- # redundant, but so $new->usergroup gets set
- $error = $new->check;
- return $error if $error;
-
- $old->usergroup( [ $old->radius_groups('NUMBERS') ] );
- if ( $DEBUG ) {
- warn $old->email. " old groups: ". join(' ',@{$old->usergroup}). "\n";
- warn $new->email. " new groups: ". join(' ',@{$new->usergroup}). "\n";
- }
- if ( $new->usergroup ) {
- #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
- my @newgroups = @{$new->usergroup};
- foreach my $oldgroup ( @{$old->usergroup} ) {
- if ( grep { $oldgroup eq $_ } @newgroups ) {
- @newgroups = grep { $oldgroup ne $_ } @newgroups;
- next;
- }
- my $radius_usergroup = qsearchs('radius_usergroup', {
- svcnum => $old->svcnum,
- groupnum => $oldgroup,
- } );
- my $error = $radius_usergroup->delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "error deleting radius_usergroup $oldgroup: $error";
- }
- }
-
- foreach my $newgroup ( @newgroups ) {
- my $radius_usergroup = new FS::radius_usergroup ( {
- svcnum => $new->svcnum,
- groupnum => $newgroup,
- } );
- my $error = $radius_usergroup->insert;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "error adding radius_usergroup $newgroup: $error";
- }
- }
-
- }
-
- $error = $new->SUPER::replace($old, @_);
+ $error = $new->SUPER::replace($old, @_); # usergroup here
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error if $error;
@@ -1191,15 +1113,10 @@
my($recref) = $self->hashref;
- my $x = $self->setfixed( $self->_fieldhandlers );
+ my $x = $self->setfixed;
return $x unless ref($x);
my $part_svc = $x;
- if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
- $self->usergroup(
- [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
- }
-
my $error = $self->ut_numbern('svcnum')
#|| $self->ut_number('domsvc')
|| $self->ut_foreign_key( 'domsvc', 'svc_domain', 'svcnum' )
@@ -2549,41 +2466,7 @@
}
-=item radius_groups
-
-Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
-
-=cut
-
-sub radius_groups {
- my $self = shift;
- if ( $self->usergroup ) {
- confess "explicitly specified usergroup not an arrayref: ". $self->usergroup
- unless ref($self->usergroup) eq 'ARRAY';
- #when provisioning records, export callback runs in svc_Common.pm before
- #radius_usergroup records can be inserted...
- my $groups = join(',',@{$self->usergroup});
- my @groups;
- return @groups unless length($groups);
- @groups = qsearch({ 'table' => 'radius_group',
- 'extra_sql' => "where groupnum in ($groups)",
- });
- map { $_->groupname } @groups;
- } else {
- my $format = shift || '';
- my @groups = qsearch({ 'table' => 'radius_usergroup',
- 'addl_from' => 'left join radius_group using (groupnum)',
- 'select' => 'radius_group.*',
- 'hashref' => { 'svcnum' => $self->svcnum },
- });
-
- # this is to preserve various legacy behaviour / avoid re-writing other code
- return map { $_->groupnum } @groups if $format eq 'NUMBERS';
- return map { $_->description . " (" . $_->groupname . ")" } @groups
- if $format eq 'COMBINED';
- map { $_->groupname } @groups;
- }
-}
+# sub radius_groups has moved to svc_Radius_Mixin
=item clone_suspended
Index: radius_usergroup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/radius_usergroup.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- radius_usergroup.pm 21 Jun 2011 01:04:55 -0000 1.3
+++ radius_usergroup.pm 10 Nov 2011 21:40:04 -0000 1.4
@@ -96,25 +96,29 @@
sub check {
my $self = shift;
-
+ my $svcnum = $self->svcnum;
die "radius_usergroup.groupname is deprecated" if $self->groupname;
$self->ut_numbern('usergroupnum')
- || $self->ut_foreign_key('svcnum','svc_acct','svcnum')
+ || ( $self->ut_foreign_key('svcnum','svc_acct','svcnum')
+ && $self->ut_foreign_key('svcnum','svc_broadband','svcnum')
+ && "Can't find radius_usergroup.svcnum $svcnum in svc_acct.svcnum or svc_broadband.svcnum" )
|| $self->ut_foreign_key('groupnum','radius_group','groupnum')
|| $self->SUPER::check
;
}
-=item svc_acct
+=item svc_x
-Returns the account associated with this record (see L<FS::svc_acct>).
+Returns the account associated with this record (see L<FS::svc_acct> and
+L<FS::svc_broadband>).
=cut
sub svc_acct {
my $self = shift;
- qsearchs('svc_acct', { svcnum => $self->svcnum } );
+ qsearchs('svc_acct', { svcnum => $self->svcnum } ) ||
+ qsearchs('svc_broadband', { svcnum => $self->svcnum } )
}
=item radius_group
More information about the freeside-commits
mailing list