Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Api2_Adminhtml_Api2_AttributeController
  • Mage_Api2_Adminhtml_Api2_RoleController
  • Mage_Api2_Block_Adminhtml_Attribute
  • Mage_Api2_Block_Adminhtml_Attribute_Buttons
  • Mage_Api2_Block_Adminhtml_Attribute_Edit
  • Mage_Api2_Block_Adminhtml_Attribute_Edit_Form
  • Mage_Api2_Block_Adminhtml_Attribute_Grid
  • Mage_Api2_Block_Adminhtml_Attribute_Tab_Resource
  • Mage_Api2_Block_Adminhtml_Attribute_Tabs
  • Mage_Api2_Block_Adminhtml_Permissions_User_Edit_Tab_Roles
  • Mage_Api2_Block_Adminhtml_Roles
  • Mage_Api2_Block_Adminhtml_Roles_Buttons
  • Mage_Api2_Block_Adminhtml_Roles_Grid
  • Mage_Api2_Block_Adminhtml_Roles_Tab_Info
  • Mage_Api2_Block_Adminhtml_Roles_Tab_Resources
  • Mage_Api2_Block_Adminhtml_Roles_Tab_Users
  • Mage_Api2_Block_Adminhtml_Roles_Tabs
  • Mage_Api2_Helper_Data
  • Mage_Api2_Model_Acl
  • Mage_Api2_Model_Acl_Filter
  • Mage_Api2_Model_Acl_Filter_Attribute
  • Mage_Api2_Model_Acl_Filter_Attribute_Operation
  • Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission
  • Mage_Api2_Model_Acl_Global
  • Mage_Api2_Model_Acl_Global_Role
  • Mage_Api2_Model_Acl_Global_Rule
  • Mage_Api2_Model_Acl_Global_Rule_Permission
  • Mage_Api2_Model_Acl_Global_Rule_Privilege
  • Mage_Api2_Model_Acl_Global_Rule_ResourcePermission
  • Mage_Api2_Model_Acl_Global_Rule_Tree
  • Mage_Api2_Model_Auth
  • Mage_Api2_Model_Auth_Adapter
  • Mage_Api2_Model_Auth_Adapter_Abstract
  • Mage_Api2_Model_Auth_Adapter_Oauth
  • Mage_Api2_Model_Auth_User
  • Mage_Api2_Model_Auth_User_Abstract
  • Mage_Api2_Model_Auth_User_Admin
  • Mage_Api2_Model_Auth_User_Customer
  • Mage_Api2_Model_Auth_User_Guest
  • Mage_Api2_Model_Config
  • Mage_Api2_Model_Dispatcher
  • Mage_Api2_Model_Multicall
  • Mage_Api2_Model_Observer
  • Mage_Api2_Model_Renderer
  • Mage_Api2_Model_Renderer_Json
  • Mage_Api2_Model_Renderer_Query
  • Mage_Api2_Model_Renderer_Xml
  • Mage_Api2_Model_Renderer_Xml_Writer
  • Mage_Api2_Model_Request
  • Mage_Api2_Model_Request_Internal
  • Mage_Api2_Model_Request_Interpreter
  • Mage_Api2_Model_Request_Interpreter_Json
  • Mage_Api2_Model_Request_Interpreter_Query
  • Mage_Api2_Model_Request_Interpreter_Xml
  • Mage_Api2_Model_Resource
  • Mage_Api2_Model_Resource_Acl_Filter_Attribute
  • Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection
  • Mage_Api2_Model_Resource_Acl_Global_Role
  • Mage_Api2_Model_Resource_Acl_Global_Role_Collection
  • Mage_Api2_Model_Resource_Acl_Global_Rule
  • Mage_Api2_Model_Resource_Acl_Global_Rule_Collection
  • Mage_Api2_Model_Resource_Setup
  • Mage_Api2_Model_Resource_Validator
  • Mage_Api2_Model_Resource_Validator_Eav
  • Mage_Api2_Model_Resource_Validator_Fields
  • Mage_Api2_Model_Response
  • Mage_Api2_Model_Route_Abstract
  • Mage_Api2_Model_Route_ApiType
  • Mage_Api2_Model_Route_Rest
  • Mage_Api2_Model_Router
  • Mage_Api2_Model_Server

