mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Security::findAnAdministrator doesn't always find an admin
This commit is contained in:
parent
7b89c17349
commit
2bdfd65e9b
@ -745,11 +745,7 @@ class Security extends Controller {
|
|||||||
$member = null;
|
$member = null;
|
||||||
|
|
||||||
// find a group with ADMIN permission
|
// find a group with ADMIN permission
|
||||||
$adminGroup = DataObject::get('Group')
|
$adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
|
||||||
->where("\"Permission\".\"Code\" = 'ADMIN'")
|
|
||||||
->sort("\"Group\".\"ID\"")
|
|
||||||
->innerJoin("Permission", "\"Group\".\"ID\"=\"Permission\".\"GroupID\"")
|
|
||||||
->First();
|
|
||||||
|
|
||||||
if(is_callable('Subsite::changeSubsite')) {
|
if(is_callable('Subsite::changeSubsite')) {
|
||||||
Subsite::changeSubsite($origSubsite);
|
Subsite::changeSubsite($origSubsite);
|
||||||
@ -761,6 +757,7 @@ class Security extends Controller {
|
|||||||
|
|
||||||
if(!$adminGroup) {
|
if(!$adminGroup) {
|
||||||
singleton('Group')->requireDefaultRecords();
|
singleton('Group')->requireDefaultRecords();
|
||||||
|
$adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$member) {
|
if(!$member) {
|
||||||
@ -772,6 +769,14 @@ class Security extends Controller {
|
|||||||
$member = Member::default_admin();
|
$member = Member::default_admin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$member) {
|
||||||
|
// Failover to a blank admin
|
||||||
|
$member = Member::create();
|
||||||
|
$member->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
|
||||||
|
$member->write();
|
||||||
|
$member->Groups()->add($adminGroup);
|
||||||
|
}
|
||||||
|
|
||||||
return $member;
|
return $member;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,23 @@ class SecurityDefaultAdminTest extends SapphireTest {
|
|||||||
$this->assertNull($admin->Password);
|
$this->assertNull($admin->Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFindAnAdministratorWithoutDefaultAdmin() {
|
||||||
|
// Clear default admin
|
||||||
|
Security::clear_default_admin();
|
||||||
|
|
||||||
|
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
||||||
|
$this->assertEquals(0, $adminMembers->count());
|
||||||
|
|
||||||
|
$admin = Security::findAnAdministrator();
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Member', $admin);
|
||||||
|
$this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
|
||||||
|
|
||||||
|
// User should be blank
|
||||||
|
$this->assertEmpty($admin->Email);
|
||||||
|
$this->assertEmpty($admin->Password);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDefaultAdmin() {
|
public function testDefaultAdmin() {
|
||||||
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
||||||
$this->assertEquals(0, $adminMembers->count());
|
$this->assertEquals(0, $adminMembers->count());
|
||||||
|
Loading…
Reference in New Issue
Block a user