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' ],
155 'Regular void' => [ 'Void payments' ],
156 'Unvoid' => [ 'Unvoid payments', 'Unvoid invoices' ],
159 foreach my $oldright (keys %migrate) {
160 my @old = qsearch('access_right', { 'righttype'=>'FS::access_group',
161 'rightname'=>$oldright,
165 foreach my $old ( @old ) {
167 foreach my $newright ( @{ $migrate{$oldright} } ) {
169 'righttype' => 'FS::access_group',
170 'rightobjnum' => $old->rightobjnum,
171 'rightname' => $newright,
173 next if qsearchs('access_right', \%hash);
174 my $access_right = new FS::access_right \%hash;
175 my $error = $access_right->insert;
176 die $error if $error;
179 unless ( $oldright =~ / (payment|refund)$/ ) { #after the WEST stuff is sorted
180 my $error = $old->delete;
181 die $error if $error;
188 my @all_groups = qsearch('access_group', {});
190 #tie my %onetime, 'Tie::IxHash',
192 'List customers' => 'List all customers',
193 'List all customers' => 'Advanced customer search',
194 'List packages' => 'Summarize packages',
195 'Post payment' => 'Backdate payment',
196 'Cancel customer package immediately' => 'Un-cancel customer package',
197 'Suspend customer package' => 'Suspend customer',
198 'Unsuspend customer package' => 'Unsuspend customer',
199 'New prospect' => 'Generate quotation',
200 'Delete invoices' => 'Void invoices',
201 'List invoices' => 'List quotations',
202 'Post credit' => 'Credit line items',
203 #'View customer tax exemptions' => 'Edit customer tax exemptions',
204 'Edit customer' => 'Edit customer tax exemptions',
205 'Edit package definitions' => 'Bulk edit package definitions',
207 'List services' => [ 'Services: Accounts',
209 'Services: Certificates',
210 'Services: Mail forwards',
211 'Services: Virtual hosting services',
212 'Services: Wireless broadband services',
214 'Services: Dish services',
215 'Services: Hardware',
216 'Services: Phone numbers',
219 'Services: Mailing lists',
220 'Services: External services',
223 'Services: Accounts' => 'Services: Accounts: Advanced search',
224 'Services: Wireless broadband services' => 'Services: Wireless broadband services: Advanced search',
225 'Services: Hardware' => 'Services: Hardware: Advanced search',
226 'Services: Phone numbers' => 'Services: Phone numbers: Advanced search',
228 'Services: Accounts' => 'Services: Alarm services',
230 'List rating data' => [ 'Usage: RADIUS sessions',
231 'Usage: Call Detail Records (CDRs)',
232 'Usage: Unrateable CDRs',
234 'Provision customer service' => [ 'Edit password' ],
235 'Financial reports' => [ 'Employees: Commission Report',
236 'Employees: Audit Report',
238 'Change customer package' => 'Detach customer package',
239 'Services: Accounts' => 'Services: Cable Subscribers',
240 'Bulk change customer packages' => 'Bulk move customer services',
241 'Configuration' => 'Edit sales people',
242 'Configuration' => 'Alarm global configuration',
243 'Services: Accounts' => 'Services: Conferencing',
244 'Services: Accounts' => 'Services: Video',
247 # foreach my $old_acl ( keys %onetime ) {
249 # my @new_acl = ref($onetime{$old_acl})
250 # ? @{ $onetime{$old_acl} }
251 # : ( $onetime{$old_acl} );
255 my( $old_acl, $new_acl ) = splice(@onetime, 0, 2);
256 my @new_acl = ref($new_acl) ? @$new_acl : ( $new_acl );
258 foreach my $new_acl ( @new_acl ) {
260 ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/\W/_/g;
261 next if FS::upgrade_journal->is_done($journal);
263 # grant $new_acl to all groups who have $old_acl
264 for my $group (@all_groups) {
265 next unless $group->access_right($old_acl);
266 next if $group->access_right($new_acl);
267 my $access_right = FS::access_right->new( {
268 'righttype' => 'FS::access_group',
269 'rightobjnum' => $group->groupnum,
270 'rightname' => $new_acl,
272 my $error = $access_right->insert;
273 die $error if $error;
276 FS::upgrade_journal->set_done($journal);
282 ### ACL_download_report_data
283 if ( !FS::upgrade_journal->is_done('ACL_download_report_data') ) {
286 for my $group (@all_groups) {
287 my $access_right = FS::access_right->new( {
288 'righttype' => 'FS::access_group',
289 'rightobjnum' => $group->groupnum,
290 'rightname' => 'Download report data',
292 my $error = $access_right->insert;
293 warn $error if $error;
296 FS::upgrade_journal->set_done('ACL_download_report_data');
309 L<FS::Record>, schema.html from the base documentation.