Interfaces

  • Mage_Api2_Model_Acl_PermissionInterface
  • Mage_Api2_Model_Renderer_Interface
  • Mage_Api2_Model_Request_Interpreter_Interface
  • Mage_Api2_Model_Route_Interface

Exceptions

  • Mage_Api2_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Api2
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * API2 roles controller
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Api2
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Api2_Adminhtml_Api2_RoleController extends Mage_Adminhtml_Controller_Action
 35: {
 36:     /**
 37:      * Show grid
 38:      */
 39:     public function indexAction()
 40:     {
 41:         $this->_title($this->__('System'))
 42:              ->_title($this->__('Web Services'))
 43:              ->_title($this->__('REST Roles'));
 44: 
 45:         $this->loadLayout()->_setActiveMenu('system/services/roles');
 46:         $this->_addBreadcrumb($this->__('Web services'), $this->__('Web services'));
 47:         $this->_addBreadcrumb($this->__('REST Roles'), $this->__('REST Roles'));
 48:         $this->_addBreadcrumb($this->__('Roles'), $this->__('Roles'));
 49: 
 50:         $this->renderLayout();
 51:     }
 52: 
 53:     /**
 54:      * Updating grid by ajax
 55:      */
 56:     public function gridAction()
 57:     {
 58:         $this->loadLayout();
 59:         $this->renderLayout();
 60:     }
 61: 
 62:     /**
 63:      * Updating users grid by ajax
 64:      */
 65:     public function usersGridAction()
 66:     {
 67:         $id = $this->getRequest()->getParam('id', false);
 68: 
 69:         $this->loadLayout();
 70:         /** @var $grid Mage_Api2_Block_Adminhtml_Roles_Tab_Users */
 71:         $grid = $this->getLayout()->getBlock('adminhtml.role.edit.tab.users');
 72:         $grid->setUsers($this->_getUsers($id));
 73: 
 74:         $this->renderLayout();
 75:     }
 76: 
 77:     /**
 78:      * Create new role
 79:      */
 80:     public function newAction()
 81:     {
 82:         $this->_title($this->__('System'))
 83:              ->_title($this->__('Web Services'))
 84:              ->_title($this->__('Rest Roles'));
 85: 
 86:         $this->loadLayout()->_setActiveMenu('system/services/roles');
 87:         $this->_addBreadcrumb($this->__('Web services'), $this->__('Web services'));
 88:         $this->_addBreadcrumb($this->__('REST Roles'), $this->__('REST Roles'));
 89:         $this->_addBreadcrumb($this->__('Roles'), $this->__('Roles'));
 90: 
 91:         $breadCrumb = $this->__('Add New Role');
 92:         $breadCrumbTitle = $this->__('Add New Role');
 93:         $this->_title($this->__('New Role'));
 94: 
 95:         $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle);
 96: 
 97:         $this->renderLayout();
 98:     }
 99: 
