fix RADIUS open sessions report (modern mysql & Pg?), RT#14218
[freeside.git] / FS / FS / AccessRight.pm
1 package FS::AccessRight;
2
3 use strict;
4 use vars qw(@rights); # %rights);
5 use Tie::IxHash;
6
7 =head1 NAME
8
9 FS::AccessRight - Access control rights.
10
11 =head1 SYNOPSIS
12
13   use FS::AccessRight;
14
15   my @rights = FS::AccessRight->rights;
16
17   #my %rights = FS::AccessRight->rights_categorized;
18   tie my %rights, 'Tie::IxHash', FS::AccessRight->rights_categorized;
19   foreach my $category ( keys %rights ) {
20     my @category_rights = @{ $rights{$category} };
21   }
22
23 =head1 DESCRIPTION
24
25 Access control rights - Permission to perform specific actions that can be
26 assigned to users and/or groups.
27
28 =cut
29
30 #@rights = (
31 #  'Reports' => [
32 #    '_desc' => 'Access to high-level reporting',
33 #  ],
34 #  'Configuration' => [
35 #    '_desc' => 'Access to configuration',
36 #
37 #    'Settings' => {},
38 #
39 #    'agent' => [
40 #      '_desc' => 'Master access to reseller configuration',
41 #      'agent_type'  => {},
42 #      'agent'       => {},
43 #    ],
44 #
45 #    'export_svc_pkg' => [
46 #      '_desc' => 'Access to export, service and package configuration',
47 #      'part_export' => {},
48 #      'part_svc'    => {},
49 #      'part_pkg'    => {},
50 #      'pkg_class'   => {},
51 #    ],
52 #
53 #    'billing' => [
54 #      '_desc' => 'Access to billing configuration',
55 #      'payment_gateway'  => {},
56 #      'part_bill_event'  => {},
57 #      'prepay_credit'    => {},
58 #      'rate'             => {},
59 #      'cust_main_county' => {},
60 #    ],
61 #
62 #    'dialup' => [
63 #      '_desc' => 'Access to dialup configuraiton',
64 #      'svc_acct_pop' => {},
65 #    ],
66 #
67 #    'broadband' => [
68 #      '_desc' => 'Access to broadband configuration',
69 #      'router'     => {},
70 #      'addr_block' => {},
71 #    ],
72 #
73 #    'misc' => [
74 #      'part_referral'      => {},
75 #      'part_virtual_field' => {},
76 #      'msgcat'             => {},
77 #      'inventory_class'    => {},
78 #    ],
79 #
80 #  },
81 #
82 #);
83 #
84 ##turn it into a more hash-like structure, but ordered via IxHash
85
86 #well, this is what we have for now.  getting better.
87 tie my %rights, 'Tie::IxHash',
88
89   ###
90   # contact rights
91   ###
92   'Contact and Prospect rights' => [
93     'New prospect',
94     'View prospect',
95     'Edit prospect',
96     'List prospects',
97     'Edit contact', #!
98     #'New contact',
99     #'View customer contacts',
100     #'List contacts',
101   ],
102   
103   ###
104   # basic customer rights
105   ###
106   'Customer rights' => [
107     'New customer',
108     'View customer',
109     #'View Customer | View tickets',
110     'Edit customer',
111     'Edit customer basics',
112     'Edit customer tags',
113     'Edit referring customer',
114     'Edit customer addresses',
115     'Edit customer billing information',
116     'View customer history',
117     'Suspend customer',
118     'Unsuspend customer',
119     'Cancel customer',
120     'Complimentary customer', #aka users-allow_comp 
121     'Merge customer',
122     'Merge customer across agents',
123     { rightname=>'Delete customer', desc=>"Enable customer deletions. Be very careful! Deleting a customer will remove all traces that this customer ever existed! It should probably only be used when auditing a legacy database. Normally, you cancel all of a customer's packages if they cancel service." }, #aka. deletecustomers
124     'Bill customer now', #NEW
125     'Bulk send customer notices', #NEW
126     { rightname=>'View customers of all agents', global=>1 },
127   ],
128   
129   ###
130   # customer package rights
131   ###
132   'Customer package rights' => [
133     'View customer packages', #NEW
134     'Order customer package',
135     'One-time charge',
136     'Change customer package',
137     'Bulk change customer packages',
138     'Edit customer package dates',
139     'Discount customer package', #NEW
140     'Custom discount customer package', #NEW
141     'Customize customer package',
142     'Suspend customer package',
143     'Suspend customer package later',
144     'Unsuspend customer package',
145     'Cancel customer package immediately',
146     'Cancel customer package later',
147     'Un-cancel customer package',
148     'Delay suspension events',
149     'Add on-the-fly cancel reason', #NEW
150     'Add on-the-fly suspend reason', #NEW
151     'Edit customer package invoice details', #NEW
152     'Edit customer package comments', #NEW
153     'Qualify service', #NEW
154     'Waive setup fee', #NEW
155   ],
156   
157   ###
158   # customer service rights
159   ###
160   'Customer service rights' => [
161     'View customer services', #NEW
162     'Provision customer service',
163     'Bulk provision customer service',
164     'Recharge customer service', #NEW
165     'Unprovision customer service',
166     'Change customer service', #NEWNEW
167     'Edit usage', #NEW
168     'Edit home dir', #NEW
169     'Edit www config', #NEW
170     'Edit domain catchall', #NEW
171     'Edit domain nameservice', #NEW
172     'Manage domain registration',
173   
174     { rightname=>'View/link unlinked services', global=>1 }, #not agent-virtualizable without more work
175   ],
176   
177   ###
178   # customer invoice/financial info rights
179   ###
180   'Customer invoice / financial info rights' => [
181     'View invoices',
182     'Resend invoices', #NEWNEW
183     'Delete invoices', #new, but no need to phase in
184     'View customer tax exemptions', #yow
185     'Add customer tax adjustment', #new, but no need to phase in
186     'View customer batched payments', #NEW
187     'View customer pending payments', #NEW
188     'Edit customer pending payments', #NEW
189     'View customer billing events', #NEW
190   ],
191   
192   ###
193   # customer payment rights
194   ###
195   'Customer payment rights' => [
196     'View payments',
197     { rightname=>'Post payment', desc=>'Make check or cash payments.' },
198     { rightname=>'Backdate payment', desc=>'Enable payments to be posted for days other than today.' },
199     'Post check payment',
200     'Post cash payment',
201     'Post payment batch',
202     'Apply payment', #NEWNEW
203     { rightname=>'Unapply payment', desc=>'Enable "unapplication" of unclosed payments from specific invoices.' }, #aka. unapplypayments
204     { rightname=>'Process payment', desc=>'Process credit card or e-check payments' },
205     'Process credit card payment',
206     'Process Echeck payment',
207     { rightname=>'Delete payment', desc=>'Enable deletion of unclosed payments. Be very careful!  Only delete payments that were data-entry errors, not adjustments.' }, #aka. deletepayments Optionally specify one or more comma-separated email addresses to be notified when a payment is deleted.
208   ],
209   
210   ###
211   # customer credit rights
212   ###
213   'Customer credit and refund rights' => [
214     'Post credit',
215     'Credit line items', #NEWNEWNEW
216     'Apply credit', #NEWNEW
217     { rightname=>'Unapply credit', desc=>'Enable "unapplication" of unclosed credits.' }, #aka unapplycredits
218     { rightname=>'Delete credit', desc=>'Enable deletion of unclosed credits. Be very careful!  Only delete credits that were data-entry errors, not adjustments.' }, #aka. deletecredits Optionally specify one or more comma-separated email addresses to be notified when a credit is deleted.
219     'View refunds',
220     { rightname=>'Post refund', desc=>'Enable posting of check and cash refunds.' },
221     'Post check refund',
222     'Post cash refund',
223 #    { rightname=>'Process refund', desc=>'Enable processing of generic credit card/ACH refunds (i.e. not associated with a specific prior payment).' },
224     { rightname=>'Refund payment', desc=>'Enable refund of existing customer credit card or e-check payments.' },
225     'Refund credit card payment',
226     'Refund Echeck payment',
227     'Delete refund', #NEW
228     'Add on-the-fly credit reason', #NEW
229   ],
230   
231   ###
232   # customer voiding rights..
233   ###
234   'Customer void rights' => [
235     { rightname=>'Credit card void', desc=>'Enable local-only voiding of echeck payments in addition to refunds against the payment gateway.' }, #aka. cc-void 
236     { rightname=>'Echeck void', desc=>'Enable local-only voiding of echeck payments in addition to refunds against the payment gateway.' }, #aka. echeck-void
237     'Regular void',
238     { rightname=>'Unvoid', desc=>'Enable unvoiding of voided payments' }, #aka. unvoid 
239     
240   
241   ],
242  
243   ###
244   # note/attachment rights...
245   ###
246   'Customer note and attachment rights' => [
247     'Add customer note', #NEW
248     'Edit customer note', #NEW
249     'View attachments', #NEW
250     'Browse attachments', #NEW
251     'Download attachment', #NEW
252     'Add attachment', #NEW
253     'Edit attachment', #NEW
254     'Delete attachment', #NEW
255     'View deleted attachments', #NEW
256     'Undelete attachment', #NEW
257     'Purge attachment', #NEW
258   ],
259   
260   ###
261   # report/listing rights...
262   ###
263   'Reporting/listing rights' => [
264     'List customers',
265     'List all customers',
266     'Advanced customer search',
267     'List zip codes', #NEW
268     'List invoices',
269     'List packages',
270     'Summarize packages',
271     'List services',
272     'List service passwords',
273   
274     { rightname=> 'List rating data', desc=>'Usage reports', global=>1 },
275     'Billing event reports',
276     'Receivables report',
277     'Financial reports',
278     { rightname=> 'List inventory', global=>1 },
279     { rightname=>'View email logs', global=>1 },
280     { rightname=>'View system logs' },
281
282     'Download report data',
283     'Services: Accounts',
284     'Services: Accounts: Advanced search',
285     'Services: Domains',
286     'Services: Certificates',
287     'Services: Mail forwards',
288     'Services: Virtual hosting services',
289     'Services: Wireless broadband services',
290     'Services: Wireless broadband services: Advanced search',
291     'Services: DSLs',
292     'Services: Dish services',
293     'Services: Hardware',
294     'Services: Hardware: Advanced search',
295     'Services: Phone numbers',
296     'Services: Phone numbers: Advanced search',
297     'Services: PBXs',
298     'Services: Ports',
299     'Services: Mailing lists',
300     'Services: External services',
301     'Usage: RADIUS sessions',
302     'Usage: Call Detail Records (CDRs)',
303     'Usage: Unrateable CDRs',
304     'Usage: Time worked',
305
306     #{ rightname => 'List customers of all agents', global=>1 },
307   ],
308   
309   ###
310   # misc rights
311   ###
312   'Miscellaneous rights' => [
313     { rightname=>'Job queue', global=>1 },
314     { rightname=>'Time queue', global=>1 },
315     { rightname=>'Process batches', }, #Process payment batches
316     { rightname=>'Process global batches', global=>1 }, #Process global payment batches
317     { rightname=>'Reprocess batches', global=>1 }, #Reprocess payment batches
318     { rightname=>'Redownload resolved batches', global=>1 }, #Redownload resolved payment batches
319     { rightname=>'Process invoice batches', },
320     { rightname=>'Process global invoice batches', global=>1 },
321     { rightname=>'Import', global=>1 }, #some of these are ag-virt'ed now?  give em their own ACLs
322     { rightname=>'Export', global=>1 },
323     { rightname=> 'Edit rating data', desc=>'Delete CDRs', global=>1 },
324   #],
325   #
326   ###
327   # misc misc rights
328   ###
329   #'Database access rights' => [
330     { rightname=>'Raw SQL', global=>1 }, #NEW
331   ],
332   
333   ###
334   # setup/config rights
335   ###
336   'Configuration rights' => [
337     'Edit advertising sources',
338     { rightname=>'Edit global advertising sources', global=>1 },
339
340     'Edit package definitions',
341     { rightname=>'Edit global package definitions', global=>1 },
342   
343     'Edit billing events',
344     { rightname=>'Edit global billing events', global=>1 },
345
346     'View templates',
347     { rightname=>'View global templates', global=>1 },
348     'Edit templates',
349     { rightname=>'Edit global templates', global=>1 },
350
351     'Edit inventory',
352     { rightname=>'Edit global inventory', global=>1 },
353   
354     { rightname=>'Dialup configuration' },
355     { rightname=>'Dialup global configuration', global=>1 },
356
357     { rightname=>'Broadband configuration' },
358     { rightname=>'Broadband global configuration', global=>1 },
359     
360     { rightname=> 'Configure network monitoring', global=>1 },
361
362     #{ rightname=>'Edit employees', global=>1, },
363     #{ rightname=>'Edit employee groupss', global=>1, },
364
365     { rightname=>'Configuration', global=>1 }, #most of the rest of the configuraiton is not agent-virtualized
366
367     { rightname=>'Configuration download', }, #description of how it affects
368                                               #search/elements/search.html
369
370   ],
371   
372 ;
373   
374 =head1 CLASS METHODS
375   
376 =over 4
377   
378 =item rights
379
380 Returns the full list of right names.
381
382 =cut
383   
384 sub rights {
385   #my $class = shift;
386   map { ref($_) ? $_->{'rightname'} : $_ } map @{ $rights{$_} }, keys %rights;
387 }
388
389 =item default_superuser_rights
390
391 Most (but not all) right names.
392
393 =cut
394
395 sub default_superuser_rights {
396   my $class = shift;
397   my %omit = map { $_=>1 } (
398     'Delete customer',
399     'Delete invoices',
400     'Delete payment',
401     'Delete credit', #?
402     'Delete refund', #?
403     'Edit customer package dates',
404     'Time queue',
405     'Usage: Time worked',
406     'Redownload resolved batches',
407     'Raw SQL',
408     'Configuration download',
409     'View customers of all agents',
410     'View/link unlinked services',
411     'Edit usage',
412     'Credit card void',
413     'Echeck void',
414     'Edit customer package dates',
415   );
416
417   no warnings 'uninitialized';
418   grep { ! $omit{$_} } $class->rights;
419 }
420   
421 =item rights_info
422
423 Returns a list of key-value pairs suitable for assigning to a hash.  Keys are
424 category names and values are list references of rights.  Each element of the
425 list reference scalar right name or a hashref with the following keys:
426
427 =over 4
428
429 =item rightname - Right name
430
431 =item desc - Extended right description
432
433 =item global - Global flag, indicates that this access right provides access to global data which is shared among all agents.
434
435 =back
436
437 =cut
438
439 sub rights_info {
440   %rights;
441 }
442
443 =back
444
445 =head1 BUGS
446
447 Damn those infernal six-legged creatures!
448
449 =head1 SEE ALSO
450
451 L<FS::access_right>, L<FS::access_group>, L<FS::access_user>
452
453 =cut
454
455 1;
456