BUG Prevent archived pages from having add to campaign action

Fixes #1626
This commit is contained in:
Damian Mooyman 2016-10-26 16:25:35 +13:00
parent 062c8205c1
commit 4bf4fca416
2 changed files with 16 additions and 6 deletions

View File

@ -2215,6 +2215,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$isPublished = $this->isPublished(); $isPublished = $this->isPublished();
$stagesDiffer = $this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE); $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. // Major actions appear as buttons immediately visible as page actions.
$majorActions = CompositeField::create()->setName('MajorActions'); $majorActions = CompositeField::create()->setName('MajorActions');
$majorActions->setFieldHolderTemplate(get_class($majorActions) . '_holder_buttongroup'); $majorActions->setFieldHolderTemplate(get_class($majorActions) . '_holder_buttongroup');
@ -2239,7 +2244,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
))->renderWith($infoTemplate) ))->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 // "readonly"/viewing version that isn't the current version of the record
$stageRecord = Versioned::get_by_stage(static::class, Versioned::DRAFT)->byID($this->ID); $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; return $actions;
} }
// Check permissions
$canPublish = $this->canPublish();
$canUnpublish = $this->canUnpublish();
$canEdit = $this->canEdit();
// "unpublish" // "unpublish"
if($isPublished && $canPublish && $isOnDraft && $canUnpublish) { if($isPublished && $canPublish && $isOnDraft && $canUnpublish) {
$moreOptions->push( $moreOptions->push(

View File

@ -45,6 +45,7 @@ class SiteTreeActionsTest extends FunctionalTest {
$page = Page::get()->byID($page->ID); $page = Page::get()->byID($page->ID);
$actions = $page->getCMSActions(); $actions = $page->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_addtocampaign'));
$this->assertNull($actions->dataFieldByName('action_save')); $this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish')); $this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish')); $this->assertNull($actions->dataFieldByName('action_unpublish'));
@ -105,6 +106,7 @@ class SiteTreeActionsTest extends FunctionalTest {
$actions = $page->getCMSActions(); $actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign'));
$this->assertNotNull($actions->dataFieldByName('action_save')); $this->assertNotNull($actions->dataFieldByName('action_save'));
$this->assertNotNull($actions->dataFieldByName('action_publish')); $this->assertNotNull($actions->dataFieldByName('action_publish'));
$this->assertNotNull($actions->dataFieldByName('action_unpublish')); $this->assertNotNull($actions->dataFieldByName('action_unpublish'));
@ -135,6 +137,8 @@ class SiteTreeActionsTest extends FunctionalTest {
$actions = $page->getCMSActions(); $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_save'));
$this->assertNull($actions->dataFieldByName('action_publish')); $this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish')); $this->assertNull($actions->dataFieldByName('action_unpublish'));
@ -164,6 +168,7 @@ class SiteTreeActionsTest extends FunctionalTest {
$page = Page::get()->byID($page->ID); $page = Page::get()->byID($page->ID);
$actions = $page->getCMSActions(); $actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign'));
$this->assertNotNull($actions->dataFieldByName('action_save')); $this->assertNotNull($actions->dataFieldByName('action_save'));
$this->assertNotNull($actions->dataFieldByName('action_publish')); $this->assertNotNull($actions->dataFieldByName('action_publish'));
$this->assertNotNull($actions->dataFieldByName('action_unpublish')); $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(); $version = DB::query('SELECT "Version" FROM "SiteTree_Versions" WHERE "Content" = \'test page first version\'')->value();
$old = Versioned::get_version('Page', $p->ID, $version); $old = Versioned::get_version('Page', $p->ID, $version);
$actions = $old->getCMSActions(); $actions = $old->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_addtocampaign'));
$this->assertNull($actions->dataFieldByName('action_save')); $this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish')); $this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish')); $this->assertNull($actions->dataFieldByName('action_unpublish'));