当前位置: 首页>>代码示例>>PHP>>正文


PHP Account::addPermissions方法代码示例

本文整理汇总了PHP中Account::addPermissions方法的典型用法代码示例。如果您正苦于以下问题:PHP Account::addPermissions方法的具体用法?PHP Account::addPermissions怎么用?PHP Account::addPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Account的用法示例。


在下文中一共展示了Account::addPermissions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testABitOfEverythingAsAnExample


//.........这里部分代码省略.........
     $this->assertTrue($adminDudes->save());
     $salesDudes = new Group();
     $salesDudes->name = 'Sales Dudes';
     $salesDudes->users->add($salesDude1);
     $salesDudes->users->add($salesDude2);
     $this->assertTrue($salesDudes->save());
     $managementDudes = new Group();
     $managementDudes->name = 'Management Dudes';
     $managementDudes->users->add($managementDudette);
     $this->assertTrue($managementDudes->save());
     $everyone = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $everyone->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB);
     $everyone->setPolicy('UsersModule', UsersModule::POLICY_PASSWORD_EXPIRES, 1);
     $everyone->setPolicy('UsersModule', UsersModule::POLICY_PASSWORD_EXPIRY_DAYS, 30);
     $this->assertTrue($everyone->save());
     Yii::app()->user->userModel = $accountOwner;
     $account = new Account();
     $account->name = 'Doozy Co.';
     $this->assertTrue($account->save());
     // The account has no explicit permissions set at this point.
     // The account owner has full permissions implicitly.
     $this->assertEquals(Permission::ALL, $account->getEffectivePermissions($accountOwner));
     // Nobody else has permissions.
     $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));
     // Everyone is given read permissions to the account.
     $everyone = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $account->addPermissions($everyone, Permission::READ);
     $account->save();
     // In one step everyone has read permissions, except the owner who still has full.
     $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, $account->getEffectivePermissions($salesDude1));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($salesDude2));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($managementDudette));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($salesDudes));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($managementDudes));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($supportDude));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($everyone));
     // Sales Dudes is given write permissions to the account.
     $account->addPermissions($salesDudes, Permission::WRITE);
     $account->save();
     // The Sales Dudes group and everyone in it has write.
     $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, $account->getEffectivePermissions($managementDudette));
     $this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDudes));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($managementDudes));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($supportDude));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($everyone));
     // Management Dudes is given change owner permissions to the account.
     $account->addPermissions($managementDudes, Permission::CHANGE_OWNER);
     $account->save();
     // The Managment Dudes group and everyone in it has change owner.
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDude));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDudes));
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:67,代码来源:SecurityDocumentationTest.php

示例2: testMakeBySecurableItem

 public function testMakeBySecurableItem()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $group2 = Group::getByName('Group2');
     $group3 = Group::getByName('Group3');
     $account = new Account();
     $account->name = 'aTestAccount';
     $account->owner = Yii::app()->user->userModel;
     $this->assertTrue($account->save());
     $account->addPermissions($group2, Permission::READ_WRITE);
     $account->addPermissions($group3, Permission::READ);
     $this->assertTrue($account->save());
     $accountId = $account->id;
     $account->forget();
     unset($account);
     $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Account::getById($accountId));
     $this->assertTrue($explicitReadWriteModelPermissions instanceof ExplicitReadWriteModelPermissions);
     $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
     $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables();
     $this->assertEquals(1, count($readWritePermitables));
     $this->assertEquals(1, count($readOnlyPermitables));
     $this->assertEquals($group3, $readOnlyPermitables[$group3->id]);
     $this->assertEquals($group2, $readWritePermitables[$group2->id]);
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:24,代码来源:ExplicitReadWriteModelPermissionsUtilTest.php

