Ejemplo n.º 1
0
 /**
  * Test method Mage_Webapi_Model_Acl_Rule::saveResources()
  */
 public function testSaveResources()
 {
     $role = $this->_roleFactory->create()->load('test_role', 'role_name');
     $resources = array('customer/create', 'customer/update');
     $this->_model->setRoleId($role->getId())->setResources($resources)->saveResources();
     /** @var $rulesSet Mage_Webapi_Model_Resource_Acl_Rule_Collection */
     $rulesSet = $this->_objectManager->get('Mage_Webapi_Model_Resource_Acl_Rule_Collection')->getByRole($role->getRoleId())->load();
     $this->assertCount(2, $rulesSet);
 }
Ejemplo n.º 2
0
 /**
  * Save resources.
  *
  * @param Mage_Webapi_Model_Acl_Rule $rule
  * @throws Exception
  */
 public function saveResources(Mage_Webapi_Model_Acl_Rule $rule)
 {
     $roleId = $rule->getRoleId();
     if ($roleId > 0) {
         $adapter = $this->_getWriteAdapter();
         $adapter->beginTransaction();
         try {
             $adapter->delete($this->getMainTable(), array('role_id = ?' => (int) $roleId));
             $resources = $rule->getResources();
             if ($resources) {
                 $resourcesToInsert = array();
                 foreach ($resources as $resName) {
                     $resourcesToInsert[] = array('role_id' => $roleId, 'resource_id' => trim($resName));
                 }
                 $adapter->insertArray($this->getMainTable(), array('role_id', 'resource_id'), $resourcesToInsert);
             }
             $adapter->commit();
         } catch (Exception $e) {
             $adapter->rollBack();
             throw $e;
         }
     }
 }