From 4f632b27fce2807bf44a0686e1536a89432bce83 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 13 Sep 2010 18:47:17 -0700 Subject: [PATCH] Forbid pasting content below a shortcut, to prevent loops on purge and other operations. Fixes bug #11855. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Shortcut.pm | 13 +++++++++++++ lib/WebGUI/AssetClipboard.pm | 2 +- t/Asset/AssetClipboard.t | 37 +++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7dc1bd7af..f88d18483 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #11746: Thingy import CSV only supports one line ending - fixed #11833: Recheck for losing Product Images - fixed #11788: Calendar - Can't enter Midnight - Broke page layout + - fixed #11855: Purging Shortcut from Trash causes loop 7.10.0 - fixed #11812: Checking www_ajaxSave's response in the cart js, urlencoding post parameters diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 12cc3a1df..8ed480268 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -786,6 +786,19 @@ sub notLinked { #------------------------------------------------------------------- +=head2 paste ( ) + +Pasting assets under a Shortcut can cause lots of problems, including infinite loops +for operations like paste, and purge. + +=cut + +sub paste { + return 0; +} + +#------------------------------------------------------------------- + =head2 prepareView ( ) See WebGUI::Asset::prepareView() for details. Extends the base class to call prepareView diff --git a/lib/WebGUI/AssetClipboard.pm b/lib/WebGUI/AssetClipboard.pm index 1597452f7..f11f7413f 100644 --- a/lib/WebGUI/AssetClipboard.pm +++ b/lib/WebGUI/AssetClipboard.pm @@ -214,7 +214,7 @@ sub paste { return 0 unless ($self->state eq "published"); return 0 unless ($pastedAsset->canPaste()); ##Allow pasted assets to have a say about pasting. - # Don't allow a shortcut to create an endless loop + ##Do not paste a shortcut immediately below the original asset return 0 if ($pastedAsset->isa("WebGUI::Asset::Shortcut") && $pastedAsset->shortcutToAssetId eq $self->getId); my $i18n=WebGUI::International->new($session, 'Asset'); $outputSub->(sprintf $i18n->get('pasting %s'), $pastedAsset->getTitle) if defined $outputSub; diff --git a/t/Asset/AssetClipboard.t b/t/Asset/AssetClipboard.t index 38a13538d..d7d9c2b86 100644 --- a/t/Asset/AssetClipboard.t +++ b/t/Asset/AssetClipboard.t @@ -19,7 +19,7 @@ use WebGUI::Asset; use WebGUI::VersionTag; use Test::More; # increment this value for each test you create -plan tests => 27; +plan tests => 29; my $session = WebGUI::Test->session; $session->user({userId => 3}); @@ -155,3 +155,38 @@ for my $i (0..2) { is_tree_of_folders($clip, $i+1, $meth); $clip->purge; } + +#################################################### +# +# paste +# +#################################################### + +my $versionTag2 = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->addToCleanup($versionTag2); + +my $page = $tempspace->addChild({ + className => 'WebGUI::Asset::Wobject::Layout', + title => 'Parent asset', +}); + +my $shortcut = $tempspace->addChild({ + className => 'WebGUI::Asset::Shortcut', + shortcutToAssetId => $page->getId, +}); + +$versionTag2->commit; + +foreach my $asset ($page, $shortcut, ) { + $asset = $asset->cloneFromDb; +} + +$shortcut->cut; + +is $page->paste($shortcut->getId), 0, 'cannot paste a shortcut immediately below the asset it shortcuts'; + +$shortcut->publish; + +$page->cut; + +is $shortcut->paste($page->getId), 0, 'cannot paste below shortcuts';