示例#1
0
 public function testRemovePermissions()
 {
     $integrationId = 22;
     $roleName = UserContextInterface::USER_TYPE_INTEGRATION . $integrationId;
     $this->roleMock->expects($this->once())->method('load')->with($roleName)->will($this->returnSelf());
     $this->integrationAuthorizationService->removePermissions($integrationId);
 }
示例#2
0
 /**
  * Restore general information Form Data from Session and save one in Registry
  *
  * @param \Magento\Authorization\Model\Role $role
  * @return $this
  */
 protected function restoreFormDataFromSession(\Magento\Authorization\Model\Role $role)
 {
     $data = $this->_getSession()->getData(SaveRole::ROLE_EDIT_FORM_DATA_SESSION_KEY, true);
     if (!empty($data['rolename'])) {
         $role->setRoleName($data['rolename']);
     }
     return $this;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
     if (!$pluginInfo) {
         return parent::save();
     } else {
         return $this->___callPlugins('save', func_get_args(), $pluginInfo);
     }
 }
示例#4
0
 /**
  * @magentoDataFixture roleDataFixture
  */
 public function testGetRole()
 {
     $this->_model->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
     $role = $this->_model->getRole();
     $this->assertInstanceOf('Magento\\Authorization\\Model\\Role', $role);
     $this->assertEquals(1, $role->getId());
     $this->_model->setRoleId(self::$_newRole->getId())->save();
     $role = $this->_model->getRole();
     $this->assertEquals(self::$_newRole->getId(), $role->getId());
 }
 public function testGrantAllPermissions()
 {
     $rootResource = 'Magento_All:all';
     $this->rootAclResourceMock->expects($this->any())->method('getId')->will($this->returnValue($rootResource));
     $this->roleMock->expects($this->any())->method('getId')->will($this->returnValue(self::ROLE_ID));
     $this->rulesMock->expects($this->any())->method('setRoleId')->with(self::ROLE_ID)->will($this->returnSelf());
     $this->rulesMock->expects($this->any())->method('setResources')->with([$rootResource])->will($this->returnSelf());
     $this->rulesMock->expects($this->any())->method('saveRel')->will($this->returnSelf());
     $this->integrationAuthorizationService->grantAllPermissions(self::INTEGRATION_ID);
 }
示例#6
0
 /**
  * Get admin role model
  *
  * @return \Magento\Authorization\Model\Role
  */
 public function getRole()
 {
     if (null === $this->_role) {
         $this->_role = $this->_roleFactory->create();
         $roles = $this->getRoles();
         if ($roles && isset($roles[0]) && $roles[0]) {
             $this->_role->load($roles[0]);
         }
     }
     return $this->_role;
 }
示例#7
0
 public function testAfterSave()
 {
     $roleId = 123;
     $methodUserMock = $this->getMockBuilder('\\Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['hasRoleId', 'getRoleId'])->getMock();
     $methodUserMock->expects($this->once())->method('hasRoleId')->willReturn(true);
     $methodUserMock->expects($this->once())->method('getRoleId')->willReturn($roleId);
     $this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->dbAdapterMock);
     $this->roleFactoryMock->expects($this->once())->method('create')->willReturn($this->roleMock);
     $this->roleMock->expects($this->once())->method('load')->willReturn($this->roleMock);
     $this->roleMock->expects($this->atLeastOnce())->method('getId')->willReturn($roleId);
     $this->dbAdapterMock->expects($this->once())->method('describeTable')->willReturn([1, 2, 3]);
     $this->assertInstanceOf('\\Magento\\User\\Model\\ResourceModel\\User', $this->invokeMethod($this->model, '_afterSave', [$methodUserMock]));
 }
示例#8
0
 /**
  * Get role users
  *
  * @param \Magento\Authorization\Model\Role $role
  * @return array
  */
 public function getRoleUsers(\Magento\Authorization\Model\Role $role)
 {
     $connection = $this->getConnection();
     $binds = ['role_id' => $role->getId(), 'role_type' => RoleUser::ROLE_TYPE];
     $select = $connection->select()->from($this->getMainTable(), ['user_id'])->where('parent_id = :role_id')->where('role_type = :role_type')->where('user_id > 0');
     return $connection->fetchCol($select, $binds);
 }
