本文整理汇总了PHP中Permission::deleteAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::deleteAll方法的具体用法?PHP Permission::deleteAll怎么用?PHP Permission::deleteAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Permission
的用法示例。
在下文中一共展示了Permission::deleteAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testABitOfEverythingAsAnExample
//.........这里部分代码省略.........
// This takes precedence over the read permission the group was given.
$account->addPermissions($managementDudes, Permission::ALL, Permission::DENY);
$account->save();
// The effect is that Management Dudes lose all permissions
// regardless of what they have been granted.
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDudes));
$this->assertEquals(Permission::ALL, $account->getEffectivePermissions($accountOwner));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude1));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude2));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudette));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($supportDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($everyone));
// We'll give Management Dudes back their permissions.
$account->removePermissions($managementDudes, Permission::ALL, Permission::DENY);
// And give management dudette change permissions.
$account->addPermissions($managementDudette, Permission::CHANGE_PERMISSIONS);
$account->save();
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDudes));
$this->assertEquals(Permission::ALL, $account->getEffectivePermissions($accountOwner));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude1));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude2));
$this->assertEquals(Permission::READ | Permission::CHANGE_PERMISSIONS | Permission::CHANGE_OWNER, $account->getEffectivePermissions($managementDudette));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDudes));
$this->assertEquals(Permission::READ | Permission::CHANGE_OWNER, $account->getEffectivePermissions($managementDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($supportDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($everyone));
// Then we'll just nuke eveyone's permissions. If you use this it is for
// the kind of scenario where an admin wants to re-setup permissions from scratch
// so you'd put a Do You Really Want To Do This???? kind of message.
Permission::deleteAll();
// Removing all permissions is done directly on the database,
// so we need to forget our account and get it back again.
$accountId = $account->id;
$account->forget();
unset($account);
$account = Account::getById($accountId);
// Nobody else has permissions again.
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($adminDude));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($adminDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($salesDude1));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($salesDude2));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudette));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($salesDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($supportDude));
// TODO
// - Permissions on modules.
// - Permissions on types.
// - Permissions on fields.
// All users have the right to login via the web, because the Everyone group was granted that right.
$this->assertEquals(Right::ALLOW, $adminDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $adminDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $salesDude1->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $salesDude2->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $managementDudette->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $salesDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $managementDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $supportDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $everyone->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $adminDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::ALLOW, $adminDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $salesDude1->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
示例2: revokeInternal
/**
* @param string $sourceName
* @param int $sourceId
* @param string $targetName
* @param int $targetId
* @param string $permission
*/
protected function revokeInternal($sourceName, $sourceId, $targetName, $targetId, $permission)
{
Permission::deleteAll(['source_model' => $sourceName, 'source_id' => $sourceId, 'target_model' => $targetId, 'target_id' => $targetId, 'permission' => $permission]);
return !$this->isAllowedExplicit($sourceName, $sourceId, $targetName, $targetId, $permission);
}
示例3: testPermissionsCachingHitsAndMisses2
public function testPermissionsCachingHitsAndMisses2()
{
if (!SECURITY_OPTIMIZED) {
return;
}
// Like the test above by averaging over many loops.
$loops = 100;
$accounts = Account::getAll();
$account = $accounts[0];
$user = User::getByUsername('bobby');
$this->assertNotEquals($account->owner->id, $user->id);
$this->setSomePermissions();
$firstTime = $secondTime = $thirdTime = $fourthTime = 0;
for ($i = 0; $i < $loops; $i++) {
$startTime = microtime(true);
$permissions = $account->getEffectivePermissions($user);
$endTime = microtime(true);
$firstTime += $endTime - $startTime;
$startTime = microtime(true);
$permissions = $account->getEffectivePermissions($user);
$endTime = microtime(true);
$secondTime += $endTime - $startTime;
// The false tells it to not forget the
// db level cached permissions.
PermissionsCache::forgetAll(false);
AllPermissionsOptimizationCache::forgetAll();
$startTime = microtime(true);
$permissions = $account->getEffectivePermissions($user);
$endTime = microtime(true);
$thirdTime += $endTime - $startTime;
// Will forget the db level cached permissions.
PermissionsCache::forgetAll();
AllPermissionsOptimizationCache::forgetAll();
$startTime = microtime(true);
$permissions = $account->getEffectivePermissions($user);
$endTime = microtime(true);
$fourthTime += $endTime - $startTime;
// Will forget the db level cached permissions
// to leave it clean for the next loop.
PermissionsCache::forgetAll();
AllPermissionsOptimizationCache::forgetAll();
}
$firstTime /= $loops;
$secondTime /= $loops;
$thirdTime /= $loops;
$fourthTime /= $loops;
// The first time is at least 10 times faster than
// the second time because it will get it from the
// php cached permissions.
if ($secondTime > 0) {
$this->assertGreaterThan(10, $firstTime / $secondTime);
}
// The first time is at least 2 times faster than
// the third time even though the php level permissions
// cache is cleared (or it's a different request)
// because it will get it from the db cached permissions.
if ($thirdTime > 0) {
$this->assertGreaterThan(2, $firstTime / $thirdTime);
}
// The first time is at least 10 times faster than
// the third time even though the php level permissions
// cache is cleared (or it's a different request)
// because it will get it from the db cached permissions.
$this->assertWithinTolerance($firstTime, $fourthTime, 0.005);
Permission::deleteAll();
}
示例4: testPermissionsPropagationViaRolesWhenChildRoleHaveNoUsers
public function testPermissionsPropagationViaRolesWhenChildRoleHaveNoUsers()
{
$childRole = Role::getByName('Sales Person');
foreach ($childRole->users as $user) {
$childRole->users->remove($user);
$this->assertTrue($childRole->save());
}
$parentRole = Role::getByName('Sales Manager');
$childChildRole = Role::getByName('Junior Sales Person');
$userInParentRole = $parentRole->users[0];
$userInChildChildRole = $childChildRole->users[0];
$this->assertEquals(0, count($childRole->users));
Permission::deleteAll();
$accounts = Account::getAll();
$account = $accounts[0];
$this->assertEquals(Permission::ALL, $account->getEffectivePermissions($account->owner));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($userInParentRole));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($userInChildChildRole));
$account->addPermissions($userInChildChildRole, Permission::READ);
$this->assertTrue($account->save());
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($userInParentRole));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($userInChildChildRole));
}