fix TeleAPI import (what kind of crack was Christopher smoking that he couldn't fix...
[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 #      'prepay_credit'    => {},
57 #      'rate'             => {},
58 #      'cust_main_county' => {},
59 #    ],
60 #
61 #    'dialup' => [
62 #      '_desc' => 'Access to dialup configuraiton',
63 #      'svc_acct_pop' => {},
64 #    ],
65 #
66 #    'broadband' => [
67 #      '_desc' => 'Access to broadband configuration',
68 #      'router'     => {},
69 #      'addr_block' => {},
70 #    ],
71 #
72 #    'misc' => [
73 #      'part_referral'      => {},
74 #      'part_virtual_field' => {},
75 #      'msgcat'             => {},
76 #      'inventory_class'    => {},
77 #    ],
78 #
79 #  },
80 #
81 #);
82 #
83 ##turn it into a more hash-like structure, but ordered via IxHash
84
85 #well, this is what we have for now.  getting better.
86 tie my %rights, 'Tie::IxHash',
87
88   ###
89   # contact rights
90   ###
91   'Contact and Prospect rights' => [
92     'New prospect',
93     'View prospect',
94     'Edit prospect',
95     'Edit contact', #!
96     #'New contact',
97     #'View customer contacts',
98     'Generate quotation',
99     'Disable quotation',
100   ],
101   
102   ###
103   # basic customer rights
104   ###
105   'Customer rights' => [
106     'New customer',
107     'View customer',
108     #'View Customer | View tickets',
109     'Edit customer',
110     'Edit customer tags',
111     'Edit referring customer',
112     'Edit customer invoice terms',
113     'View customer history',
114     'Suspend customer',
115     'Unsuspend customer',
116     'Cancel customer',
117     'Complimentary customer', #aka users-allow_comp 
118     'Merge customer',
119     'Merge customer across agents',
120     'Bill customer now', #NEW
121     'Bulk send customer notices', #NEW
122     { rightname=>'View customers of all agents', global=>1 },
123   ],
124   
125   ###
126   # customer package rights
127   ###
128   'Customer package rights' => [
129     'View customer packages', #NEW
130     'Order customer package',
131     'One-time charge',
132     'Modify one-time charge',
133     'Change customer package',
134     'Detach customer package',
135     'Bulk change customer packages',
136     'Edit customer package dates',
137     'Discount customer package', #NEW
138     'Custom discount customer package', #NEW
139     'Customize customer package',
140     'Suspend customer package',
141     'Suspend customer package later',
142     'Unsuspend customer package',
143     'Cancel customer package immediately',
144     'Cancel customer package later',
145     'Un-cancel customer package',
146     'Delay suspension events',
147     'Customize billing during suspension',
148     'Add on-the-fly cancel reason', #NEW
149     'Add on-the-fly suspend reason', #NEW
150     'Edit customer package invoice details', #NEW
151     'Edit customer package comments', #NEW
152     'Qualify service', #NEW
153     'Waive setup fee', #NEW
154     'View appointments', #NEWNEW
155     'Make appointment',
156     'View package definition costs', #NEWNEW
157     'Change package start date',
158     'Change package contract end date',
159     'Unmask customer DL',
160     'Unmask customer SSN',
161   ],
162   
163   ###
164   # customer service rights
165   ###
166   'Customer service rights' => [
167     'View customer services', #NEW
168     'Provision customer service',
169     'Bulk provision customer service',
170     'Bulk move customer services', #NEWNEW
171     'Recharge customer service', #NEW
172     'Unprovision customer service',
173     'Change customer service', #NEWNEW
174     'Edit password',
175     'Edit usage', #NEW
176     'Edit home dir', #NEW
177     'Edit www config', #NEW
178     'Edit domain catchall', #NEW
179     'Edit domain nameservice', #NEW
180     'Manage domain registration',
181   
182     { rightname=>'View/link unlinked services', global=>1 }, #not agent-virtualizable without more work
183   ],
184   
185   ###
186   # customer invoice/financial info rights
187   ###
188   'Customer invoice / financial info rights' => [
189     'View invoices',
190     'Resend invoices', #NEWNEW
191     { rightname=>'Print and mail invoices', desc=>"Print and mail via Freeside's web service", }, ##NEWER than NEWNEWNEW
192     'Void invoices',
193     'Unvoid invoices',
194     'View customer tax exemptions', #yow
195     'Edit customer tax exemptions', #NEWNEW
196     'Add customer tax adjustment', #new, but no need to phase in
197     'View customer batched payments', #NEW
198     'View customer pending payments', #NEW
199     'Edit customer pending payments', #NEW
200     'View customer billing events', #NEW
201     'View legacy typeset statements', #new, but no need to phase in
202   ],
203   
204   ###
205   # customer payment rights
206   ###
207   'Customer payment rights' => [
208     'View payments',
209     { rightname=>'Post payment', desc=>'Make check or cash payments.' },
210     { rightname=>'Backdate payment', desc=>'Enable payments to be posted for days other than today.' },
211     'Post check payment',
212     'Post cash payment',
213     'Post Paypal payment',
214     'Post payment batch',
215     'Apply payment', #NEWNEW
216     { rightname=>'Unapply payment', desc=>'Enable "unapplication" of unclosed payments from specific invoices.' }, #aka. unapplypayments
217     { rightname=>'Process payment', desc=>'Process credit card or e-check payments' },
218     'Process credit card payment',
219     'Process Echeck payment',
220   ],
221   
222   ###
223   # customer credit rights
224   ###
225   'Customer credit and refund rights' => [
226     'Post credit',
227     { rightname=>'Backdate credit', desc=>'Enable credits to be posted for days other than today.' },
228     'Credit line items', #NEWNEWNEW
229     'Apply credit', #NEWNEW
230     'Void credit', #NEWER than things marked NEWNEWNEW
231     'Unvoid credit', #NEWER than things marked NEWNEWNEW
232     { rightname=>'Unapply credit', desc=>'Enable "unapplication" of unclosed credits.' }, #aka unapplycredits
233     'View refunds',
234     { rightname=>'Post refund', desc=>'Enable posting of check and cash refunds.' },
235     'Post check refund',
236     'Post cash refund',
237 #    { rightname=>'Process refund', desc=>'Enable processing of generic credit card/ACH refunds (i.e. not associated with a specific prior payment).' },
238     { rightname=>'Refund payment', desc=>'Enable refund of existing customer credit card or e-check payments.' },
239     'Refund credit card payment',
240     'Refund Echeck payment',
241     'Delete refund', #NEW
242     'Add on-the-fly credit reason', #NEW
243     'Add on-the-fly void reason',
244     'Add on-the-fly refund reason', #NEW
245   ],
246   
247   ###
248   # customer voiding rights..
249   ###
250   'Customer payment void rights' => [
251     { rightname=>'Credit card void', desc=>'Enable local-only voiding of credit card payments in addition to refunds against the payment gateway.' }, #aka. cc-void 
252     { rightname=>'Echeck void', desc=>'Enable local-only voiding of echeck payments in addition to refunds against the payment gateway.' }, #aka. echeck-void
253     'Void payments',
254     { rightname=>'Unvoid payments', desc=>'Enable unvoiding of voided payments' }, #aka. unvoid 
255     
256   
257   ],
258  
259   ###
260   # note/attachment rights...
261   ###
262   'Customer note and attachment rights' => [
263     'Add customer note', #NEW
264     'Edit customer note', #NEW
265     'Delete customer note', #NEWEST
266     'View attachments', #NEW
267     'Browse attachments', #NEW
268     'Download attachment', #NEW
269     'Add attachment', #NEW
270     'Edit attachment', #NEW
271     'Delete attachment', #NEW
272     'View deleted attachments', #NEW
273     'Undelete attachment', #NEW
274     'Purge attachment', #NEW
275   ],
276   
277   ###
278   # report/listing rights...
279   ###
280   'Reporting/listing rights' => [
281     'List prospects',
282     'List contacts',
283     'List customers',
284     'List all customers',
285     'Advanced customer search',
286     'List zip codes', #NEW
287     'List quotations',
288     'List invoices',
289     'List packages',
290     'Summarize packages',
291     'List services',
292     'List service passwords',
293   
294     { rightname=> 'List rating data', desc=>'Usage reports', global=>1 },
295     'Billing event reports',
296     'Receivables report',
297     'Basic payment and refund reports',
298     'Financial reports',
299     { rightname=>'Send reports to customers', global=>1 },
300     { rightname=> 'List inventory', global=>1 },
301     { rightname=>'View email logs', global=>1 },
302     { rightname=>'View system logs' },
303
304     'Download report data',
305     'Customers: Customer churn report',
306     'Services: Accounts',
307     'Services: Accounts: Advanced search',
308     'Services: Domains',
309     'Services: Certificates',
310     'Services: Mail forwards',
311     'Services: Virtual hosting services',
312     'Services: Wireless broadband services',
313     'Services: Wireless broadband services: Advanced search',
314     'Services: DSLs',
315     'Services: Cable subscribers',
316     'Services: Conferencing',
317     'Services: Dish services',
318     'Services: Hardware',
319     'Services: Hardware: Advanced search',
320     'Services: Phone numbers',
321     'Services: Phone numbers: Advanced search',
322     'Services: PBXs',
323     'Services: Ports',
324     'Services: Mailing lists',
325     'Services: Alarm services',
326     'Services: Video',
327     'Services: Circuits',
328     'Services: Fiber',
329     'Services: Fiber: Advanced search',
330     'Services: External services',
331     'Usage: RADIUS sessions',
332     'Usage: Call Detail Records (CDRs)',
333     'Usage: Unrateable CDRs',
334     'Usage: Time worked',
335     #gone in 4.x as a distinct ACL (for now?) { rightname=>'Employees: Commission Report', global=>1 },
336     { rightname=>'Employee Reports', global=>1 },
337
338     #{ rightname => 'List customers of all agents', global=>1 },
339   ],
340   
341   ###
342   # misc rights
343   ###
344   'Miscellaneous rights' => [
345     { rightname=>'Job queue', global=>1 },
346     { rightname=>'Time queue', global=>1 },
347     { rightname=>'Process batches', }, #Process payment batches
348     { rightname=>'Process global batches', global=>1 }, #Process global payment batches
349     { rightname=>'Reprocess batches', global=>1 }, #Reprocess payment batches
350     { rightname=>'Redownload resolved batches', global=>1 }, #Redownload resolved payment batches
351     { rightname=>'Process invoice batches', },
352     { rightname=>'Process global invoice batches', global=>1 },
353     { rightname=>'Import', global=>1 }, #some of these are ag-virt'ed now?  give em their own ACLs
354     { rightname=>'Export', global=>1 },
355     { rightname=> 'Edit rating data', desc=>'Delete CDRs', global=>1 },
356     { rightname=>'Delete fees', },
357   #],
358   #
359   ###
360   # misc misc rights
361   ###
362   #'Database access rights' => [
363     { rightname=>'Raw SQL', global=>1 }, #NEW
364   #]
365
366   #'Employee preference rights' => [
367     { rightname=>'Employee preference telephony integration' },
368   #]
369
370   #'RT preference rights' => [
371     { rightname=>'RT activity notification' },
372   #]
373
374   ],
375   
376   ###
377   # setup/config rights
378   ###
379   'Configuration rights' => [
380     'Edit advertising sources',
381     { rightname=>'Edit global advertising sources', global=>1 },
382
383     'Edit sales people',
384
385     'Edit package definitions',
386     { rightname=>'Edit global package definitions', global=>1 },
387     'Edit package definition costs',
388
389     'Bulk edit package definitions',
390
391     'Edit FCC report configuration',
392     { rightname => 'Edit FCC report configuration for all agents', global=>1 },
393
394     'Edit CDR rates',
395     #{ rightname=>'Edit global CDR rates', global=>1, },
396
397     'Edit fee definitions',
398     { rightname=>'Edit global fee definitions', global=>1 },
399
400     'Edit billing events',
401     { rightname=>'Edit global billing events', global=>1 },
402
403     'View templates',
404     { rightname=>'View global templates', global=>1 },
405     'Edit templates',
406     { rightname=>'Edit global templates', global=>1 },
407
408     'Edit inventory',
409     { rightname=>'Edit global inventory', global=>1 },
410   
411     { rightname=>'Dialup configuration' },
412     { rightname=>'Dialup global configuration', global=>1 },
413
414     { rightname=>'Broadband configuration' },
415     { rightname=>'Broadband global configuration', global=>1 },
416
417     { rightname=>'Alarm configuration' },
418     { rightname=>'Alarm global configuration', global=>1 },
419
420     { rightname=>'Edit hardware classes and types' },
421
422     { rightname=> 'Configure network monitoring', global=>1 },
423
424     #{ rightname=>'Edit employees', global=>1, },
425     #{ rightname=>'Edit employee groupss', global=>1, },
426
427     { rightname=>'Edit custom fields', global=>1 },
428
429     { rightname=>'Configuration', global=>1 }, #most of the rest of the configuraiton is not agent-virtualized
430
431     { rightname=>'Configuration download', }, #description of how it affects
432                                               #search/elements/search.html
433
434   ],
435   
436 ;
437   
438 =head1 CLASS METHODS
439   
440 =over 4
441   
442 =item rights
443
444 Returns the full list of right names.
445
446 =cut
447   
448 sub rights {
449   #my $class = shift;
450   map { ref($_) ? $_->{'rightname'} : $_ } map @{ $rights{$_} }, keys %rights;
451 }
452
453 =item default_superuser_rights
454
455 Most (but not all) right names.
456
457 =cut
458
459 sub default_superuser_rights {
460   my $class = shift;
461   my %omit = map { $_=>1 } (
462     'Delete refund', #?
463     'Edit customer package dates',
464     'Time queue',
465     'Usage: Time worked',
466     'Redownload resolved batches',
467     'Raw SQL',
468     'Configuration download',
469     'View customers of all agents',
470     'View/link unlinked services',
471     'Edit usage',
472     'Credit card void',
473     'Echeck void',
474     'Void invoices',#people are overusing this when credits are more appropriate
475     'Backdate credit',
476     'View legacy typeset statments',
477     'Detach customer package',
478     'Delete fees',
479     'Employee preference telephony integration',
480   );
481
482   no warnings 'uninitialized';
483   grep { ! $omit{$_} } $class->rights;
484 }
485   
486 =item rights_info
487
488 Returns a list of key-value pairs suitable for assigning to a hash.  Keys are
489 category names and values are list references of rights.  Each element of the
490 list reference scalar right name or a hashref with the following keys:
491
492 =over 4
493
494 =item rightname - Right name
495
496 =item desc - Extended right description
497
498 =item global - Global flag, indicates that this access right provides access to global data which is shared among all agents.
499
500 =back
501
502 =cut
503
504 sub rights_info {
505   %rights;
506 }
507
508 =back
509
510 =head1 BUGS
511
512 Damn those infernal six-legged creatures!
513
514 =head1 SEE ALSO
515
516 L<FS::access_right>, L<FS::access_group>, L<FS::access_user>
517
518 =cut
519
520 1;