mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUG Prevent archived pages from having add to campaign action
Fixes #1626
This commit is contained in:
parent
062c8205c1
commit
4bf4fca416
@ -2215,6 +2215,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
$isPublished = $this->isPublished();
|
||||
$stagesDiffer = $this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
// Check permissions
|
||||
$canPublish = $this->canPublish();
|
||||
$canUnpublish = $this->canUnpublish();
|
||||
$canEdit = $this->canEdit();
|
||||
|
||||
// Major actions appear as buttons immediately visible as page actions.
|
||||
$majorActions = CompositeField::create()->setName('MajorActions');
|
||||
$majorActions->setFieldHolderTemplate(get_class($majorActions) . '_holder_buttongroup');
|
||||
@ -2239,7 +2244,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
))->renderWith($infoTemplate)
|
||||
)
|
||||
);
|
||||
$moreOptions->push(AddToCampaignHandler_FormAction::create());
|
||||
|
||||
// Add to campaign option if not-archived and has publish permission
|
||||
if (($isPublished || $isOnDraft) && $canPublish) {
|
||||
$moreOptions->push(AddToCampaignHandler_FormAction::create());
|
||||
}
|
||||
|
||||
// "readonly"/viewing version that isn't the current version of the record
|
||||
$stageRecord = Versioned::get_by_stage(static::class, Versioned::DRAFT)->byID($this->ID);
|
||||
@ -2254,11 +2263,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
return $actions;
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
$canPublish = $this->canPublish();
|
||||
$canUnpublish = $this->canUnpublish();
|
||||
$canEdit = $this->canEdit();
|
||||
|
||||
// "unpublish"
|
||||
if($isPublished && $canPublish && $isOnDraft && $canUnpublish) {
|
||||
$moreOptions->push(
|
||||
|
@ -45,6 +45,7 @@ class SiteTreeActionsTest extends FunctionalTest {
|
||||
$page = Page::get()->byID($page->ID);
|
||||
$actions = $page->getCMSActions();
|
||||
|
||||
$this->assertNull($actions->dataFieldByName('action_addtocampaign'));
|
||||
$this->assertNull($actions->dataFieldByName('action_save'));
|
||||
$this->assertNull($actions->dataFieldByName('action_publish'));
|
||||
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
||||
@ -105,6 +106,7 @@ class SiteTreeActionsTest extends FunctionalTest {
|
||||
|
||||
$actions = $page->getCMSActions();
|
||||
|
||||
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign'));
|
||||
$this->assertNotNull($actions->dataFieldByName('action_save'));
|
||||
$this->assertNotNull($actions->dataFieldByName('action_publish'));
|
||||
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
|
||||
@ -135,6 +137,8 @@ class SiteTreeActionsTest extends FunctionalTest {
|
||||
|
||||
$actions = $page->getCMSActions();
|
||||
|
||||
// Theoretically allow deletions to be staged via add to campaign
|
||||
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign'));
|
||||
$this->assertNull($actions->dataFieldByName('action_save'));
|
||||
$this->assertNull($actions->dataFieldByName('action_publish'));
|
||||
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
||||
@ -164,6 +168,7 @@ class SiteTreeActionsTest extends FunctionalTest {
|
||||
$page = Page::get()->byID($page->ID);
|
||||
|
||||
$actions = $page->getCMSActions();
|
||||
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign'));
|
||||
$this->assertNotNull($actions->dataFieldByName('action_save'));
|
||||
$this->assertNotNull($actions->dataFieldByName('action_publish'));
|
||||
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
|
||||
@ -187,6 +192,7 @@ class SiteTreeActionsTest extends FunctionalTest {
|
||||
$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();
|
||||
$this->assertNull($actions->dataFieldByName('action_addtocampaign'));
|
||||
$this->assertNull($actions->dataFieldByName('action_save'));
|
||||
$this->assertNull($actions->dataFieldByName('action_publish'));
|
||||
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
||||
|
Loading…
Reference in New Issue
Block a user