1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 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 =head2 ACLEquivalenceObjects
217 Rights on the topic are inherited from the object it is a topic on.
221 sub ACLEquivalenceObjects {
223 return unless $self->id and $self->ObjectId;
225 return $self->Object;
231 my $Object = $self->__Value('ObjectType')->new( $self->CurrentUser );
232 $Object->Load( $self->__Value('ObjectId') );
238 Returns the current value of id.
239 (In the database, id is stored as int(11).)
247 Returns the current value of Parent.
248 (In the database, Parent is stored as int(11).)
252 =head2 SetParent VALUE
256 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
257 (In the database, Parent will be stored as a int(11).)
265 Returns the current value of Name.
266 (In the database, Name is stored as varchar(255).)
274 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
275 (In the database, Name will be stored as a varchar(255).)
283 Returns the current value of Description.
284 (In the database, Description is stored as varchar(255).)
288 =head2 SetDescription VALUE
291 Set Description to VALUE.
292 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
293 (In the database, Description will be stored as a varchar(255).)
301 Returns the current value of ObjectType.
302 (In the database, ObjectType is stored as varchar(64).)
306 =head2 SetObjectType VALUE
309 Set ObjectType to VALUE.
310 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
311 (In the database, ObjectType will be stored as a varchar(64).)
319 Returns the current value of ObjectId.
320 (In the database, ObjectId is stored as int(11).)
324 =head2 SetObjectId VALUE
327 Set ObjectId to VALUE.
328 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
329 (In the database, ObjectId will be stored as a int(11).)
336 sub _CoreAccessible {
340 {read => 1, type => 'int(11)', default => ''},
342 {read => 1, write => 1, type => 'int(11)', default => ''},
344 {read => 1, write => 1, type => 'varchar(255)', default => ''},
346 {read => 1, write => 1, type => 'varchar(255)', default => ''},
348 {read => 1, write => 1, type => 'varchar(64)', default => ''},
350 {read => 1, write => 1, type => 'int(11)', default => '0'},
355 sub FindDependencies {
357 my ($walker, $deps) = @_;
359 $self->SUPER::FindDependencies($walker, $deps);
360 $deps->Add( out => $self->ParentObj ) if $self->ParentObj->Id;
361 $deps->Add( in => $self->Children );
362 $deps->Add( out => $self->Object );
365 RT::Base->_ImportOverlays();