This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / rt / lib / RT / System.pm
1 # {{{ BEGIN BPS TAGGED BLOCK
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
6 #                                          <jesse@bestpractical.com>
7
8 # (Except where explicitly superseded by other copyright notices)
9
10
11 # LICENSE:
12
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
16 # from www.gnu.org.
17
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 # General Public License for more details.
22
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27
28 # CONTRIBUTION SUBMISSION POLICY:
29
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
35
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
44
45 # }}} END BPS TAGGED BLOCK
46 =head1 NAME 
47
48 RT::System
49
50 =head1 DESCRIPTION
51
52 RT::System is a simple global object used as a focal point for things
53 that are system-wide.
54
55 It works sort of like an RT::Record, except it's really a single object that has
56 an id of "1" when instantiated.
57
58 This gets used by the ACL system so that you can have rights for the scope "RT::System"
59
60 In the future, there will probably be other API goodness encapsulated here.
61
62 =cut
63
64
65 package RT::System;
66 use base qw /RT::Base/;
67 use strict;
68
69 use RT::ACL;
70 use vars qw/ $RIGHTS/;
71
72 # System rights are rights granted to the whole system
73 # XXX TODO Can't localize these outside of having an object around.
74 $RIGHTS = {
75     SuperUser              => 'Do anything and everything',           # loc_pair
76     AdminAllPersonalGroups =>
77       "Create, delete and modify the members of any user's personal groups"
78     ,                                                                 # loc_pair
79     AdminOwnPersonalGroups =>
80       'Create, delete and modify the members of personal groups',     # loc_pair
81     AdminUsers     => 'Create, delete and modify users',              # loc_pair
82     ModifySelf     => "Modify one's own RT account",                  # loc_pair
83     DelegateRights =>
84       "Delegate specific rights which have been granted to you."      # loc_pair
85 };
86
87 # Tell RT::ACE that this sort of object can get acls granted
88 $RT::ACE::OBJECT_TYPES{'RT::System'} = 1;
89
90 foreach my $right ( keys %{$RIGHTS} ) {
91     $RT::ACE::LOWERCASERIGHTNAMES{ lc $right } = $right;
92 }
93
94
95 =head2 AvailableRights
96
97 Returns a hash of available rights for this object. The keys are the right names and the values are a description of what the rights do
98
99 =begin testing
100
101 my $s = RT::System->new($RT::SystemUser);
102 my $rights = $s->AvailableRights;
103 ok ($rights, "Rights defined");
104 ok ($rights->{'AdminUsers'},"AdminUsers right found");
105 ok ($rights->{'CreateTicket'},"CreateTicket right found");
106 ok ($rights->{'AdminGroupMembership'},"ModifyGroupMembers right found");
107 ok (!$rights->{'CasdasdsreateTicket'},"bogus right not found");
108
109
110
111 =end testing
112
113
114 =cut
115
116 sub AvailableRights {
117     my $self = shift;
118
119     my $queue = RT::Queue->new($RT::SystemUser);
120     my $group = RT::Group->new($RT::SystemUser);
121
122     my $qr =$queue->AvailableRights();
123     my $gr = $group->AvailableRights();
124
125     # Build a merged list of all system wide rights, queue rights and group rights.
126     my %rights = (%{$RIGHTS}, %{$gr}, %{$qr});
127     return(\%rights);
128 }
129
130
131 =head2 new
132
133 Create a new RT::System object. Really, you should be using $RT::System
134
135 =cut
136
137                          
138 sub new {
139     my $proto = shift;
140     my $class = ref($proto) || $proto;
141     my $self  = {};
142     bless( $self, $class );
143
144
145     return ($self);
146 }
147
148 =head2 id
149
150 Returns RT::System's id. It's 1. 
151
152
153 =begin testing
154
155 use RT::System;
156 my $sys = RT::System->new();
157 is( $sys->Id, 1);
158 is ($sys->id, 1);
159
160 =end testing
161
162
163 =cut
164
165 *Id = \&id;
166
167 sub id {
168     return (1);
169 }
170
171 =head2 Load
172
173 Since this object is pretending to be an RT::Record, we need a load method.
174 It does nothing
175
176 =cut
177
178 sub Load {
179         return (1);
180 }
181
182 eval "require RT::System_Vendor";
183 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Vendor.pm});
184 eval "require RT::System_Local";
185 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Local.pm});
186
187 1;