#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
use warnings;
package RT::Article;
-
use base 'RT::Record';
+use Role::Basic 'with';
+with "RT::Record::Role::Links" => { -excludes => ["AddLink", "_AddLinksOnCreate"] };
+
use RT::Articles;
use RT::ObjectTopics;
use RT::Classes;
# This object takes custom fields
use RT::CustomField;
-RT::CustomField->_ForObjectType( CustomFieldLookupType() => 'Articles' )
- ; #loc
+RT::CustomField->RegisterLookupType( CustomFieldLookupType() => 'Articles' ); #loc
# {{{ Create
=head2 AddLink
-Takes a paramhash of Type and one of Base or Target. Adds that link to this tick
-et.
+Takes a paramhash of Type and one of Base or Target. Adds that link to this article.
-=cut
+Prevents the use of plain numbers to avoid confusing behaviour.
-sub DeleteLink {
- my $self = shift;
- my %args = (
- Target => '',
- Base => '',
- Type => '',
- Silent => undef,
- @_
- );
-
- unless ( $self->CurrentUserHasRight('ModifyArticle') ) {
- return ( 0, $self->loc("Permission Denied") );
- }
-
- $self->_DeleteLink(%args);
-}
+=cut
sub AddLink {
my $self = shift;
return ( 0, $self->loc("Cannot add link to plain number") );
}
- # Check that we're actually getting a valid URI
- my $uri_obj = RT::URI->new( $self->CurrentUser );
- $uri_obj->FromURI( $args{'Target'}||$args{'Base'} );
- unless ( $uri_obj->Resolver && $uri_obj->Scheme ) {
- my $msg = $self->loc( "Couldn't resolve '[_1]' into a Link.", $args{'Target'} );
- $RT::Logger->warning( $msg );
- return( 0, $msg );
- }
-
-
$self->_AddLink(%args);
}
}
}
-=head2 CurrentUserHasRight
-
-Returns true if the current user has the right for this article, for the whole system or for this article's class
-
-=cut
-
-sub CurrentUserHasRight {
- my $self = shift;
- my $right = shift;
-
- return (
- $self->CurrentUser->HasRight(
- Right => $right,
- Object => $self,
- EquivObjects => [ $RT::System, $RT::System, $self->ClassObj ]
- )
- );
-
-}
-
=head2 CurrentUserCanSee
Returns true if the current user can see the article, using ShowArticle
"RT::Class-RT::Article";
}
-# _LookupId is the id of the toplevel type object the customfield is joined to
-# in this case, that's an RT::Class.
-sub _LookupId {
+sub ACLEquivalenceObjects {
my $self = shift;
- return $self->ClassObj->id;
-
+ return $self->ClassObj;
}
+sub ModifyLinkRight { "ModifyArticle" }
+
=head2 LoadByInclude Field Value
Takes the name of a form field from "Include Article"
}
unless ($ok) { # load failed, don't check Class
- return ($ok, $msg);
+ return wantarray ? ($ok, $msg) : $ok;
}
unless ($Queue) { # we haven't requested extra sanity checking
- return ($ok, $msg);
+ return wantarray ? ($ok, $msg) : $ok;
}
# ensure that this article is available for the Queue we're
my $class = $self->ClassObj;
unless ($class->IsApplied(0) || $class->IsApplied($Queue)) {
$self->LoadById(0);
- return (0, $self->loc("The Class of the Article identified by [_1] is not applied to the current Queue",$Value));
+ return wantarray ? (0, $self->loc("The Class of the Article identified by [_1] is not applied to the current Queue",$Value)) : 0;
}
- return ($ok, $msg);
+ return wantarray ? ($ok, $msg) : $ok;
}
=cut
sub ClassObj {
- my $self = shift;
- my $Class = RT::Class->new($self->CurrentUser);
- $Class->Load($self->Class());
- return($Class);
+ my $self = shift;
+ my $Class = RT::Class->new($self->CurrentUser);
+ $Class->Load($self->Class());
+ return($Class);
}
=head2 Parent
{
id =>
- {read => 1, type => 'int(11)', default => ''},
+ {read => 1, type => 'int(11)', default => ''},
Name =>
- {read => 1, write => 1, type => 'varchar(255)', default => ''},
+ {read => 1, write => 1, type => 'varchar(255)', default => ''},
Summary =>
- {read => 1, write => 1, type => 'varchar(255)', default => ''},
+ {read => 1, write => 1, type => 'varchar(255)', default => ''},
SortOrder =>
- {read => 1, write => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, type => 'int(11)', default => '0'},
Class =>
- {read => 1, write => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, type => 'int(11)', default => '0'},
Parent =>
- {read => 1, write => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, type => 'int(11)', default => '0'},
URI =>
- {read => 1, write => 1, type => 'varchar(255)', default => ''},
+ {read => 1, write => 1, type => 'varchar(255)', default => ''},
Creator =>
- {read => 1, auto => 1, type => 'int(11)', default => '0'},
+ {read => 1, auto => 1, type => 'int(11)', default => '0'},
Created =>
- {read => 1, auto => 1, type => 'datetime', default => ''},
+ {read => 1, auto => 1, type => 'datetime', default => ''},
LastUpdatedBy =>
- {read => 1, auto => 1, type => 'int(11)', default => '0'},
+ {read => 1, auto => 1, type => 'int(11)', default => '0'},
LastUpdated =>
- {read => 1, auto => 1, type => 'datetime', default => ''},
+ {read => 1, auto => 1, type => 'datetime', default => ''},
}
};
+sub FindDependencies {
+ my $self = shift;
+ my ($walker, $deps) = @_;
+
+ $self->SUPER::FindDependencies($walker, $deps);
+
+ # Links
+ my $links = RT::Links->new( $self->CurrentUser );
+ $links->Limit(
+ SUBCLAUSE => "either",
+ FIELD => $_,
+ VALUE => $self->URI,
+ ENTRYAGGREGATOR => 'OR'
+ ) for qw/Base Target/;
+ $deps->Add( in => $links );
+
+ $deps->Add( out => $self->ClassObj );
+ $deps->Add( in => $self->Topics );
+}
+
+sub PostInflate {
+ my $self = shift;
+
+ $self->__Set( Field => 'URI', Value => $self->URI );
+}
+
RT::Base->_ImportOverlays();
1;