Update for security namespace

This commit is contained in:
Damian Mooyman 2016-07-20 10:34:52 +12:00
parent f03b0ab6c9
commit ef723bb265
6 changed files with 43 additions and 32 deletions

View File

@ -1,5 +1,7 @@
<?php
use SilverStripe\Security\Member;
Member::add_extension('FrameworkTestRole');
Member::add_extension('FileUploadRole');
SiteTree::add_extension('FrameworkTestSiteTreeExtension');

View File

@ -3,14 +3,16 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Security\Member;
class FrameworkTestRole extends DataExtension
{
private static $has_one = array(
'FavouritePage' => 'SiteTree',
);
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab(
@ -18,10 +20,10 @@ class FrameworkTestRole extends DataExtension
new TreeDropdownField("FavouritePageID", "Favourite page", "SiteTree")
);
}
public function requireDefaultRecords()
{
$hasTestMembers = DataObject::get('Member')->find('Email', 'hayley@test.com');
$hasTestMembers = Member::get()->find('Email', 'hayley@test.com');
if (!$hasTestMembers) {
foreach ($this->data() as $name) {
$member = new Member(array(

View File

@ -1,4 +1,8 @@
<?php
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
/**
* Starts a test session with various configurations set in session.
* These configurations are assumed to be evaluated in mysite/_config.php,
@ -6,27 +10,27 @@
*/
class FrameworktestRegressSessionAdmin extends Controller
{
protected $template = 'BlankPage';
public function init()
{
parent::init();
if (!Permission::check('ADMIN')) {
return Security::permissionFailure($this);
}
}
public function Link($action = null)
{
return Controller::join_links('dev', 'regress', $action);
}
public function Form()
{
$isRunning = (Session::get('db'));
if ($isRunning) {
$actions = new FieldList(
new FormAction('endsession', 'End Session')
@ -36,7 +40,7 @@ class FrameworktestRegressSessionAdmin extends Controller
new FormAction('startsession', 'Start Session')
);
}
$form = new Form(
$this,
'Form',
@ -65,7 +69,7 @@ class FrameworktestRegressSessionAdmin extends Controller
$actions
);
$dbField->setHasEmptyDefault(false);
if ($isRunning) {
foreach ($form->Fields() as $field) {
$form->Fields()->replaceField($field->Name(),
@ -73,7 +77,7 @@ class FrameworktestRegressSessionAdmin extends Controller
);
}
}
return $form;
}
@ -81,15 +85,15 @@ class FrameworktestRegressSessionAdmin extends Controller
{
Session::set('enabletranslatable', (isset($data['enabletranslatable'])) ? $data['enabletranslatable'] : null);
Session::set('db', $data['db']);
return $this->redirect('dev/build/?BackURL=admin');
}
public function endsession()
{
Session::set('enabletranslatable', null);
Session::set('db', null);
return $this->redirectBack();
}
}

View File

@ -2,6 +2,7 @@
use SilverStripe\FrameworkTest\Model\TestPage;
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
use SilverStripe\Security\Member;
class TestFileUploadPage extends TestPage
{
@ -13,7 +14,7 @@ class TestFileUploadPage_Controller extends TestPage_Controller
private static $allowed_actions = array(
'Form'
);
public function Form()
{
$fields = new FieldList(
@ -21,15 +22,15 @@ class TestFileUploadPage_Controller extends TestPage_Controller
new FileField('AFile', 'FileField'),
$aImage = new UploadField('AImage', 'SimpleImageField')
);
$aImage->allowedExtensions = array('jpg', 'gif', 'png');
$actions = new FieldList(
new FormAction('addMember', "Add a member with two Files uploaded")
);
return new Form($this, "Form", $fields, $actions);
}
public function addMember($data, $form)
{
$member = new Member();

View File

@ -1,12 +1,13 @@
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
class Page2MultiForm extends MultiForm
{
public static $start_step = 'Page2PersonalDetailsFormStep';
public function finish($data, $form)
{
parent::finish($data, $form);
@ -44,9 +45,9 @@ class Page2MultiForm extends MultiForm
class Page2PersonalDetailsFormStep extends MultiFormStep
{
public static $next_steps = 'Page2OrganisationDetailsFormStep';
public function getFields()
{
return new FieldList(
@ -58,7 +59,7 @@ class Page2PersonalDetailsFormStep extends MultiFormStep
class Page2OrganisationDetailsFormStep extends MultiFormStep
{
public static $is_final_step = true;
public function getFields()

View File

@ -1,12 +1,13 @@
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
class Page3MultiForm extends MultiForm
{
public static $start_step = 'Page3StartFormStep';
public function finish($data, $form)
{
parent::finish($data, $form);
@ -44,9 +45,9 @@ class Page3MultiForm extends MultiForm
class Page3StartFormStep extends MultiFormStep
{
public static $next_steps = 'Page3PersonalDetailsFormStep';
public function getFields()
{
return new FieldList(
@ -63,9 +64,9 @@ class Page3StartFormStep extends MultiFormStep
class Page3PersonalDetailsFormStep extends MultiFormStep
{
public static $next_steps = 'Page3OrganisationDetailsFormStep';
public function getFields()
{
return new FieldList(
@ -77,7 +78,7 @@ class Page3PersonalDetailsFormStep extends MultiFormStep
class Page3OrganisationDetailsFormStep extends MultiFormStep
{
public static $is_final_step = true;
public function getFields()