示例#9
0
 public function testGetRoleUsers()
 {
     $this->assertEmpty($this->_model->getRoleUsers());
     $this->_model->load(\Magento\TestFramework\Bootstrap::ADMIN_ROLE_NAME, 'role_name');
     $this->assertNotEmpty($this->_model->getRoleUsers());
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet');
     if (!$pluginInfo) {
         return parent::offsetGet($offset);
     } else {
         return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo);
     }
 }
示例#11
0
文件: User.php 项目: aiesh/magento2
 /**
  * Update role users ACL
  *
  * @param \Magento\Authorization\Model\Role $role
  * @return bool
  */
 public function updateRoleUsersAcl(\Magento\Authorization\Model\Role $role)
 {
     $write = $this->_getWriteAdapter();
     $users = $role->getRoleUsers();
     $rowsCount = 0;
     if (sizeof($users) > 0) {
         $bind = array('reload_acl_flag' => 1);
         $where = array('user_id IN(?)' => $users);
         $rowsCount = $write->update($this->_usersTable, $bind, $where);
     }
     return $rowsCount > 0;
 }
 /**
  * @param \Magento\Authorization\Model\Role $role
  * @param array $data
  * @param \Magento\Backend\Model\View\Result\Redirect $resultRedirect
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function saveDataToSessionAndRedirect($role, $data, $resultRedirect)
 {
     $this->_getSession()->setData(self::ROLE_EDIT_FORM_DATA_SESSION_KEY, ['rolename' => $data['rolename']]);
     $this->_getSession()->setData(self::IN_ROLE_USER_FORM_DATA_SESSION_KEY, $data['in_role_user']);
     $this->_getSession()->setData(self::IN_ROLE_OLD_USER_FORM_DATA_SESSION_KEY, $data['in_role_user_old']);
     if ($data['all']) {
         $this->_getSession()->setData(self::RESOURCE_ALL_FORM_DATA_SESSION_KEY, $data['all']);
     } else {
         $resource = isset($data['resource']) ? $data['resource'] : [];
         $this->_getSession()->setData(self::RESOURCE_FORM_DATA_SESSION_KEY, $resource);
     }
     $arguments = $role->getId() ? ['rid' => $role->getId()] : [];
     return $resultRedirect->setPath('*/*/editrole', $arguments);
 }
 public function testGetAllowedResourcesByUser()
 {
     $this->roleMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $expectedResources = ['Magento_Backend::dashboard', 'Magento_Cms::page'];
     $this->assertEquals($expectedResources, $this->aclRetriever->getAllowedResourcesByUser(UserContextInterface::USER_TYPE_INTEGRATION, 1));
 }
示例#14
0
 /**
  * Associate resources with the specified role. All resources previously assigned to the role will be unassigned.
  *
  * @param \Magento\Authorization\Model\Role $role
  * @param string[] $resources
  * @return void
  * @throws \LogicException
  */
 protected function _associateResourcesWithRole($role, $resources)
 {
     /** @var \Magento\Authorization\Model\Rules $rules */
     $rules = $this->_rulesFactory->create();
     $rules->setRoleId($role->getId())->setResources($resources)->saveRel();
 }
示例#15
0
 /**
  * Update role users ACL
  *
  * @param \Magento\Authorization\Model\Role $role
  * @return bool
  */
 public function updateRoleUsersAcl(\Magento\Authorization\Model\Role $role)
 {
     $connection = $this->getConnection();
     $users = $role->getRoleUsers();
     $rowsCount = 0;
     if (sizeof($users) > 0) {
         $bind = ['reload_acl_flag' => 1];
         $where = ['user_id IN(?)' => $users];
         $rowsCount = $connection->update($this->_usersTable, $bind, $where);
     }
     return $rowsCount > 0;
 }
示例#16
0
文件: Role.php 项目: aiesh/magento2
 /**
  * Get role users
  *
  * @param \Magento\Authorization\Model\Role $role
  * @return array
  */
 public function getRoleUsers(\Magento\Authorization\Model\Role $role)
 {
     $read = $this->_getReadAdapter();
     $binds = array('role_id' => $role->getId(), 'role_type' => RoleUser::ROLE_TYPE);
     $select = $read->select()->from($this->getMainTable(), array('user_id'))->where('parent_id = :role_id')->where('role_type = :role_type')->where('user_id > 0');
     return $read->fetchCol($select, $binds);
 }
示例#17
0
 public function testGetAclRoleId()
 {
     $roleId = 9;
     $this->role->expects($this->exactly(2))->method('getId')->will($this->returnValue($roleId));
     $this->assertEquals($roleId, $this->locator->getAclRoleId());
 }