BUGFIX: Let CMS users open pages deleted from draft; bug introduced by translatable.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@75611 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-04-29 02:45:19 +00:00
parent 7e64e2e7e8
commit d33c2869a7
3 changed files with 54 additions and 17 deletions

View File

@ -377,6 +377,12 @@ JS;
$record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id");
if($record) Versioned::reading_stage(null);
}
// Don't open a page from a different locale
if($record && Translatable::is_enabled() && $record->Locale && $record->Locale != Translatable::current_locale()) {
$record = null;
}
return $record;
} else if(substr($id,0,3) == 'new') {

View File

@ -451,7 +451,7 @@ class LeftAndMain extends Controller {
public function getRecord($id, $className = null) {
if(!$className) $className = $this->stat('tree_class');
return DataObject::get_by_id($className, $rootID);
return DataObject::get_by_id($className, $id);
}
function getSiteTreeFor($className, $rootID = null) {
@ -844,12 +844,7 @@ JS;
}
public function EditForm() {
if(isset($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) {
$record = DataObject::get_by_id($this->stat('tree_class'), $_REQUEST['ID']);
} else {
$record = $this->CurrentPage();
}
$record = $this->currentPage();
if(!$record) return false;
if($record && !$record->canView()) return Security::permissionFailure($this);
@ -899,15 +894,7 @@ JS;
}
public function currentPage() {
$id = $this->currentPageID();
if($id && is_numeric($id)) {
$page = DataObject::get_by_id($this->stat('tree_class'), $id);
if($page && Translatable::is_enabled() && $page->Locale && $page->Locale != Translatable::current_locale()) {
return false;
} else {
return $page;
}
}
return $this->getRecord($this->currentPageID());
}
public function isCurrentPage(DataObject $page) {

View File

@ -1,6 +1,6 @@
<?php
class CMSMainTest extends SapphireTest {
class CMSMainTest extends FunctionalTest {
static $fixture_file = 'cms/tests/CMSMainTest.yml';
/**
@ -82,4 +82,48 @@ class CMSMainTest extends SapphireTest {
$this->assertTrue($page->getCMSFields(null) instanceof FieldSet);
}
}
/**
* Test that a draft-deleted page can still be opened in the CMS
*/
function testDraftDeletedPageCanBeOpenedInCMS() {
// Set up a page that is delete from live
$page = $this->objFromFixture('Page','page1');
$pageID = $page->ID;
$page->doPublish();
$page->delete();
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
$response = $this->get('admin/getitem?ID=' . $pageID . '&ajax=1');
// Check that the 'delete from live' button exists as a simple way of checking that the correct page is returned.
$this->assertRegExp('/<input[^>]+type="submit"[^>]+name="action_deletefromlive"/i', $response->getBody());
}
/**
* Test CMSMain::getRecord()
*/
function testGetRecord() {
// Set up a page that is delete from live
$page1 = $this->objFromFixture('Page','page1');
$page1ID = $page1->ID;
$page1->doPublish();
$page1->delete();
$cmsMain = new CMSMain();
// Bad calls
$this->assertNull($cmsMain->getRecord('0'));
$this->assertNull($cmsMain->getRecord('asdf'));
// Pages that are on draft and aren't on draft should both work
$this->assertType('Page', $cmsMain->getRecord($page1ID));
$this->assertType('Page', $cmsMain->getRecord($this->idFromFixture('Page','page2')));
// This functionality isn't actually used any more.
$newPage = $cmsMain->getRecord('new-Page-5');
$this->assertType('Page', $newPage);
$this->assertEquals('5', $newPage->ParentID);
}
}