Skip to content

Commit

Permalink
BUGFIX #6291 Remove rollback action from CMSMain allowed_actions and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Sean Harvey authored and Sam Minnee committed Feb 2, 2011
1 parent e174276 commit a96e5a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
16 changes: 14 additions & 2 deletions core/model/SiteTree.php
Expand Up @@ -1381,10 +1381,22 @@ function fieldLabels($includerelations = true) {
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);
}
Expand All @@ -1393,7 +1405,7 @@ function getCMSActions() {
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);
}
Expand Down
23 changes: 21 additions & 2 deletions tests/SiteTreeActionsTest.php
Expand Up @@ -109,5 +109,24 @@ function testActionsChangedOnStageRecord() {
$this->assertNotContains('action_revert',$actionsArr);
}
}
}
?>

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);
}

}

0 comments on commit a96e5a7

Please sign in to comment.