import rt 3.6.6
[freeside.git] / rt / lib / RT / System.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/copyleft/gpl.html.
28
29
30 # CONTRIBUTION SUBMISSION POLICY:
31
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
37
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
46
47 # END BPS TAGGED BLOCK }}}
48 =head1 NAME 
49
50 RT::System
51
52 =head1 DESCRIPTION
53
54 RT::System is a simple global object used as a focal point for things
55 that are system-wide.
56
57 It works sort of like an RT::Record, except it's really a single object that has
58 an id of "1" when instantiated.
59
60 This gets used by the ACL system so that you can have rights for the scope "RT::System"
61
62 In the future, there will probably be other API goodness encapsulated here.
63
64 =cut
65
66
67 package RT::System;
68 use base qw /RT::Record/;
69 use strict;
70
71 use RT::ACL;
72 use vars qw/ $RIGHTS/;
73
74 # System rights are rights granted to the whole system
75 # XXX TODO Can't localize these outside of having an object around.
76 $RIGHTS = {
77     SuperUser              => 'Do anything and everything',           # loc_pair
78     AdminAllPersonalGroups =>
79       "Create, delete and modify the members of any user's personal groups"
80     ,                                                                 # loc_pair
81     AdminOwnPersonalGroups =>
82       'Create, delete and modify the members of personal groups',     # loc_pair
83     AdminUsers     => 'Create, delete and modify users',              # loc_pair
84     ModifySelf     => "Modify one's own RT account",                  # loc_pair
85     DelegateRights =>
86       "Delegate specific rights which have been granted to you.",     # loc_pair
87     ShowConfigTab => "show Configuration tab",     # loc_pair
88     LoadSavedSearch => "allow loading of saved searches",     # loc_pair
89     CreateSavedSearch => "allow creation of saved searches",      # loc_pair
90 };
91
92 # Tell RT::ACE that this sort of object can get acls granted
93 $RT::ACE::OBJECT_TYPES{'RT::System'} = 1;
94
95 foreach my $right ( keys %{$RIGHTS} ) {
96     $RT::ACE::LOWERCASERIGHTNAMES{ lc $right } = $right;
97 }
98
99
100 =head2 AvailableRights
101
102 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
103
104 =begin testing
105
106 my $s = RT::System->new($RT::SystemUser);
107 my $rights = $s->AvailableRights;
108 ok ($rights, "Rights defined");
109 ok ($rights->{'AdminUsers'},"AdminUsers right found");
110 ok ($rights->{'CreateTicket'},"CreateTicket right found");
111 ok ($rights->{'AdminGroupMembership'},"ModifyGroupMembers right found");
112 ok (!$rights->{'CasdasdsreateTicket'},"bogus right not found");
113
114
115
116 =end testing
117
118
119 =cut
120
121 sub AvailableRights {
122     my $self = shift;
123
124     my $queue = RT::Queue->new($RT::SystemUser);
125     my $group = RT::Group->new($RT::SystemUser);
126     my $cf    = RT::CustomField->new($RT::SystemUser);
127
128     my $qr =$queue->AvailableRights();
129     my $gr = $group->AvailableRights();
130     my $cr = $cf->AvailableRights();
131
132     # Build a merged list of all system wide rights, queue rights and group rights.
133     my %rights = (%{$RIGHTS}, %{$gr}, %{$qr}, %{$cr});
134     return(\%rights);
135 }
136
137 sub _Init {
138     my $self = shift;
139     $self->SUPER::_Init (@_) if @_ && $_[0];
140 }
141
142 =head2 id
143
144 Returns RT::System's id. It's 1. 
145
146
147 =begin testing
148
149 use RT::System;
150 my $sys = RT::System->new();
151 is( $sys->Id, 1);
152 is ($sys->id, 1);
153
154 =end testing
155
156
157 =cut
158
159 *Id = \&id;
160
161 sub id {
162     return (1);
163 }
164
165 =head2 Load
166
167 Since this object is pretending to be an RT::Record, we need a load method.
168 It does nothing
169
170 =cut
171
172 sub Load {
173         return (1);
174 }
175
176 sub Name {
177     return 'RT System';
178 }
179
180 sub __Set { 0 }
181 sub __Value { 0 }
182 sub Create { 0 }
183 sub Delete { 0 }
184
185 eval "require RT::System_Vendor";
186 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Vendor.pm});
187 eval "require RT::System_Local";
188 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Local.pm});
189
190 1;