RADIUS group attributes, #15017
[freeside.git] / FS / FS / radius_group.pm
1 package FS::radius_group;
2
3 use strict;
4 use base qw( FS::o2m_Common FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::radius_attr;
7
8 =head1 NAME
9
10 FS::radius_group - Object methods for radius_group records
11
12 =head1 SYNOPSIS
13
14   use FS::radius_group;
15
16   $record = new FS::radius_group \%hash;
17   $record = new FS::radius_group { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::radius_group object represents a RADIUS group.  FS::radius_group inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item groupnum
35
36 primary key
37
38 =item groupname
39
40 groupname
41
42 =item description
43
44 description
45
46 =item priority
47
48 priority - for export
49
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new RADIUS group.  To add the RADIUS group to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 # the new method can be inherited from FS::Record, if a table method is defined
67
68 sub table { 'radius_group'; }
69
70 =item insert
71
72 Adds this record to the database.  If there is an error, returns the error,
73 otherwise returns false.
74
75 =cut
76
77 # the insert method can be inherited from FS::Record
78
79 =item delete
80
81 Delete this record from the database.
82
83 =cut
84
85 # I'd delete any linked attributes here but we don't really support group
86 # deletion.  We would also have to delete linked records from 
87 # radius_usergroup and part_svc_column...
88
89 =item replace OLD_RECORD
90
91 Replaces the OLD_RECORD with this one in the database.  If there is an error,
92 returns the error, otherwise returns false.
93
94 =cut
95
96 # To keep these things from proliferating, we will follow the same 
97 # export/noexport switches that radius_attr uses.  If you _don't_ use
98 # Freeside to maintain your RADIUS group attributes, then it probably 
99 # shouldn't try to rename groups either.
100
101 sub replace {
102   my ($self, $old) = @_;
103   $old ||= $self->replace_old;
104
105   my $error = $self->check;
106   return $error if $error;
107
108   if ( !$FS::radius_attr::noexport_hack ) {
109     foreach ( qsearch('part_export', {}) ) {
110       next if !$_->option('export_attrs',1);
111       $error = $_->export_group_replace($self, $old);
112       return $error if $error;
113     }
114   }
115
116   $self->SUPER::replace($old);
117 }
118
119 =item check
120
121 Checks all fields to make sure this is a valid RADIUS group.  If there is
122 an error, returns the error, otherwise returns false.  Called by the insert
123 and replace methods.
124
125 =cut
126
127 # the check method should currently be supplied - FS::Record contains some
128 # data checking routines
129
130 sub check {
131   my $self = shift;
132
133   my $error = 
134     $self->ut_numbern('groupnum')
135     || $self->ut_text('groupname')
136     || $self->ut_textn('description')
137     || $self->ut_numbern('priority')
138   ;
139   return $error if $error;
140
141   $self->SUPER::check;
142 }
143
144 =item long_description
145
146 Returns a description for this group consisting of its description field, 
147 if any, and the RADIUS group name.
148
149 =cut
150
151 sub long_description {
152     my $self = shift;
153     $self->description ? $self->description . " (". $self->groupname . ")"
154                        : $self->groupname;
155 }
156
157 =item radius_attr
158
159 Returns all L<FS::radius_attr> objects (check and reply attributes) for 
160 this group.
161
162 =cut
163
164 sub radius_attr {
165   my $self = shift;
166   qsearch({
167       table   => 'radius_attr', 
168       hashref => {'groupnum' => $self->groupnum },
169       order_by  => 'ORDER BY attrtype, attrname',
170   })
171 }
172
173 =back
174
175 =head1 BUGS
176
177 This isn't export-specific (i.e. groups are globally unique, as opposed to being
178 unique per-export).
179
180 =head1 SEE ALSO
181
182 L<FS::radius_usergroup>, L<FS::Record>, schema.html from the base documentation.
183
184 =cut
185
186 1;
187