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',
191 'List customers' => 'List all customers',
192 'List all customers' => 'Advanced customer search',
193 'List packages' => 'Summarize packages',
194 'Post payment' => 'Backdate payment',
195 'Cancel customer package immediately' => 'Un-cancel customer package',
196 'Suspend customer package' => 'Suspend customer',
197 'Unsuspend customer package' => 'Unsuspend customer',
198 'New prospect' => 'Generate quotation',
199 'Delete invoices' => 'Void invoices',
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',
221 'List rating data' => [ 'Usage: RADIUS sessions',
222 'Usage: Call Detail Records (CDRs)',
223 'Usage: Unrateable CDRs',
227 foreach my $old_acl ( keys %onetime ) {
229 my @new_acl = ref($onetime{$old_acl})
230 ? @{ $onetime{$old_acl} }
231 : ( $onetime{$old_acl} );
233 foreach my $new_acl ( @new_acl ) {
235 ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/\W/_/g;
236 next if FS::upgrade_journal->is_done($journal);
238 # grant $new_acl to all groups who have $old_acl
239 for my $group (@all_groups) {
240 next unless $group->access_right($old_acl);
241 next if $group->access_right($new_acl);
242 my $access_right = FS::access_right->new( {
243 'righttype' => 'FS::access_group',
244 'rightobjnum' => $group->groupnum,
245 'rightname' => $new_acl,
247 my $error = $access_right->insert;
248 die $error if $error;
251 FS::upgrade_journal->set_done($journal);
257 ### ACL_download_report_data
258 if ( !FS::upgrade_journal->is_done('ACL_download_report_data') ) {
261 for my $group (@all_groups) {
262 my $access_right = FS::access_right->new( {
263 'righttype' => 'FS::access_group',
264 'rightobjnum' => $group->groupnum,
265 'rightname' => 'Download report data',
267 my $error = $access_right->insert;
268 die $error if $error;
271 FS::upgrade_journal->set_done('ACL_download_report_data');
284 L<FS::Record>, schema.html from the base documentation.