import of rt 3.0.9
[freeside.git] / rt / lib / RT / System.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
10 # from www.gnu.org.
11
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
21
22
23 # END LICENSE BLOCK
24 =head1 NAME 
25
26 RT::System
27
28 =head1 DESCRIPTION
29
30 RT::System is a simple global object used as a focal point for things
31 that are system-wide.
32
33 It works sort of like an RT::Record, except it's really a single object that has
34 an id of "1" when instantiated.
35
36 This gets used by the ACL system so that you can have rights for the scope "RT::System"
37
38 In the future, there will probably be other API goodness encapsulated here.
39
40 =cut
41
42
43 package RT::System;
44 use base qw /RT::Base/;
45 use strict;
46
47 use RT::ACL;
48 use vars qw/ $RIGHTS/;
49
50 # System rights are rights granted to the whole system
51 # XXX TODO Can't localize these outside of having an object around.
52 $RIGHTS = {
53     SuperUser              => 'Do anything and everything',           # loc_pair
54     AdminAllPersonalGroups =>
55       "Create, delete and modify the members of any user's personal groups"
56     ,                                                                 # loc_pair
57     AdminOwnPersonalGroups =>
58       'Create, delete and modify the members of personal groups',     # loc_pair
59     AdminUsers     => 'Create, delete and modify users',              # loc_pair
60     ModifySelf     => "Modify one's own RT account",                  # loc_pair
61     DelegateRights =>
62       "Delegate specific rights which have been granted to you."      # loc_pair
63 };
64
65 # Tell RT::ACE that this sort of object can get acls granted
66 $RT::ACE::OBJECT_TYPES{'RT::System'} = 1;
67
68 foreach my $right ( keys %{$RIGHTS} ) {
69     $RT::ACE::LOWERCASERIGHTNAMES{ lc $right } = $right;
70 }
71
72
73 =head2 AvailableRights
74
75 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
76
77 =begin testing
78
79 my $s = RT::System->new($RT::SystemUser);
80 my $rights = $s->AvailableRights;
81 ok ($rights, "Rights defined");
82 ok ($rights->{'AdminUsers'},"AdminUsers right found");
83 ok ($rights->{'CreateTicket'},"CreateTicket right found");
84 ok ($rights->{'AdminGroupMembership'},"ModifyGroupMembers right found");
85 ok (!$rights->{'CasdasdsreateTicket'},"bogus right not found");
86
87
88
89 =end testing
90
91
92 =cut
93
94 sub AvailableRights {
95     my $self = shift;
96
97     my $queue = RT::Queue->new($RT::SystemUser);
98     my $group = RT::Group->new($RT::SystemUser);
99
100     my $qr =$queue->AvailableRights();
101     my $gr = $group->AvailableRights();
102
103     # Build a merged list of all system wide rights, queue rights and group rights.
104     my %rights = (%{$RIGHTS}, %{$gr}, %{$qr});
105     return(\%rights);
106 }
107
108
109 =head2 new
110
111 Create a new RT::System object. Really, you should be using $RT::System
112
113 =cut
114
115                          
116 sub new {
117     my $proto = shift;
118     my $class = ref($proto) || $proto;
119     my $self  = {};
120     bless( $self, $class );
121
122
123     return ($self);
124 }
125
126 =head2 id
127
128 Returns RT::System's id. It's 1. 
129
130
131 =begin testing
132
133 use RT::System;
134 my $sys = RT::System->new();
135 is( $sys->Id, 1);
136 is ($sys->id, 1);
137
138 =end testing
139
140
141 =cut
142
143 *Id = \&id;
144
145 sub id {
146     return (1);
147 }
148
149 =head2 Load
150
151 Since this object is pretending to be an RT::Record, we need a load method.
152 It does nothing
153
154 =cut
155
156 sub Load {
157         return (1);
158 }
159
160 eval "require RT::System_Vendor";
161 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Vendor.pm});
162 eval "require RT::System_Local";
163 die $@ if ($@ && $@ !~ qr{^Can't locate RT/System_Local.pm});
164
165 1;