1 package FS::access_right;
6 use FS::Record qw( qsearch qsearchs );
7 use FS::upgrade_journal;
10 @ISA = qw(FS::Record);
14 FS::access_right - Object methods for access_right records
20 $record = new FS::access_right \%hash;
21 $record = new FS::access_right { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::access_right object represents a granted access right. FS::access_right
34 inherits from FS::Record. The following fields are currently supported:
38 =item rightnum - primary key
55 Creates a new right. To add the right to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 # the new method can be inherited from FS::Record, if a table method is defined
64 sub table { 'access_right'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
73 # the insert method can be inherited from FS::Record
77 Delete this record from the database.
81 # the delete method can be inherited from FS::Record
83 =item replace OLD_RECORD
85 Replaces the OLD_RECORD with this one in the database. If there is an error,
86 returns the error, otherwise returns false.
90 # the replace method can be inherited from FS::Record
94 Checks all fields to make sure this is a valid right. If there is
95 an error, returns the error, otherwise returns false. Called by the insert
100 # the check method should currently be supplied - FS::Record contains some
101 # data checking routines
107 $self->ut_numbern('rightnum')
108 || $self->ut_text('righttype')
109 || $self->ut_text('rightobjnum')
110 || $self->ut_text('rightname')
112 return $error if $error;
119 # Used by FS::Upgrade to migrate to a new database.
121 sub _upgrade_data { # class method
122 my ($class, %opts) = @_;
124 my @unmigrated = ( qsearch( 'access_right',
125 { 'righttype'=>'FS::access_group',
126 'rightname'=>'Engineering configuration',
129 qsearch( 'access_right',
130 { 'righttype'=>'FS::access_group',
131 'rightname'=>'Engineering global configuration',
135 foreach ( @unmigrated ) {
136 my $rightname = $_->rightname;
137 $rightname =~ s/Engineering/Dialup/;
138 $_->rightname($rightname);
139 my $error = $_->replace;
140 die "Failed to update access right: $error"
142 my $broadband = new FS::access_right { $_->hash };
143 $rightname =~ s/Dialup/Broadband/;
144 $broadband->rightnum('');
145 $broadband->rightname($rightname);
146 $error = $broadband->insert;
147 die "Failed to insert access right: $error"
152 'Post payment' => [ 'Post check payment', 'Post cash payment' ],
153 'Process payment' => [ 'Process credit card payment', 'Process Echeck payment' ],
154 'Post refund' => [ 'Post check refund', 'Post cash refund' ],
155 'Refund payment' => [ 'Refund credit card payment', 'Refund Echeck payment' ],
158 foreach my $oldright (keys %migrate) {
159 my @old = qsearch('access_right', { 'righttype'=>'FS::access_group',
160 'rightname'=>$oldright,
164 foreach my $old ( @old ) {
166 foreach my $newright ( @{ $migrate{$oldright} } ) {
168 'righttype' => 'FS::access_group',
169 'rightobjnum' => $old->rightobjnum,
170 'rightname' => $newright,
172 next if qsearchs('access_right', \%hash);
173 my $access_right = new FS::access_right \%hash;
174 my $error = $access_right->insert;
175 die $error if $error;
178 #after the WEST stuff is sorted, etc.
179 #my $error = $old->delete;
180 #die $error if $error;
186 my @all_groups = qsearch('access_group', {});
188 tie my %onetime, 'Tie::IxHash',
189 'List customers' => 'List all customers',
190 'List all customers' => 'Advanced customer search',
191 'List packages' => 'Summarize packages',
192 'Post payment' => 'Backdate payment',
193 'Cancel customer package immediately' => 'Un-cancel customer package',
194 'Suspend customer package' => 'Suspend customer',
195 'Unsuspend customer package' => 'Unsuspend customer',
196 'Post credit' => 'Credit line items',
197 #'View customer tax exemptions' => 'Edit customer tax exemptions',
198 'Edit customer' => 'Edit customer tax exemptions',
199 'Edit package definitions' => 'Bulk edit package definitions',
201 'List services' => [ 'Services: Accounts',
203 'Services: Certificates',
204 'Services: Mail forwards',
205 'Services: Virtual hosting services',
206 'Services: Wireless broadband services',
208 'Services: Dish services',
209 'Services: Hardware',
210 'Services: Phone numbers',
213 'Services: Mailing lists',
214 'Services: External services',
217 'Services: Accounts' => 'Services: Accounts: Advanced search',
218 'Services: Wireless broadband services' => 'Services: Wireless broadband services: Advanced search',
219 'Services: Hardware' => 'Services: Hardware: Advanced search',
220 'Services: Phone numbers' => 'Services: Phone numbers: Advanced search',
222 'List rating data' => [ 'Usage: RADIUS sessions',
223 'Usage: Call Detail Records (CDRs)',
224 'Usage: Unrateable CDRs',
227 'Edit customer' => [ 'Edit customer basics',
228 'Edit customer addresses',
229 'Edit customer contacts',
232 'Provision customer service' => [ 'Edit password' ],
234 'Financial reports' => [ 'Employees: Commission Report',
235 'Employees: Audit Report',
237 'Services: Accounts' => 'Services: Cable Subscribers',
240 foreach my $old_acl ( keys %onetime ) {
242 my @new_acl = ref($onetime{$old_acl})
243 ? @{ $onetime{$old_acl} }
244 : ( $onetime{$old_acl} );
246 foreach my $new_acl ( @new_acl ) {
248 ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/\W/_/g;
249 next if FS::upgrade_journal->is_done($journal);
251 # grant $new_acl to all groups who have $old_acl
252 for my $group (@all_groups) {
253 next unless $group->access_right($old_acl);
254 next if $group->access_right($new_acl);
255 my $access_right = FS::access_right->new( {
256 'righttype' => 'FS::access_group',
257 'rightobjnum' => $group->groupnum,
258 'rightname' => $new_acl,
260 my $error = $access_right->insert;
261 die $error if $error;
264 FS::upgrade_journal->set_done($journal);
270 ### ACL_download_report_data
271 if ( !FS::upgrade_journal->is_done('ACL_download_report_data') ) {
274 for my $group (@all_groups) {
275 my $access_right = FS::access_right->new( {
276 'righttype' => 'FS::access_group',
277 'rightobjnum' => $group->groupnum,
278 'rightname' => 'Download report data',
280 my $error = $access_right->insert;
281 warn $error if $error;
284 FS::upgrade_journal->set_done('ACL_download_report_data');
297 L<FS::Record>, schema.html from the base documentation.