1 package FS::access_right;
6 use FS::Record qw( qsearch qsearchs );
7 use FS::upgrade_journal;
13 FS::access_right - Object methods for access_right records
19 $record = new FS::access_right \%hash;
20 $record = new FS::access_right { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::access_right object represents a granted access right. FS::access_right
33 inherits from FS::Record. The following fields are currently supported:
37 =item rightnum - primary key
54 Creates a new right. To add the right to the database, see L<"insert">.
56 Note that this stores the hash reference, not a distinct copy of the hash it
57 points to. You can ask the object for a copy with the I<hash> method.
61 # the new method can be inherited from FS::Record, if a table method is defined
63 sub table { 'access_right'; }
67 Adds this record to the database. If there is an error, returns the error,
68 otherwise returns false.
72 # the insert method can be inherited from FS::Record
76 Delete this record from the database.
80 # the delete method can be inherited from FS::Record
82 =item replace OLD_RECORD
84 Replaces the OLD_RECORD with this one in the database. If there is an error,
85 returns the error, otherwise returns false.
89 # the replace method can be inherited from FS::Record
93 Checks all fields to make sure this is a valid right. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
99 # the check method should currently be supplied - FS::Record contains some
100 # data checking routines
106 $self->ut_numbern('rightnum')
107 || $self->ut_text('righttype')
108 || $self->ut_text('rightobjnum')
109 || $self->ut_text('rightname')
111 return $error if $error;
118 # Used by FS::Upgrade to migrate to a new database.
120 sub _upgrade_data { # class method
121 my ($class, %opts) = @_;
123 my @unmigrated = ( qsearch( 'access_right',
124 { 'righttype'=>'FS::access_group',
125 'rightname'=>'Engineering configuration',
128 qsearch( 'access_right',
129 { 'righttype'=>'FS::access_group',
130 'rightname'=>'Engineering global configuration',
134 foreach ( @unmigrated ) {
135 my $rightname = $_->rightname;
136 $rightname =~ s/Engineering/Dialup/;
137 $_->rightname($rightname);
138 my $error = $_->replace;
139 die "Failed to update access right: $error"
141 my $broadband = new FS::access_right { $_->hash };
142 $rightname =~ s/Dialup/Broadband/;
143 $broadband->rightnum('');
144 $broadband->rightname($rightname);
145 $error = $broadband->insert;
146 die "Failed to insert access right: $error"
151 'Post payment' => [ 'Post check payment', 'Post cash payment' ],
152 'Process payment' => [ 'Process credit card payment', 'Process Echeck payment' ],
153 'Post refund' => [ 'Post check refund', 'Post cash refund' ],
154 'Refund payment' => [ 'Refund credit card payment', 'Refund Echeck payment' ],
157 foreach my $oldright (keys %migrate) {
158 my @old = qsearch('access_right', { 'righttype'=>'FS::access_group',
159 'rightname'=>$oldright,
163 foreach my $old ( @old ) {
165 foreach my $newright ( @{ $migrate{$oldright} } ) {
167 'righttype' => 'FS::access_group',
168 'rightobjnum' => $old->rightobjnum,
169 'rightname' => $newright,
171 next if qsearchs('access_right', \%hash);
172 my $access_right = new FS::access_right \%hash;
173 my $error = $access_right->insert;
174 die $error if $error;
177 #after the WEST stuff is sorted, etc.
178 #my $error = $old->delete;
179 #die $error if $error;
185 my @all_groups = qsearch('access_group', {});
187 tie my %onetime, 'Tie::IxHash',
188 'List customers' => 'List all customers',
189 'List all customers' => 'Advanced customer search',
190 'List packages' => 'Summarize packages',
191 'Post payment' => 'Backdate payment',
192 'Cancel customer package immediately' => 'Un-cancel customer package',
193 'Suspend customer package' => 'Suspend customer',
194 'Unsuspend customer package' => 'Unsuspend customer',
195 'Post credit' => 'Credit line items',
196 #'View customer tax exemptions' => 'Edit customer tax exemptions',
197 'Edit customer' => 'Edit customer tax exemptions',
198 'Edit package definitions' => 'Bulk edit package definitions',
200 'List services' => [ 'Services: Accounts',
202 'Services: Certificates',
203 'Services: Mail forwards',
204 'Services: Virtual hosting services',
205 'Services: Wireless broadband services',
207 'Services: Dish services',
208 'Services: Hardware',
209 'Services: Phone numbers',
212 'Services: Mailing lists',
213 'Services: External services',
216 'Services: Accounts' => 'Services: Accounts: Advanced search',
217 'Services: Wireless broadband services' => 'Services: Wireless broadband services: Advanced search',
218 'Services: Hardware' => 'Services: Hardware: Advanced search',
219 'Services: Phone numbers' => 'Services: Phone numbers: Advanced search',
221 'List rating data' => [ 'Usage: RADIUS sessions',
222 'Usage: Call Detail Records (CDRs)',
223 'Usage: Unrateable CDRs',
226 'Edit customer' => [ 'Edit customer basics',
227 'Edit customer addresses',
228 'Edit customer contacts',
231 'Provision customer service' => [ 'Edit password' ],
233 'Financial reports' => [ 'Employees: Commission Report',
234 'Employees: Audit Report',
236 'Services: Accounts' => 'Services: Cable Subscribers',
239 foreach my $old_acl ( keys %onetime ) {
241 my @new_acl = ref($onetime{$old_acl})
242 ? @{ $onetime{$old_acl} }
243 : ( $onetime{$old_acl} );
245 foreach my $new_acl ( @new_acl ) {
247 ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/\W/_/g;
248 next if FS::upgrade_journal->is_done($journal);
250 # grant $new_acl to all groups who have $old_acl
251 for my $group (@all_groups) {
252 next unless $group->access_right($old_acl);
253 next if $group->access_right($new_acl);
254 my $access_right = FS::access_right->new( {
255 'righttype' => 'FS::access_group',
256 'rightobjnum' => $group->groupnum,
257 'rightname' => $new_acl,
259 my $error = $access_right->insert;
260 die $error if $error;
263 FS::upgrade_journal->set_done($journal);
269 ### ACL_download_report_data
270 if ( !FS::upgrade_journal->is_done('ACL_download_report_data') ) {
273 for my $group (@all_groups) {
274 my $access_right = FS::access_right->new( {
275 'righttype' => 'FS::access_group',
276 'rightobjnum' => $group->groupnum,
277 'rightname' => 'Download report data',
279 my $error = $access_right->insert;
280 warn $error if $error;
283 FS::upgrade_journal->set_done('ACL_download_report_data');
296 L<FS::Record>, schema.html from the base documentation.