diff --git a/security/Permission.php b/security/Permission.php index a418b0a40..e2e1603c4 100644 --- a/security/Permission.php +++ b/security/Permission.php @@ -160,7 +160,11 @@ class Permission extends DataObject implements TemplateGlobalProvider { if(!$member) { $memberID = $member = Member::currentUserID(); } else { - $memberID = (is_object($member)) ? $member->ID : $member; + $memberID = (is_object($member)) ? $member->ID : $member; + } + + if (!$memberID) { + return false; } // Turn the code into an array as we may need to add other permsissions to the set we check diff --git a/tests/security/PermissionTest.php b/tests/security/PermissionTest.php index fc659fdb4..30bb43554 100644 --- a/tests/security/PermissionTest.php +++ b/tests/security/PermissionTest.php @@ -124,4 +124,14 @@ class PermissionTest extends SapphireTest { Config::inst()->remove('Permission', 'hidden_permissions'); $this->assertContains('CMS_ACCESS_LeftAndMain', $permissionCheckboxSet->Field()); } + + public function testEmptyMemberFails() { + $member = new Member(); + $this->assertFalse($member->exists()); + + $this->logInWithPermission('ADMIN'); + + $this->assertFalse(Permission::checkMember($member, 'ADMIN')); + $this->assertFalse(Permission::checkMember($member, 'CMS_ACCESS_LeftAndMain')); + } }