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

@ -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;
}
};
#-------------------------------------------------------------------