-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: UI to list and remove orphaned ACL resources in backend. (…
…#3647) Co-authored-by: Sven Reichel <github-sr@hotmail.com> Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
- Loading branch information
1 parent
8371adc
commit 1a842ec
Showing
10 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* OpenMage | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available at https://opensource.org/license/osl-3-0-php | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* Adminhtml permissions orphaned resource block | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
*/ | ||
class Mage_Adminhtml_Block_Permissions_OrphanedResource extends Mage_Adminhtml_Block_Widget_Grid_Container | ||
{ | ||
public function __construct() | ||
{ | ||
$this->_controller = 'permissions_orphanedResource'; | ||
$this->_headerText = Mage::helper('adminhtml')->__('Orphaned Role Resources'); | ||
parent::__construct(); | ||
$this->_removeButton('add'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function _toHtml(): string | ||
{ | ||
Mage::dispatchEvent('permissions_orphanedresource_html_before', ['block' => $this]); | ||
return parent::_toHtml(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* OpenMage | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available at https://opensource.org/license/osl-3-0-php | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* Adminhtml permissions orphanedResource grid | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
*/ | ||
class Mage_Adminhtml_Block_Permissions_OrphanedResource_Grid extends Mage_Adminhtml_Block_Widget_Grid | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->setId('permissionsOrphanedResourceGrid'); | ||
$this->setDefaultSort('resource_id'); | ||
$this->setDefaultDir('asc'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareCollection() | ||
{ | ||
/** @var Mage_Admin_Model_Resource_Rules_Collection */ | ||
$collection = Mage::getResourceModel('admin/rules_collection') | ||
->addFieldToFilter('resource_id', ['nin' => Mage::getModel('admin/roles')->getResourcesList2D()]) | ||
->addFieldToSelect('resource_id'); | ||
$collection->getSelect()->group('resource_id'); | ||
|
||
/** | ||
* In order for mass action selection to work properly, we need to overwrite | ||
* the model resource $_idFieldName, from the default 'rule_id' to 'resource_id'. | ||
* @see Mage_Adminhtml_Block_Widget_Grid_Massaction_Abstract::getGridIdsJson() | ||
* @var Mage_Admin_Model_Resource_Rules $resource | ||
*/ | ||
$resource = $collection->getResource(); | ||
$resource->setResourceIdAsIdFieldName(); | ||
|
||
$this->setCollection($collection); | ||
return parent::_prepareCollection(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareColumns() | ||
{ | ||
$this->addColumn('resource_id', [ | ||
'header' => Mage::helper('adminhtml')->__('Orphaned Role Resource'), | ||
'index' => 'resource_id' | ||
]); | ||
|
||
return parent::_prepareColumns(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareMassaction() | ||
{ | ||
$this->setMassactionIdField('resource_id'); | ||
$this->getMassactionBlock()->setFormFieldName('resource_id'); | ||
|
||
$this->getMassactionBlock()->addItem('delete', [ | ||
'label' => Mage::helper('adminhtml')->__('Delete'), | ||
'url' => $this->getUrl('*/*/massDelete'), | ||
'confirm' => Mage::helper('adminhtml')->__('Are you sure you want to do this?') | ||
]); | ||
|
||
return $this; | ||
} | ||
|
||
public function getRowUrl($row): string | ||
{ | ||
return ''; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/code/core/Mage/Adminhtml/controllers/Permissions/OrphanedResourceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* OpenMage | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available at https://opensource.org/license/osl-3-0-php | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
class Mage_Adminhtml_Permissions_OrphanedResourceController extends Mage_Adminhtml_Controller_Action | ||
{ | ||
/** | ||
* ACL resource | ||
* @see Mage_Adminhtml_Controller_Action::_isAllowed() | ||
*/ | ||
public const ADMIN_RESOURCE = 'system/acl/orphaned_resources'; | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
protected function _initAction() | ||
{ | ||
$this->loadLayout() | ||
->_setActiveMenu('system/acl') | ||
->_addBreadcrumb($this->__('System'), $this->__('System')) | ||
->_addBreadcrumb($this->__('Permissions'), $this->__('Permissions')) | ||
->_addBreadcrumb($this->__('Orphaned Resources'), $this->__('Orphaned Role Resources')); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Index action | ||
*/ | ||
public function indexAction() | ||
{ | ||
$this->_title($this->__('System')) | ||
->_title($this->__('Permissions')) | ||
->_title($this->__('Orphaned Role Resources')); | ||
|
||
/** @var Mage_Adminhtml_Block_Permissions_OrphanedResource $block */ | ||
$block = $this->getLayout()->createBlock('adminhtml/permissions_orphanedResource'); | ||
$this->_initAction() | ||
->_addContent($block) | ||
->renderLayout(); | ||
} | ||
|
||
/** | ||
* Mass delete action | ||
*/ | ||
public function massDeleteAction() | ||
{ | ||
$resourceIds = $this->getRequest()->getParam('resource_id'); | ||
try { | ||
$deletedRows = Mage::getResourceSingleton('admin/rules')->deleteOrphanedResources($resourceIds); | ||
$this->_getSession()->addSuccess($this->__('Total of %d record(s) have been deleted.', $deletedRows)); | ||
} catch (Mage_Core_Exception $e) { | ||
$this->_getSession()->addError($e->getMessage()); | ||
} catch (Exception $e) { | ||
$error = Mage::getIsDeveloperMode() | ||
? $e->getMessage() | ||
: $this->__('An error occurred while deleting record(s).'); | ||
$this->_getSession()->addError($error); | ||
Mage::logException($e); | ||
} | ||
|
||
$this->_redirect('*/*/'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function preDispatch() | ||
{ | ||
$this->_setForcedFormKeyActions('massDelete'); | ||
return parent::preDispatch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters