Centralized isLive checks

This commit is contained in:
Ingo Schommer 2012-12-19 14:30:18 +01:00
parent db290a1cf9
commit 4e75488dd3

View File

@ -12,7 +12,10 @@ class TestSessionController extends Controller {
public function init() { public function init() {
parent::init(); parent::init();
$canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN")); $canAccess = (
!Director::isLive()
&& (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"))
);
if(!$canAccess) return Security::permissionFailure($this); if(!$canAccess) return Security::permissionFailure($this);
} }
@ -29,7 +32,6 @@ class TestSessionController extends Controller {
* as an encrypted cookie. * as an encrypted cookie.
*/ */
public function start() { public function start() {
if(!Director::isLive()) {
if(SapphireTest::using_temp_db()) { if(SapphireTest::using_temp_db()) {
$endLink = Director::baseURL() . "dev/testsession/end"; $endLink = Director::baseURL() . "dev/testsession/end";
return "<p><a id=\"end-session\" href=\"$endLink\">You're in the middle of a test session;" return "<p><a id=\"end-session\" href=\"$endLink\">You're in the middle of a test session;"
@ -91,10 +93,6 @@ HTML;
End your test session</a></li> End your test session</a></li>
</ul>"; </ul>";
} }
} else {
return "<p>startession can only be used on dev and test sites</p>";
}
} }
/** /**
@ -115,9 +113,6 @@ HTML;
* as an encrypted cookie. * as an encrypted cookie.
*/ */
public function setdb() { public function setdb() {
if(Director::isLive()) {
return $this->httpError(403, "dev/testsession/setdb can only be used on dev and test sites");
}
if(!isset($_GET['database'])) { if(!isset($_GET['database'])) {
return $this->httpError(400, "dev/testsession/setdb must be used with a 'database' parameter"); return $this->httpError(400, "dev/testsession/setdb must be used with a 'database' parameter");
} }
@ -162,6 +157,7 @@ HTML;
public function end() { public function end() {
SapphireTest::kill_temp_db(); SapphireTest::kill_temp_db();
DB::set_alternative_database_name(null); DB::set_alternative_database_name(null);
Session::clear('testsession');
return "<p>Test session ended.</p> return "<p>Test session ended.</p>
<ul> <ul>