100:     /**
101:      * Edit role
102:      */
103:     public function editAction()
104:     {
105:         $id = (int) $this->getRequest()->getParam('id');
106:         /** @var $role Mage_Api2_Model_Acl_Global_Role */
107:         $role = Mage::getModel('api2/acl_global_role')->load($id);
108: 
109:         if (!$role->getId()) {
110:             $this->_getSession()->addError($this->__('Role "%s" not found.', $id));
111:             $this->_redirect('*/*/');
112:             return;
113:         }
114: 
115:         $this->loadLayout()->_setActiveMenu('system/services/roles');
116: 
117:         $this->_title($this->__('System'))
118:              ->_title($this->__('Web Services'))
119:              ->_title($this->__('Rest Roles'));
120: 
121:         $breadCrumb = $this->__('Edit Role');
122:         $breadCrumbTitle = $this->__('Edit Role');
123:         $this->_title($this->__('Edit Role'));
124:         $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle);
125: 
126:         /** @var $tabs Mage_Api2_Block_Adminhtml_Roles_Tabs */
127:         $tabs = $this->getLayout()->getBlock('adminhtml.role.edit.tabs');
128:         $tabs->setRole($role);
129:         /** @var $child Mage_Adminhtml_Block_Template */
130:         foreach ($tabs->getChild() as $child) {
131:             $child->setData('role', $role);
132:         }
133: 
134:         /** @var $buttons Mage_Api2_Block_Adminhtml_Roles_Buttons */
135:         $buttons = $this->getLayout()->getBlock('adminhtml.roles.buttons');
136:         $buttons->setRole($role);
137: 
138:         /** @var $users Mage_Api2_Block_Adminhtml_Roles_Tab_Users */
139:         $users = $this->getLayout()->getBlock('adminhtml.role.edit.tab.users');
140:         $users->setUsers($this->_getUsers($id));
141: 
142:         //$this->getLayout()->getBlock('adminhtml.role.edit.tab.resources')->getResTreeJson();
143:         //exit;
144: 
145:         $this->renderLayout();
146:     }
147: 
148:     /**
149:      * Save role
150:      */
151:     public function saveAction()
152:     {
153:         $request = $this->getRequest();
154: 
155:         $id = $request->getParam('id', false);
156:         /** @var $role Mage_Api2_Model_Acl_Global_Role */
157:         $role = Mage::getModel('api2/acl_global_role')->load($id);
158: 
159:         if (!$role->getId() && $id) {
160:             $this->_getSession()->addError(
161:                 $this->__('Role "%s" no longer exists', $role->getData('role_name')));
162:             $this->_redirect('*/*/');
163:             return;
164:         }
165: 
166:         $roleUsers  = $request->getParam('in_role_users', null);
167:         parse_str($roleUsers, $roleUsers);
168:         $roleUsers = array_keys($roleUsers);
169: 
170:         $oldRoleUsers = $this->getRequest()->getParam('in_role_users_old');
171:         parse_str($oldRoleUsers, $oldRoleUsers);
172:         $oldRoleUsers = array_keys($oldRoleUsers);
173: 
174:         /** @var $session Mage_Adminhtml_Model_Session */
175:         $session = $this->_getSession();
176: 
177:         try {
178:             $role->setRoleName($this->getRequest()->getParam('role_name', false))
179:                     ->save();
180: 
181:             foreach($oldRoleUsers as $oUid) {
182:                 $this->_deleteUserFromRole($oUid, $role->getId());
183:             }
184: 
185:             foreach ($roleUsers as $nRuid) {
186:                 $this->_addUserToRole($nRuid, $role->getId());
187:             }
188: 
189:             /**
190:              * Save rules with resources
191:              */
192:             /** @var $rule Mage_Api2_Model_Acl_Global_Rule */
193:             $rule = Mage::getModel('api2/acl_global_rule');
194:             if ($id) {
195:                 $collection = $rule->getCollection();
196:                 $collection->addFilterByRoleId($role->getId());
197: 
198:                 /** @var $model Mage_Api2_Model_Acl_Global_Rule */
199:                 foreach ($collection as $model) {
200:                     $model->delete();
201:                 }
202:             }
203: 
204:             /** @var $ruleTree Mage_Api2_Model_Acl_Global_Rule_Tree */
205:             $ruleTree = Mage::getSingleton(
206:                 'api2/acl_global_rule_tree',
207:                 array('type' => Mage_Api2_Model_Acl_Global_Rule_Tree::TYPE_PRIVILEGE)
208:             );
209:             $resources = $ruleTree->getPostResources();
210:             $id = $role->getId();
211:             foreach ($resources as $resourceId => $privileges) {
212:                 foreach ($privileges as $privilege => $allow) {
213:                     if (!$allow) {
214:                         continue;
215:                     }
216: 
217:                     $rule->setId(null)
218:                             ->isObjectNew(true);
219: 
220:                     $rule->setRoleId($id)
221:                             ->setResourceId($resourceId)
222:                             ->setPrivilege($privilege)
223:                             ->save();
224:                 }
225:             }
226: 
227:             $session->addSuccess($this->__('The role has been saved.'));
228:         } catch (Mage_Core_Exception $e) {
229:             $session->addError($e->getMessage());
230:         } catch (Exception $e) {
231:             $session->addException($e, $this->__('An error occurred while saving role.'));
232:         }
233: 
234:         $this->_redirect('*/*/edit', array('id'=>$id));
235:     }
236: 
237:     /**
238:      * Delete role
239:      */
240:     public function deleteAction()
241:     {
242:         $id = $this->getRequest()->getParam('id', false);
243: 
244:         try {
245:             /** @var $model Mage_Api2_Model_Acl_Global_Role */
246:             $model = Mage::getModel("api2/acl_global_role");
247:             $model->load($id)->delete();
248:             $this->_getSession()->addSuccess($this->__('Role has been deleted.'));
249:         } catch (Mage_Core_Exception $e) {
250:             $this->_getSession()->addError($e->getMessage());
251:         } catch (Exception $e) {
252:             $this->_getSession()->addException($e, $this->__('An error occurred while deleting the role.'));
253:         }
254: 
255:         $this->_redirect("*/*/");
256:     }
257: 
258:     /**
259:      * Check against ACL
260:      *
261:      * @return bool
262:      */
263:     protected function _isAllowed()
264:     {
265:         /** @var $session Mage_Admin_Model_Session */
266:         $session = Mage::getSingleton('admin/session');
267:         return $session->isAllowed('system/api/roles_rest');
268:     }
269: 
270:     /**
271:      * Get API2 roles ajax grid action
272:      */
273:     public function rolesGridAction()
274:     {
275:         /** @var $model Mage_Admin_Model_User */
276:         $model = Mage::getModel('admin/user');
277:         $model->load($this->getRequest()->getParam('user_id'));
278: 
279:         Mage::register('permissions_user', $model);
280:         $this->getResponse()
281:             ->setBody($this->getLayout()->createBlock('api2/adminhtml_permissions_user_edit_tab_roles')->toHtml());
282:     }
283: 
284:     /**
285:      * Get users possessing the role
286:      *
287:      * @param int $id
288:      * @return array|mixed
289:      */
290:     protected function _getUsers($id)
291:     {
292:         if ( $this->getRequest()->getParam('in_role_users') != "" ) {
293:             return $this->getRequest()->getParam('in_role_users');
294:         }
295: 
296:         /** @var $role Mage_Api2_Model_Acl_Global_Role */
297:         $role = Mage::getModel('api2/acl_global_role');
298:         $role->setId($id);
299: 
300:         /** @var $resource Mage_Api2_Model_Resource_Acl_Global_Role  */
301:         $resource = $role->getResource();
302:         $users = $resource->getRoleUsers($role);
303: 
304:         if (sizeof($users) == 0) {
305:             $users = array();
306:         }
307: 
308:         return $users;
309:     }
310: 
311:     /**
312:      * Take away user role
313:      *
314:      * @param int $adminId
315:      * @param int $roleId
316:      * @return Mage_Api2_Adminhtml_Api2_RoleController
317:      */
318:     protected function _deleteUserFromRole($adminId, $roleId)
319:     {
320:         /** @var $resourceModel Mage_Api2_Model_Resource_Acl_Global_Role */
321:         $resourceModel = Mage::getResourceModel('api2/acl_global_role');
322:         $resourceModel->deleteAdminToRoleRelation($adminId, $roleId);
323:         return $this;
324:     }
325: 
326:     /**
327:      * Give user a role
328:      *
329:      * @param int $adminId
330:      * @param int $roleId
331:      * @return Mage_Api2_Adminhtml_Api2_RoleController
332:      */
333:     protected function _addUserToRole($adminId, $roleId)
334:     {
335:         /** @var $resourceModel Mage_Api2_Model_Resource_Acl_Global_Role */
336:         $resourceModel = Mage::getResourceModel('api2/acl_global_role');
337:         $resourceModel->saveAdminToRoleRelation($adminId, $roleId);
338:         return $this;
339:     }
340: }
341: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0