1 package FS::access_right;
5 use FS::Record qw( qsearch qsearchs );
6 use FS::upgrade_journal;
12 FS::access_right - Object methods for access_right records
18 $record = new FS::access_right \%hash;
19 $record = new FS::access_right { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::access_right object represents a granted access right. FS::access_right
32 inherits from FS::Record. The following fields are currently supported:
36 =item rightnum - primary key
53 Creates a new right. To add the right to the database, see L<"insert">.
55 Note that this stores the hash reference, not a distinct copy of the hash it
56 points to. You can ask the object for a copy with the I<hash> method.
60 # the new method can be inherited from FS::Record, if a table method is defined
62 sub table { 'access_right'; }
66 Adds this record to the database. If there is an error, returns the error,
67 otherwise returns false.
71 # the insert method can be inherited from FS::Record
75 Delete this record from the database.
79 # the delete method can be inherited from FS::Record
81 =item replace OLD_RECORD
83 Replaces the OLD_RECORD with this one in the database. If there is an error,
84 returns the error, otherwise returns false.
88 # the replace method can be inherited from FS::Record
92 Checks all fields to make sure this is a valid right. If there is
93 an error, returns the error, otherwise returns false. Called by the insert
98 # the check method should currently be supplied - FS::Record contains some
99 # data checking routines
105 $self->ut_numbern('rightnum')
106 || $self->ut_text('righttype')
107 || $self->ut_text('rightobjnum')
108 || $self->ut_text('rightname')
110 return $error if $error;
117 # Used by FS::Upgrade to migrate to a new database.
119 sub _upgrade_data { # class method
120 my ($class, %opts) = @_;
122 my @unmigrated = ( qsearch( 'access_right',
123 { 'righttype'=>'FS::access_group',
124 'rightname'=>'Engineering configuration',
127 qsearch( 'access_right',
128 { 'righttype'=>'FS::access_group',
129 'rightname'=>'Engineering global configuration',
133 foreach ( @unmigrated ) {
134 my $rightname = $_->rightname;
135 $rightname =~ s/Engineering/Dialup/;
136 $_->rightname($rightname);
137 my $error = $_->replace;
138 die "Failed to update access right: $error"
140 my $broadband = new FS::access_right { $_->hash };
141 $rightname =~ s/Dialup/Broadband/;
142 $broadband->rightnum('');
143 $broadband->rightname($rightname);
144 $error = $broadband->insert;
145 die "Failed to insert access right: $error"
150 'Post payment' => [ 'Post check payment', 'Post cash payment' ],
151 'Process payment' => [ 'Process credit card payment', 'Process Echeck payment' ],
152 'Post refund' => [ 'Post check refund', 'Post cash refund' ],
153 'Refund payment' => [ 'Refund credit card payment', 'Refund Echeck payment' ],
156 foreach my $oldright (keys %migrate) {
157 my @old = qsearch('access_right', { 'righttype'=>'FS::access_group',
158 'rightname'=>$oldright,
162 foreach my $old ( @old ) {
164 foreach my $newright ( @{ $migrate{$oldright} } ) {
166 'righttype' => 'FS::access_group',
167 'rightobjnum' => $old->rightobjnum,
168 'rightname' => $newright,
170 next if qsearchs('access_right', \%hash);
171 my $access_right = new FS::access_right \%hash;
172 my $error = $access_right->insert;
173 die $error if $error;
176 #after the WEST stuff is sorted, etc.
177 #my $error = $old->delete;
178 #die $error if $error;
184 my @all_groups = qsearch('access_group', {});
187 'List customers' => 'List all customers',
188 'List packages' => 'Summarize packages',
189 'Post payment' => 'Backdate payment',
190 'Cancel customer package immediately' => 'Un-cancel customer package',
191 'Suspend customer package' => 'Suspend customer',
192 'Unsuspend customer package' => 'Unsuspend customer',
194 'List services' => [ 'Services: Accounts',
196 'Services: Certificates',
197 'Services: Mail forwards',
198 'Services: Virtual hosting services',
199 'Services: Wireless broadband services',
201 'Services: Dish services',
202 'Services: Hardware',
203 'Services: Phone numbers',
206 'Services: Mailing lists',
207 'Services: External services',
209 'List rating data' => [ 'Usage: RADIUS sessions',
210 'Usage: Call Detail Records (CDRs)',
211 'Usage: Unrateable CDRs',
215 foreach my $old_acl ( keys %onetime ) {
217 my @new_acl = ref($onetime{$old_acl})
218 ? @{ $onetime{$old_acl} }
219 : ( $onetime{$old_acl} );
221 foreach my $new_acl ( @new_acl ) {
223 ( my $journal = 'ACL_'.lc($new_acl) ) =~ s/\W/_/g;
224 next if FS::upgrade_journal->is_done($journal);
226 # grant $new_acl to all groups who have $old_acl
227 for my $group (@all_groups) {
228 next unless $group->access_right($old_acl);
229 next if $group->access_right($new_acl);
230 my $access_right = FS::access_right->new( {
231 'righttype' => 'FS::access_group',
232 'rightobjnum' => $group->groupnum,
233 'rightname' => $new_acl,
235 my $error = $access_right->insert;
236 die $error if $error;
239 FS::upgrade_journal->set_done($journal);
245 ### ACL_download_report_data
246 if ( !FS::upgrade_journal->is_done('ACL_download_report_data') ) {
249 for my $group (@all_groups) {
250 my $access_right = FS::access_right->new( {
251 'righttype' => 'FS::access_group',
252 'rightobjnum' => $group->groupnum,
253 'rightname' => 'Download report data',
255 my $error = $access_right->insert;
256 die $error if $error;
259 FS::upgrade_journal->set_done('ACL_download_report_data');
272 L<FS::Record>, schema.html from the base documentation.