[freeside-commits] freeside/FS/FS svc_acct.pm, 1.313, 1.314 radius_usergroup.pm, 1.2, 1.3 part_svc.pm, 1.37, 1.38 Upgrade.pm, 1.48, 1.49 Schema.pm, 1.306, 1.307 radius_group.pm, NONE, 1.1
Erik Levinson
levinse at wavetail.420.am
Mon Jun 20 18:04:57 PDT 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv28316/FS/FS
Modified Files:
svc_acct.pm radius_usergroup.pm part_svc.pm Upgrade.pm
Schema.pm
Added Files:
radius_group.pm
Log Message:
re-write RADIUS groups, RT13274
Index: radius_usergroup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/radius_usergroup.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- radius_usergroup.pm 5 Aug 2003 00:20:46 -0000 1.2
+++ radius_usergroup.pm 21 Jun 2011 01:04:55 -0000 1.3
@@ -4,6 +4,7 @@
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
use FS::svc_acct;
+use FS::radius_group;
@ISA = qw(FS::Record);
@@ -29,8 +30,8 @@
=head1 DESCRIPTION
An FS::radius_usergroup object links an account (see L<FS::svc_acct>) with a
-RADIUS group. FS::radius_usergroup inherits from FS::Record. The following
-fields are currently supported:
+RADIUS group (see L<FS::radius_group>). FS::radius_usergroup inherits from
+FS::Record. The following fields are currently supported:
=over 4
@@ -38,7 +39,7 @@
=item svcnum - Account (see L<FS::svc_acct>).
-=item groupname - group name
+=item groupnum - RADIUS group (see L<FS::radius_group>).
=back
@@ -96,10 +97,11 @@
sub check {
my $self = shift;
+ die "radius_usergroup.groupname is deprecated" if $self->groupname;
+
$self->ut_numbern('usergroupnum')
- || $self->ut_number('svcnum')
|| $self->ut_foreign_key('svcnum','svc_acct','svcnum')
- || $self->ut_text('groupname')
+ || $self->ut_foreign_key('groupnum','radius_group','groupnum')
|| $self->SUPER::check
;
}
@@ -115,15 +117,49 @@
qsearchs('svc_acct', { svcnum => $self->svcnum } );
}
-=back
+=item radius_group
-=head1 BUGS
+Returns the RADIUS group associated with this record (see L<FS::radius_group>).
-Don't let 'em get you down.
+=cut
+
+sub radius_group {
+ my $self = shift;
+ qsearchs('radius_group', { 'groupnum' => $self->groupnum } );
+}
+
+sub _upgrade_data { #class method
+ my ($class, %opts) = @_;
+
+ my %group_cache = map { $_->groupname => $_->groupnum }
+ qsearch('radius_group', {});
+
+ my @radius_usergroup = qsearch('radius_usergroup', {} );
+ my $error = '';
+ foreach my $rug ( @radius_usergroup ) {
+ my $groupname = $rug->groupname;
+ next unless $groupname;
+ unless(defined($group_cache{$groupname})) {
+ my $g = new FS::radius_group {
+ 'groupname' => $groupname,
+ 'description' => $groupname,
+ };
+ $error = $g->insert;
+ die $error if $error;
+ $group_cache{$groupname} = $g->groupnum;
+ }
+ $rug->groupnum($group_cache{$groupname});
+ $rug->groupname('');
+ $error = $rug->replace;
+ die $error if $error;
+ }
+}
+
+=back
=head1 SEE ALSO
-L<svc_acct>, L<FS::Record>, schema.html from the base documentation.
+L<svc_acct>, L<FS::radius_group>, L<FS::Record>, schema.html from the base documentation.
=cut
Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -w -d -r1.48 -r1.49
--- Upgrade.pm 19 Apr 2011 23:49:39 -0000 1.48
+++ Upgrade.pm 21 Jun 2011 01:04:55 -0000 1.49
@@ -191,6 +191,9 @@
#insert MSA data if not already present
'msa' => [],
+ # migrate to radius_group and groupnum instead of groupname
+ 'radius_usergroup' => [],
+
;
\%hash;
Index: part_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_svc.pm,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -w -d -r1.37 -r1.38
--- part_svc.pm 1 Apr 2011 02:52:12 -0000 1.37
+++ part_svc.pm 21 Jun 2011 01:04:55 -0000 1.38
@@ -672,7 +672,8 @@
=item def_label - Optional description of the field in the context of service definitions
-=item type - Currently "text", "select", "disabled", or "radius_usergroup_selector"
+=item type - Currently "text", "select", "checkbox", "textarea", "disabled",
+some components specified by "select-.*.html", and a bunch more...
=item disable_default - This field should not allow a default value in service definitions
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.313
retrieving revision 1.314
diff -u -w -d -r1.313 -r1.314
--- svc_acct.pm 14 Jun 2011 22:08:24 -0000 1.313
+++ svc_acct.pm 21 Jun 2011 01:04:55 -0000 1.314
@@ -43,6 +43,7 @@
use FS::raddb;
use FS::queue;
use FS::radius_usergroup;
+use FS::radius_group;
use FS::export_svc;
use FS::part_export;
use FS::svc_forward;
@@ -335,7 +336,7 @@
},
'usergroup' => {
label => 'RADIUS groups',
- type => 'radius_usergroup_selector',
+ type => 'select-radius_group.html',
disable_inventory => 1,
disable_select => 1,
},
@@ -709,10 +710,10 @@
}
if ( $self->usergroup ) {
- foreach my $groupname ( @{$self->usergroup} ) {
+ foreach my $groupnum ( @{$self->usergroup} ) {
my $radius_usergroup = new FS::radius_usergroup ( {
svcnum => $self->svcnum,
- groupname => $groupname,
+ groupnum => $groupnum,
} );
my $error = $radius_usergroup->insert;
if ( $error ) {
@@ -1010,7 +1011,7 @@
$error = $new->check;
return $error if $error;
- $old->usergroup( [ $old->radius_groups ] );
+ $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";
@@ -1025,7 +1026,7 @@
}
my $radius_usergroup = qsearchs('radius_usergroup', {
svcnum => $old->svcnum,
- groupname => $oldgroup,
+ groupnum => $oldgroup,
} );
my $error = $radius_usergroup->delete;
if ( $error ) {
@@ -1037,7 +1038,7 @@
foreach my $newgroup ( @newgroups ) {
my $radius_usergroup = new FS::radius_usergroup ( {
svcnum => $new->svcnum,
- groupname => $newgroup,
+ groupnum => $newgroup,
} );
my $error = $radius_usergroup->insert;
if ( $error ) {
@@ -2560,8 +2561,18 @@
#radius_usergroup records can be inserted...
@{$self->usergroup};
} else {
- map { $_->groupname }
- qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
+ 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;
}
}
@@ -3102,56 +3113,6 @@
}
-
-=item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
-
-=cut
-
-sub radius_usergroup_selector {
- my $sel_groups = shift;
- my %sel_groups = map { $_=>1 } @$sel_groups;
-
- my $selectname = shift || 'radius_usergroup';
-
- my $dbh = dbh;
- my $sth = $dbh->prepare(
- 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
- ) or die $dbh->errstr;
- $sth->execute() or die $sth->errstr;
- my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
-
- my $html = <<END;
- <SCRIPT>
- function ${selectname}_doadd(object) {
- var myvalue = object.${selectname}_add.value;
- var optionName = new Option(myvalue,myvalue,false,true);
- var length = object.$selectname.length;
- object.$selectname.options[length] = optionName;
- object.${selectname}_add.value = "";
- }
- </SCRIPT>
- <SELECT MULTIPLE NAME="$selectname">
-END
-
- foreach my $group ( @all_groups ) {
- $html .= qq(<OPTION VALUE="$group");
- if ( $sel_groups{$group} ) {
- $html .= ' SELECTED';
- $sel_groups{$group} = 0;
- }
- $html .= ">$group</OPTION>\n";
- }
- foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
- $html .= qq(<OPTION VALUE="$group" SELECTED>$group</OPTION>\n);
- };
- $html .= '</SELECT>';
-
- $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
- qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
-
- $html;
-}
-
=item reached_threshold
Performs some activities when svc_acct thresholds (such as number of seconds
@@ -3241,9 +3202,6 @@
current object. This is probably a bug as it's unexpected and
counterintuitive.
-radius_usergroup_selector? putting web ui components in here? they should
-probably live somewhere else...
-
insertion of RADIUS group stuff in insert could be done with child_objects now
(would probably clean up export of them too)
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.306
retrieving revision 1.307
diff -u -w -d -r1.306 -r1.307
--- Schema.pm 16 Jun 2011 23:06:19 -0000 1.306
+++ Schema.pm 21 Jun 2011 01:04:55 -0000 1.307
@@ -2329,13 +2329,25 @@
'columns' => [
'usergroupnum', 'serial', '', '', '', '',
'svcnum', 'int', '', '', '', '',
- 'groupname', 'varchar', '', $char_d, '', '',
+ 'groupname', 'varchar', 'NULL', $char_d, '', '',
+ 'groupnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'usergroupnum',
'unique' => [],
'index' => [ [ 'svcnum' ], [ 'groupname' ] ],
},
+ 'radius_group' => {
+ 'columns' => [
+ 'groupnum', 'serial', '', '', '', '',
+ 'groupname', 'varchar', '', $char_d, '', '',
+ 'description', 'varchar', 'NULL', $char_d, '', '',
+ ],
+ 'primary_key' => 'groupnum',
+ 'unique' => [ ['groupname'] ],
+ 'index' => [],
+ },
+
'msgcat' => {
'columns' => [
'msgnum', 'serial', '', '', '', '',
--- NEW FILE: radius_group.pm ---
package FS::radius_group;
use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs );
=head1 NAME
FS::radius_group - Object methods for radius_group records
=head1 SYNOPSIS
use FS::radius_group;
$record = new FS::radius_group \%hash;
$record = new FS::radius_group { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::radius_group object represents a RADIUS group. FS::radius_group inherits from
FS::Record. The following fields are currently supported:
=over 4
=item groupnum
primary key
=item groupname
groupname
=item description
description
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new RADIUS group. To add the RADIUS group to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'radius_group'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
# the insert method can be inherited from FS::Record
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
# the replace method can be inherited from FS::Record
=item check
Checks all fields to make sure this is a valid RADIUS group. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_numbern('groupnum')
|| $self->ut_text('groupname')
|| $self->ut_textn('description')
;
return $error if $error;
$self->SUPER::check;
}
=back
=head1 BUGS
This isn't export-specific (i.e. groups are globally unique, as opposed to being
unique per-export).
=head1 SEE ALSO
L<FS::radius_usergroup>, L<FS::Record>, schema.html from the base documentation.
=cut
1;
More information about the freeside-commits
mailing list