Mage_Api_Model_Mysql4_Acl Class Reference

Inheritance diagram for Mage_Api_Model_Mysql4_Acl:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 loadAcl ()
 loadRoles (Mage_Api_Model_Acl $acl, array $rolesArr)
 loadRules (Mage_Api_Model_Acl $acl, array $rulesArr)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 35 of file Acl.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resource connections

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 42 of file Acl.php.

00043     {
00044         $this->_init('api/role', 'role_id');
00045     }

loadAcl (  ) 

Load ACL for the user

Parameters:
integer $userId
Returns:
Mage_Api_Model_Acl

Definition at line 53 of file Acl.php.

00054     {
00055         $acl = Mage::getModel('api/acl');
00056 
00057         Mage::getSingleton('api/config')->loadAclResources($acl);
00058 
00059         $roleTable = Mage::getSingleton('core/resource')->getTableName('api/role');
00060         $rolesArr = $this->_getReadAdapter()->fetchAll(
00061                         $this->_getReadAdapter()->select()
00062                             ->from($this->getTable('role'))
00063                             ->order('tree_level')
00064                     );
00065         $this->loadRoles($acl, $rolesArr);
00066 
00067         $rulesArr =  $this->_getReadAdapter()->fetchAll(
00068                         $this->_getReadAdapter()->select()
00069                             ->from(array('r'=>$this->getTable('rule')))
00070                             ->joinLeft(
00071                                 array('a'=>$this->getTable('assert')),
00072                                 'a.assert_id=r.assert_id',
00073                                 array('assert_type', 'assert_data')
00074                             ));
00075         $this->loadRules($acl, $rulesArr);
00076         return $acl;
00077     }

loadRoles ( Mage_Api_Model_Acl acl,
array rolesArr 
)

Load roles

Parameters:
Mage_Api_Model_Acl $acl
array $rolesArr
Returns:
Mage_Api_Model_Mysql4_Acl

Definition at line 86 of file Acl.php.

00087     {
00088         foreach ($rolesArr as $role) {
00089             $parent = $role['parent_id']>0 ? Mage_Api_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : null;
00090             switch ($role['role_type']) {
00091                 case Mage_Api_Model_Acl::ROLE_TYPE_GROUP:
00092                     $roleId = $role['role_type'].$role['role_id'];
00093                     $acl->addRole(Mage::getModel('api/acl_role_group', $roleId), $parent);
00094                     break;
00095 
00096                 case Mage_Api_Model_Acl::ROLE_TYPE_USER:
00097                     $roleId = $role['role_type'].$role['user_id'];
00098                     if (!$acl->hasRole($roleId)) {
00099                         $acl->addRole(Mage::getModel('api/acl_role_user', $roleId), $parent);
00100                     } else {
00101                         $acl->addRoleParent($roleId, $parent);
00102                     }
00103                     break;
00104             }
00105         }
00106 
00107         return $this;
00108     }

loadRules ( Mage_Api_Model_Acl acl,
array rulesArr 
)

Load rules

Parameters:
Mage_Api_Model_Acl $acl
array $rulesArr
Returns:
Mage_Api_Model_Mysql4_Acl

Definition at line 117 of file Acl.php.

00118     {
00119         foreach ($rulesArr as $rule) {
00120             $role = $rule['role_type'].$rule['role_id'];
00121             $resource = $rule['resource_id'];
00122             $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;
00123 
00124             $assert = null;
00125             if (0!=$rule['assert_id']) {
00126                 $assertClass = Mage::getSingleton('api/config')->getAclAssert($rule['assert_type'])->getClassName();
00127                 $assert = new $assertClass(unserialize($rule['assert_data']));
00128             }
00129             try {
00130                 if ( $rule['permission'] == 'allow' ) {
00131                     $acl->allow($role, $resource, $privileges, $assert);
00132                 } else if ( $rule['permission'] == 'deny' ) {
00133                     $acl->deny($role, $resource, $privileges, $assert);
00134                 }
00135             } catch (Exception $e) {
00136                 //$m = $e->getMessage();
00137                 //if ( eregi("^Resource '(.*)' not found", $m) ) {
00138                     // Deleting non existent resource rule from rules table
00139                     //$cond = $this->_write->quoteInto('resource_id = ?', $resource);
00140                     //$this->_write->delete(Mage::getSingleton('core/resource')->getTableName('admin/rule'), $cond);
00141                 //} else {
00142                     //TODO: We need to log such exceptions to somewhere like a system/errors.log
00143                 //}
00144             }
00145             /*
00146             switch ($rule['permission']) {
00147                 case Mage_Api_Model_Acl::RULE_PERM_ALLOW:
00148                     $acl->allow($role, $resource, $privileges, $assert);
00149                     break;
00150 
00151                 case Mage_Api_Model_Acl::RULE_PERM_DENY:
00152                     $acl->deny($role, $resource, $privileges, $assert);
00153                     break;
00154             }
00155             */
00156         }
00157         return $this;
00158     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:32 2009 for Magento by  doxygen 1.5.8