public function getCMSActions() { // hide delete-draft button if page is published // (deleting from draft while having a published page, // removes the page from the gridfield and makes it un-reachable from the CMS // The Gridfield gets records from draft only (AllChildrenIncludingDeleted breaks // gridfield sorting & filtering) $actions = parent::getCMSActions(); if ($this->isPublished()) { $actions->removeByName('action_delete'); } return $actions; }
/** * To remove the unpublish button from the CMS, as this page must always be published * * @see SiteTree::getCMSActions() * @see AccountPage::canDeleteFromLive() * @return FieldList Actions fieldset with unpublish action removed */ function getCMSActions() { $actions = parent::getCMSActions(); $actions->removeByName('action_unpublish'); return $actions; }
function testActionsChangedOnStageRecord() { if(class_exists('SiteTreeCMSWorkflow')) return true; $author = $this->objFromFixture('Member', 'cmseditor'); $this->session()->inst_set('loggedInAs', $author->ID); $page = new Page(); $page->CanEditType = 'LoggedInUsers'; $page->write(); $page->doPublish(); $page->Content = 'Changed on Stage'; $page->write(); $page->flushCache(); $actions = $page->getCMSActions(); $this->assertNotNull($actions->dataFieldByName('action_save')); $this->assertNotNull($actions->dataFieldByName('action_publish')); $this->assertNotNull($actions->dataFieldByName('action_unpublish')); $this->assertNotNull($actions->dataFieldByName('action_delete')); $this->assertNull($actions->dataFieldByName('action_deletefromlive')); $this->assertNotNull($actions->dataFieldByName('action_rollback')); $this->assertNull($actions->dataFieldByName('action_revert')); }
function testCmsActionsLimited() { // For 2.3 and 2.4 compatibility $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; $custompublisherspage = $this->objFromFixture('SiteTree', 'custompublisherpage'); $custompublishersgroup = $this->objFromFixture('Group', 'custompublishergroup'); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $workflowadmin = $this->objFromFixture('Member', 'workflowadmin'); $custompublisher->Groups()->add($custompublishersgroup); $customauthorsgroup = $this->objFromFixture('Group', 'customauthorsgroup'); $customauthor = $this->objFromFixture('Member', 'customauthor'); $customauthor->Groups()->add($customauthorsgroup); $unpublishedRecord = new Page(); $unpublishedRecord->CanEditType = 'LoggedInUsers'; $unpublishedRecord->write(); $unpublishedRecord->PublisherGroups()->add($custompublishersgroup); $custompublisher->logIn(); $publishedRecord = new Page(); $publishedRecord->CanEditType = 'LoggedInUsers'; $publishedRecord->write(); $publishedRecord->doPublish(); $publishedRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromLiveRecord = new Page(); $deletedFromLiveRecord->CanEditType = 'LoggedInUsers'; $deletedFromLiveRecord->write(); $deletedFromLiveRecord->doPublish(); $deletedFromLiveRecord->deleteFromStage('Live'); $deletedFromLiveRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromStageRecord = new Page(); $deletedFromStageRecord->CanEditType = 'LoggedInUsers'; $deletedFromStageRecord->write(); $deletedFromStageRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromStageRecord->doPublish(); $deletedFromStageRecordID = $deletedFromStageRecord->ID; $deletedFromStageRecord->deleteFromStage('Stage'); $deletedFromStageRecord = Versioned::get_one_by_stage("SiteTree", "Live", "{$bt}SiteTree{$bt}.{$bt}ID{$bt} = {$deletedFromStageRecordID}"); $changedOnStageRecord = new Page(); $changedOnStageRecord->CanEditType = 'LoggedInUsers'; $changedOnStageRecord->write(); $changedOnStageRecord->publish('Stage', 'Live'); $changedOnStageRecord->Content = 'Changed on Stage'; $changedOnStageRecord->write(); $changedOnStageRecord->PublisherGroups()->add($custompublishersgroup); // test "publish" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertNotContains('action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); $this->assertNotContains('action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); $this->assertNotContains('action_publish', $deletedFromLiveRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); $this->assertNotContains('action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); // test "publish" action for publisher $this->session()->inst_set('loggedInAs', $custompublisher->ID); WorkflowRequest::set_force_publishers_to_use_workflow(false); $this->assertContains('action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button'); $this->assertContains('action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button'); $this->assertContains('action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button'); WorkflowRequest::set_force_publishers_to_use_workflow(true); $this->assertFalse(in_array('action_publish', $unpublishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow'); $this->assertFalse(in_array('action_publish', $publishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow'); $this->assertFalse(in_array('action_publish', $changedOnStageRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow'); // test "request publication" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertContains('action_cms_requestpublication', $unpublishedRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page is not published'); $this->assertNotContains('action_cms_requestpublication', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request publication button if page has been published but not altered on stage'); $this->assertContains('action_cms_requestpublication', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page has been changed on stage'); // test "request removal" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertNotContains('action_cms_requestdeletefromlive', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page hasnt been altered'); $this->assertNotContains('action_cms_requestdeletefromlive', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been published but not altered on stage'); $this->assertNotContains('action_cms_requestdeletefromlive', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been changed on stage but not deleted from stage'); // test "request removal" action for publisher $this->session()->inst_set('loggedInAs', $custompublisher->ID); // reset login $this->session()->inst_set('loggedInAs', null); }