import rt 3.4.6
[freeside.git] / rt / lib / RT / System.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2005 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
47 =head1 NAME 
48
49 RT::System
50
51 =head1 DESCRIPTION
52
53 RT::System is a simple global object used as a focal point for things
54 that are system-wide.
55
56 It works sort of like an RT::Record, except it's really a single object that has
57 an id of "1" when instantiated.
58
59 This gets used by the ACL system so that you can have rights for the scope "RT::System"
60
61 In the future, there will probably be other API goodness encapsulated here.
62
63 =cut
64
65
66 package RT::System;
67 use base qw /RT::Base/;
68 use strict;
69
70 use RT::ACL;
71 use vars qw/ $RIGHTS/;
72
73 # System rights are rights granted to the whole system
74 # XXX TODO Can't localize these outside of having an object around.
75 $RIGHTS = {
76     SuperUser              => 'Do anything and everything',           # loc_pair
77     AdminAllPersonalGroups =>
78       "Create, delete and modify the members of any user's personal groups"
79     ,                                                                 # loc_pair
80     AdminOwnPersonalGroups =>
81       'Create, delete and modify the members of personal groups',     # loc_pair
82     AdminUsers     => 'Create, delete and modify users',              # loc_pair
83     ModifySelf     => "Modify one's own RT account",                  # loc_pair
84     DelegateRights =>
85       "Delegate specific rights which have been granted to you.",     # loc_pair
86     ShowConfigTab => "show Configuration tab",     # loc_pair
87     LoadSavedSearch => "allow loading of saved searches",     # loc_pair
88     CreateSavedSearch => "allow creation of saved searches",      # loc_pair
89 };
90
91 # Tell RT::ACE that this sort of object can get acls granted
92 $RT::ACE::OBJECT_TYPES{'RT::System'} = 1;
93
94 foreach my $right ( keys %{$RIGHTS} ) {
95     $RT::ACE::LOWERCASERIGHTNAMES{ lc $right } = $right;
96 }
97
98
99 =head2 AvailableRights
100
101 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
102
103 =begin testing
104
105 my $s = RT::System->new($RT::SystemUser);
106 my $rights = $s->AvailableRights;
107 ok ($rights, "Rights defined");
108 ok ($rights->{'AdminUsers'},"AdminUsers right found");
109 ok ($rights->{'CreateTicket'},"CreateTicket right found");
110 ok ($rights->{'AdminGroupMembership'},"ModifyGroupMembers right found");
111 ok (!$rights->{'CasdasdsreateTicket'},"bogus right not found");
112
113
114
115 =end testing
116
117
118 =cut
119
120 sub AvailableRights {
121     my $self = shift;
122
123     my $queue = RT::Queue->new($RT::SystemUser);
124     my $group = RT::Group->new($RT::SystemUser);
125     my $cf    = RT::CustomField->new($RT::SystemUser);
126
127     my $qr =$queue->AvailableRights();
128     my $gr = $group->AvailableRights();
129     my $cr = $cf->AvailableRights();
130
131     # Build a merged list of all system wide rights, queue rights and group rights.
132     my %rights = (%{$RIGHTS}, %{$gr}, %{$qr}, %{$cr});
133     return(\%rights);
134 }
135
136
137 =head2 new
138
139 Create a new RT::System object. Really, you should be using $RT::System
140
141 =cut
142
143                          
144 sub new {
145     my $proto = shift;
146     my $class = ref($proto) || $proto;
147     my $self  = {};
148     bless( $self, $class );
149
150
151     return ($self);
152 }
153
154 =head2 id
155
156 Returns RT::System's id. It's 1. 
157
158
159 =begin testing
160
161 use RT::System;
162 my $sys = RT::System->new();
163 is( $sys->Id, 1);
164 is ($sys->id, 1);
165
166 =end testing
167
168
169 =cut
170
171 *Id = \&id;
172
173 sub id {
174     return (1);
175 }
176
177 =head2 Load
178
179 Since this object is pretending to be an RT::Record, we need a load method.
180 It does nothing
181
182 =cut
183
184 sub Load {
185         return (1);
186 }
187
188 eval "require RT::System_Vendor";
189 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Vendor.pm});
190 eval "require RT::System_Local";
191 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Local.pm});
192
193 1;