mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix regression in canViewStage
This commit is contained in:
parent
1eda9151a4
commit
fa0160a874
@ -815,7 +815,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
$oldMode = Versioned::get_reading_mode();
|
||||
Versioned::reading_stage($stage);
|
||||
|
||||
$versionFromStage = DataObject::get($this->class)->byID($this->ID);
|
||||
$versionFromStage = DataObject::get($this->owner->class)->byID($this->owner->ID);
|
||||
|
||||
Versioned::set_reading_mode($oldMode);
|
||||
return $versionFromStage ? $versionFromStage->canView($member) : false;
|
||||
|
@ -800,6 +800,40 @@ class VersionedTest extends SapphireTest {
|
||||
$this->assertTrue($public2->canView());
|
||||
$this->assertTrue($private->canView());
|
||||
}
|
||||
|
||||
|
||||
public function testCanViewStage() {
|
||||
$public = $this->objFromFixture('VersionedTest_PublicStage', 'public1');
|
||||
$private = $this->objFromFixture('VersionedTest_DataObject', 'page1');
|
||||
Session::clear("loggedInAs");
|
||||
Versioned::reading_stage('Stage');
|
||||
|
||||
// Test that all (and only) public pages are viewable in stage mode
|
||||
// Unpublished records are not viewable in live regardless of permissions
|
||||
$this->assertTrue($public->canViewStage('Stage'));
|
||||
$this->assertFalse($private->canViewStage('Stage'));
|
||||
$this->assertFalse($public->canViewStage('Live'));
|
||||
$this->assertFalse($private->canViewStage('Live'));
|
||||
|
||||
// Writing records to live should make both stage and live modes viewable
|
||||
$private->publish("Stage", "Live");
|
||||
$public->publish("Stage", "Live");
|
||||
$this->assertTrue($public->canViewStage('Stage'));
|
||||
$this->assertTrue($private->canViewStage('Stage'));
|
||||
$this->assertTrue($public->canViewStage('Live'));
|
||||
$this->assertTrue($private->canViewStage('Live'));
|
||||
|
||||
// If the draft mode changes, the live mode remains public, although the updated
|
||||
// draft mode is secured for non-public records.
|
||||
$private->Title = 'Secret Title';
|
||||
$private->write();
|
||||
$public->Title = 'Public Title';
|
||||
$public->write();
|
||||
$this->assertTrue($public->canViewStage('Stage'));
|
||||
$this->assertFalse($private->canViewStage('Stage'));
|
||||
$this->assertTrue($public->canViewStage('Live'));
|
||||
$this->assertTrue($private->canViewStage('Live'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user