1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
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
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.
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/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 # END BPS TAGGED BLOCK }}}
53 use base 'RT::Record';
59 =head2 Create PARAMHASH
61 Create takes a hash of values and creates a row in the database:
65 varchar(255) 'Description'.
66 varchar(64) 'ObjectType'.
81 my $obj = $RT::System;
82 if ($args{ObjectId}) {
83 $obj = $args{ObjectType}->new($self->CurrentUser);
84 $obj->Load($args{ObjectId});
85 $obj = $RT::System unless $obj->id;
88 return ( 0, $self->loc("Permission denied"))
89 unless ( $self->CurrentUser->HasRight(
90 Right => "AdminTopics",
92 EquivObjects => [ $RT::System, $obj ],
95 $self->SUPER::Create(@_);
105 Deletes this topic, reparenting all sub-topics to this one's parent.
112 unless ( $self->CurrentUserHasRight('AdminTopics') ) {
113 return ( 0, $self->loc("Permission Denied") );
116 my $kids = RT::Topics->new($self->CurrentUser);
117 $kids->LimitToKids($self->Id);
118 while (my $topic = $kids->Next) {
119 $topic->setParent($self->Parent);
122 $self->SUPER::Delete(@_);
123 return (0, "Topic deleted");
133 Deletes this topic, and all of its descendants.
140 unless ( $self->CurrentUserHasRight('AdminTopics') ) {
141 return ( 0, $self->loc("Permission Denied") );
144 $self->SUPER::Delete(@_);
145 my $kids = RT::Topics->new($self->CurrentUser);
146 $kids->LimitToKids($self->Id);
147 while (my $topic = $kids->Next) {
151 return (0, "Topic tree deleted");
161 Returns the parent Topic of this one.
167 my $id = $self->Parent;
168 my $obj = RT::Topic->new($self->CurrentUser);
179 Returns a Topics object containing this topic's children,
180 sorted by Topic.Name.
186 unless ($self->{'Children'}) {
187 $self->{'Children'} = RT::Topics->new($self->CurrentUser);
188 $self->{'Children'}->Limit('FIELD' => 'Parent',
189 'VALUE' => $self->Id);
190 $self->{'Children'}->OrderBy('FIELD' => 'Name');
192 return $self->{'Children'};
199 Intercept attempts to modify the Topic so we can apply ACLs
206 unless ( $self->CurrentUserHasRight('AdminTopics') ) {
207 return ( 0, $self->loc("Permission Denied") );
209 $self->SUPER::_Set(@_);
215 # {{{ CurrentUserHasRight
217 =head2 CurrentUserHasRight
219 Returns true if the current user has the right for this topic, for the
220 whole system or for whatever object this topic is associated with
224 sub CurrentUserHasRight {
228 my $equiv = [ $RT::System ];
229 if ($self->ObjectId) {
230 my $obj = $self->ObjectType->new($self->CurrentUser);
231 $obj->Load($self->ObjectId);
232 push @{$equiv}, $obj;
235 return ( $self->CurrentUser->HasRight(
238 EquivObjects => $equiv,
241 # If we don't have an ID, we don't even know what object we're
242 # attached to -- so the only thing we can fall back on is the
244 return ( $self->CurrentUser->HasRight(
246 Object => $RT::System,
258 Returns the current value of id.
259 (In the database, id is stored as int(11).)
267 Returns the current value of Parent.
268 (In the database, Parent is stored as int(11).)
272 =head2 SetParent VALUE
276 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
277 (In the database, Parent will be stored as a int(11).)
285 Returns the current value of Name.
286 (In the database, Name is stored as varchar(255).)
294 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
295 (In the database, Name will be stored as a varchar(255).)
303 Returns the current value of Description.
304 (In the database, Description is stored as varchar(255).)
308 =head2 SetDescription VALUE
311 Set Description to VALUE.
312 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
313 (In the database, Description will be stored as a varchar(255).)
321 Returns the current value of ObjectType.
322 (In the database, ObjectType is stored as varchar(64).)
326 =head2 SetObjectType VALUE
329 Set ObjectType to VALUE.
330 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
331 (In the database, ObjectType will be stored as a varchar(64).)
339 Returns the current value of ObjectId.
340 (In the database, ObjectId is stored as int(11).)
344 =head2 SetObjectId VALUE
347 Set ObjectId to VALUE.
348 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
349 (In the database, ObjectId will be stored as a int(11).)
356 sub _CoreAccessible {
360 {read => 1, type => 'int(11)', default => ''},
362 {read => 1, write => 1, type => 'int(11)', default => ''},
364 {read => 1, write => 1, type => 'varchar(255)', default => ''},
366 {read => 1, write => 1, type => 'varchar(255)', default => ''},
368 {read => 1, write => 1, type => 'varchar(64)', default => ''},
370 {read => 1, write => 1, type => 'int(11)', default => '0'},
375 RT::Base->_ImportOverlays();