From a96e5a7dd555d0b8b606ac111e85803b5fb1acf3 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Mon, 31 Jan 2011 03:06:35 +0000 Subject: [PATCH] BUGFIX #6291 Remove rollback action from CMSMain allowed_actions and rely on form action_rollback instead which is safer (from r115440) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@115919 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/SiteTree.php | 16 ++++++++++++++-- tests/SiteTreeActionsTest.php | 23 +++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 593218dd0..aaed9387d 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -1381,10 +1381,22 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid function getCMSActions() { $actions = new FieldSet(); + // "readonly"/viewing version that isn't the current version of the record + $stageOrLiveRecord = Versioned::get_one_by_stage($this->class, Versioned::current_stage(), sprintf('`SiteTree`.ID = %d', $this->ID)); + if($stageOrLiveRecord && $stageOrLiveRecord->Version != $this->Version) { + $actions->push(new FormAction('email', _t('CMSMain.EMAIL', 'Email'))); + $actions->push(new FormAction('rollback', _t('CMSMain.ROLLBACK', 'Roll back to this version'))); + + // getCMSActions() can be extended with updateCMSActions() on a decorator + $this->extend('updateCMSActions', $actions); + + return $actions; + } + if($this->isPublished() && $this->canPublish() && !$this->IsDeletedFromStage) { // "unpublish" $unpublish = FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete'); - $unpublish->describe(_t('SiteTree.BUTTONUNPUBLISHDESC', "Remove this page from the published site")); + $unpublish->describe(_t('SiteTree.BUTTONUNPUBLISHDESC', 'Remove this page from the published site')); $unpublish->addExtraClass('delete'); $actions->push($unpublish); } @@ -1393,7 +1405,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid if($this->isPublished() && $this->canEdit()) { // "rollback" $rollback = FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'), 'delete'); - $rollback->describe(_t('SiteTree.BUTTONCANCELDRAFTDESC', "Delete your draft and revert to the currently published page")); + $rollback->describe(_t('SiteTree.BUTTONCANCELDRAFTDESC', 'Delete your draft and revert to the currently published page')); $rollback->addExtraClass('delete'); $actions->push($rollback); } diff --git a/tests/SiteTreeActionsTest.php b/tests/SiteTreeActionsTest.php index 38b5bbb51..05cb58e9b 100644 --- a/tests/SiteTreeActionsTest.php +++ b/tests/SiteTreeActionsTest.php @@ -109,5 +109,24 @@ if(class_exists('SiteTreeCMSWorkflow')) { $this->assertNotContains('action_revert',$actionsArr); } } -} -?> \ No newline at end of file + + function testActionsViewingOldVersion() { + $p = new Page(); + $p->Content = 'test page first version'; + $p->write(); + $p->Content = 'new content'; + $p->write(); + + // Looking at the old version, the ability to rollback to that version is available + $version = DB::query('SELECT `Version` FROM `SiteTree_versions` WHERE `Content` = \'test page first version\'')->value(); + $old = Versioned::get_version('Page', $p->ID, $version); + $actions = $old->getCMSActions()->column('Name'); + $this->assertNotContains('action_save', $actions); + $this->assertNotContains('action_publish', $actions); + $this->assertNotContains('action_unpublish', $actions); + $this->assertNotContains('action_delete', $actions); + $this->assertContains('action_email', $actions); + $this->assertContains('action_rollback', $actions); + } + +} \ No newline at end of file