示例3: testUserAddedToGroup_Slide22

 /**
  * @depends testUserAddedToGroup_Slide21
  */
 public function testUserAddedToGroup_Slide22()
 {
     $u2 = User::getByUsername('u2.');
     $u99 = User::getByUsername('u99.');
     Yii::app()->user->userModel = $u99;
     $g1 = Group::getByName('G1.');
     $g2 = Group::getByName('G2.');
     $g3 = Group::getByName('G3.');
     $g3->groups->add($g2);
     $this->assertTrue($g3->save());
     $g2->groups->add($g1);
     $this->assertTrue($g2->save());
     Yii::app()->user->userModel = $u99;
     $a3 = new Account();
     $a3->name = 'A3.';
     $a3->addPermissions($g1, Permission::READ);
     $this->assertTrue($a3->save());
     //Called in OwnedSecurableItem::afterSave();
     //ReadPermissionsOptimizationUtil::ownedSecurableItemCreated($a3);
     $a2 = new Account();
     $a2->name = 'A2.';
     $a2->addPermissions($g2, Permission::READ);
     $this->assertTrue($a2->save());
     //Called in OwnedSecurableItem::afterSave();
     //ReadPermissionsOptimizationUtil::ownedSecurableItemCreated($a2);
     $a1 = new Account();
     $a1->name = 'A1.';
     $a1->addPermissions($g3, Permission::READ);
     $this->assertTrue($a1->save());
     //Called in OwnedSecurableItem::afterSave();
     //ReadPermissionsOptimizationUtil::ownedSecurableItemCreated($a1);
     ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($a3, $g1);
     ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($a2, $g2);
     ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($a1, $g3);
     //Utilize method that is used by user interface to handle removing users from a group.
     $form = new GroupUserMembershipForm();
     $fakePostData = array('userMembershipData' => array(0 => $u2->id), 'userNonMembershipData' => array());
     $form = GroupUserMembershipFormUtil::setFormFromCastedPost($form, $fakePostData);
     $saved = GroupUserMembershipFormUtil::setMembershipFromForm($form, $g1);
     //This is completed above in GroupUserMembershipFormUtil::setMembershipFromForm
     //$g1->users->add($u2);
     //$this->assertTrue($g1->save());
     //ReadPermissionsOptimizationUtil::userAddedToGroup($g1, $u2);
     $this->assertEquals(array(array('A1', 'G1', 1), array('A1', 'G2', 1), array('A1', 'G3', 1), array('A1', 'R5', 1), array('A1', 'R6', 1), array('A2', 'G1', 1), array('A2', 'G2', 1), array('A2', 'R5', 1), array('A2', 'R6', 1), array('A3', 'G1', 1), array('A3', 'R5', 1), array('A3', 'R6', 1)), self::getAccountMungeRows());
     $this->assertTrue(self::accountMungeDoesntChangeWhenRebuilt());
     //Utilize method that is used by user interface to handle removing users from a group.
     $form = new GroupUserMembershipForm();
     $fakePostData = array('userMembershipData' => array(), 'userNonMembershipData' => array());
     $form = GroupUserMembershipFormUtil::setFormFromCastedPost($form, $fakePostData);
     $saved = GroupUserMembershipFormUtil::setMembershipFromForm($form, $g1);
     //This is completed above in GroupUserMembershipFormUtil::setMembershipFromForm
     //$g1->users->remove($u2);
     //$this->assertTrue($g1->save());
     //ReadPermissionsOptimizationUtil::userRemovedFromGroup($g1, $u2);
     $this->assertEquals(array(array('A1', 'G1', 1), array('A1', 'G2', 1), array('A1', 'G3', 1), array('A2', 'G1', 1), array('A2', 'G2', 1), array('A3', 'G1', 1)), self::getAccountMungeRows());
     $this->assertTrue(self::accountMungeDoesntChangeWhenRebuilt());
     $a1->delete();
     $a2->delete();
     $a3->delete();
     $g1->group = null;
     $this->assertTrue($g1->save());
     $g2->group = null;
     $this->assertTrue($g2->save());
     $g3->group = null;
     $this->assertTrue($g3->save());
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:69,代码来源:AccountReadPermissionsOptimizationScenariosTest.php

示例4: testUnmarkModelAsStarredForAllUsers

 /**
  * @depends testCreateStarredTables
  */
 public function testUnmarkModelAsStarredForAllUsers()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $steven = UserTestHelper::createBasicUser('Steven');
     $account = new Account();
     $account->owner = $super;
     $account->name = 'Test Account';
     $account->officePhone = '1234567890';
     $account->addPermissions($steven, Permission::READ);
     $this->assertTrue($account->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($account, $steven);
     StarredUtil::markModelAsStarred($account);
     Yii::app()->user->userModel = $steven;
     StarredUtil::markModelAsStarred($account);
     $starredRecords = AccountStarred::getCountByUserIdAndModelId(null, $account->id);
     $this->assertEquals(2, $starredRecords);
     StarredUtil::unmarkModelAsStarredForAllUsers($account);
     $starredRecords = AccountStarred::getCountByUserIdAndModelId(null, $account->id);
     $this->assertEquals(0, $starredRecords);
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:24,代码来源:StarredUtilTest.php

示例5: testDeleteSecurableItemDeletesItsPermissions

 public function testDeleteSecurableItemDeletesItsPermissions()
 {
     $user = User::getByUsername('billy');
     $account = new Account();
     $account->name = 'Waxamatronic';
     $account->addPermissions($user, Permission::READ);
     $this->assertTrue($account->save());
     $this->assertEquals(1, count($account->permissions));
     $this->assertEquals(Permission::READ, $account->getEffectivePermissions($user));
     $account->delete();
     unset($account);
     $userId = $user->id;
     unset($user);
     RedBeanModel::forgetAll();
     $this->assertEquals(0, count(Permission::getAll()));
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:16,代码来源:PermissionsTest.php


注:本文中的Account::addPermissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。