rework how validParent works, and where it is checked. Add an explicit check for it in addChild, and remove a bunch of overridden addChild methods.

This commit is contained in:
Colin Kuskie 2010-03-19 14:31:49 -07:00
parent a8496c4d15
commit 88ec09d279
12 changed files with 78 additions and 110 deletions

View file

@ -1901,18 +1901,14 @@ sub setRelatedLinks {
#-------------------------------------------------------------------
=head2 validParent
=head2 valid_parent_classes
Make sure that the current session asset is a Calendar for pasting and adding checks.
This is a class method.
=cut
sub validParent {
my $class = shift;
my $session = shift;
return $session->asset->isa('WebGUI::Asset::Wobject::Calendar');
sub valid_parent_classes {
return [qw/WebGUI::Asset::Wobject::Calendar/];
}
####################################################################

View file

@ -708,6 +708,18 @@ sub setComment {
);
}
#-------------------------------------------------------------------
=head2 valid_parent_classes
Restrict valid parents to GalleryAlbums and Shortcuts.
=cut
sub valid_parent_classes {
return [qw/WebGUI::Asset::Wobject::GalleryAlbum WebGUI::Asset::Shortcut/];
}
#----------------------------------------------------------------------------
=head2 view ( )

View file

@ -1348,7 +1348,7 @@ sub prepareView {
#-------------------------------------------------------------------
=head2 validParent
=head2 valid_parent_classes
Make sure that the current session asset is a Thread or Post for pasting and adding checks.
@ -1356,7 +1356,7 @@ This is a class method.
=cut
sub validParent {
sub valid_parent_classes {
my $class = shift;
my $session = shift;
return $session->asset->isa('WebGUI::Asset::Post');

View file

@ -975,7 +975,7 @@ sub updateThreadRating {
#-------------------------------------------------------------------
=head2 validParent
=head2 valid_parent_classes
Make sure that the current session asset is a CS for pasting and adding checks.
@ -983,10 +983,8 @@ This is a class method.
=cut
sub validParent {
my $class = shift;
my $session = shift;
return $session->asset->isa('WebGUI::Asset::Wobject::Collaboration');
sub valid_parent_classes {
return [qw/WebGUI::Asset::Wobject::Collaboration/];
}
#-------------------------------------------------------------------

View file

@ -779,7 +779,7 @@ sub topic {
#-------------------------------------------------------------------
=head2 validParent
=head2 valid_parent_classes
Make sure that the current session asset is a StoryArchive for pasting and adding checks.
@ -787,13 +787,8 @@ This is a class method.
=cut
sub validParent {
my $class = shift;
my $session = shift;
return $session->asset
&& ( $session->asset->isa('WebGUI::Asset::Wobject::StoryArchive')
|| ($session->asset->isa('WebGUI::Asset::Wobject::Folder') && $session->asset->getParent->isa('WebGUI::Asset::Wobject::StoryArchive') )
);
sub valid_parent_classes {
return [qw/WebGUI::Asset::Wobject::StoryArchive WebGUI::Asset::Wobject::Folder/];
}
#-------------------------------------------------------------------

View file

@ -448,7 +448,7 @@ sub scrubContent {
#-------------------------------------------------------------------
=head2 validParent
=head2 valid_parent_classes
Make sure that the current session asset is a WikiMaster for pasting and adding checks.
@ -456,10 +456,8 @@ This is a class method.
=cut
sub validParent {
my $class = shift;
my $session = shift;
return $session->asset->isa('WebGUI::Asset::Wobject::WikiMaster');
sub valid_parent_classes {
return [qw/WebGUI::Asset::Wobject::WikiMaster/];
}
#-------------------------------------------------------------------

View file

@ -302,27 +302,6 @@ use Text::Wrap;
#----------------------------------------------------------------------------
=head2 addChild ( properties [, more ] )
Only allows Events to be added as a child of this asset.
=cut
sub addChild {
my $self = shift;
my $properties = shift;
my @other = @_;
if ($properties->{className} ne "WebGUI::Asset::Event") {
$self->session->errorHandler->security("add a ".$properties->{className}." to a ".$self->get("className"));
return undef;
}
return $self->SUPER::addChild($properties, @other);
}
#----------------------------------------------------------------------------
=head2 addFeed ( $feedParams )
Adds a new Feed to this calendar. This is a wrapper around WebGUI::JSONCollateral's setJSONCollateral

View file

@ -514,26 +514,6 @@ sub _visitorCacheOk {
&& !$self->session->form->process('sortBy'));
}
#-------------------------------------------------------------------
=head2 addChild
Extend the base method to allow only Threads as children.
=cut
sub addChild {
my $self = shift;
my $properties = shift;
my @other = @_;
if ($properties->{className} ne "WebGUI::Asset::Post::Thread") {
$self->session->errorHandler->security("add a ".$properties->{className}." to a ".$self->className);
return undef;
}
return $self->next::method($properties, @other);
}
#-------------------------------------------------------------------
=head2 appendPostListTemplateVars ($var, $p)

View file

@ -130,37 +130,6 @@ sub addArchive {
#----------------------------------------------------------------------------
=head2 addChild ( properties [, ... ] )
Add a child to this GalleryAlbum. See C<WebGUI::AssetLineage> for more info.
Override to ensure only appropriate classes get added to GalleryAlbums.
=cut
sub addChild {
my $self = shift;
my $properties = shift;
my $fileClass = 'WebGUI::Asset::File::GalleryFile';
# Load the class
WebGUI::Pluggable::load( $properties->{className} );
# Make sure we only add appropriate child classes
if ( !$properties->{className}->isa( $fileClass )
&& !$properties->{ className }->isa( "WebGUI::Asset::Shortcut" )
) {
$self->session->errorHandler->security(
"add a ".$properties->{className}." to a ".$self->className
);
return undef;
}
return $self->next::method( $properties, @_ );
}
#----------------------------------------------------------------------------
=head2 appendTemplateVarsFileLoop ( vars, assetIds )
Append template vars for a file loop for the specified assetIds. C<vars> is
@ -764,6 +733,20 @@ sub sendChunkedContent {
return "chunked";
}
#-------------------------------------------------------------------
=head2 valid_parent_classes
Make sure that the current session asset is a Gallery for pasting and adding checks.
This is a class method.
=cut
sub valid_parent_classes {
return [qw/WebGUI::Asset::Wobject::Gallery/];
}
#----------------------------------------------------------------------------
=head2 view ( )

View file

@ -118,19 +118,19 @@ does not exist, then make it.
=cut
sub addChild {
override addChild => sub {
my $self = shift;
my ($properties) = @_;
##Allow subclassing
if ($properties->{className} eq 'WebGUI::Asset::Wobject::Folder') {
return $self->SUPER::addChild(@_);
return super();
}
return undef unless $properties->{className} =~ /^WebGUI::Asset::Story/;
my $todayFolder = $self->getFolder;
return undef unless $todayFolder;
my $story = $todayFolder->addChild(@_);
return $story;
}
};
#-------------------------------------------------------------------