Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved orphaned resources detection in backend, fixed #4007 #4022

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/code/core/Mage/Admin/Model/Resource/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class Mage_Admin_Model_Resource_Acl extends Mage_Core_Model_Resource_Db_Abstract
{
public const ACL_ALL_RULES = 'all';

protected $_orphanedResources = [];

/**
* Initialize resource
*
Expand Down Expand Up @@ -114,6 +112,7 @@ public function loadRoles(Mage_Admin_Model_Acl $acl, array $rolesArr)
*/
public function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr)
{
$orphanedResources = [];
foreach ($rulesArr as $rule) {
$role = $rule['role_type'] . $rule['role_id'];
$resource = $rule['resource_id'];
Expand All @@ -134,8 +133,8 @@ public function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr)
$acl->deny($role, $resource, $privileges, $assert);
}
} catch (Zend_Acl_Exception $e) {
if (!in_array($resource, $this->_orphanedResources) && strpos($e->getMessage(), "Resource '$resource' not found") !== false) {
$this->_orphanedResources[] = $resource;
if (!in_array($resource, $orphanedResources) && strpos($e->getMessage(), "Resource '$resource' not found") !== false) {
$orphanedResources[] = $resource;
}
} catch (Exception $e) {
if (Mage::getIsDeveloperMode()) {
Expand All @@ -144,11 +143,11 @@ public function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr)
}
}

if ($this->_orphanedResources !== []) {
if ($acl->isAllowed(Mage::getSingleton('admin/session')->getUser()->getAclRole(), 'admin/system/acl/orphaned_resources') && $orphanedResources !== []) {
Mage::getSingleton('adminhtml/session')->addNotice(
Mage::helper('adminhtml')->__(
'The following role resources are no longer available in the system: %s. You can delete them by <a href="%s">clicking here</a>.',
implode(', ', $this->_orphanedResources),
implode(', ', $orphanedResources),
Mage::helper("adminhtml")->getUrl('adminhtml/permissions_orphanedResource')
)
);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function _buildResourcesArray(
$level = -1;
} else {
$resourceName = $parentName;
if (!in_array($resource->getName(), ['title', 'sort_order', 'children', 'disabled'])) {
if (!empty($resource->children()) && $resource->getName() !== 'children') {
$resourceName = (is_null($parentName) ? '' : $parentName . '/') . $resource->getName();

//assigning module for its' children nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public function __construct()
*/
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()])
->addFieldToFilter('resource_id', ['nin' => Mage::getSingleton('admin/session')->getAcl()->getResources()])
->addFieldToSelect('resource_id');
$collection->getSelect()->group('resource_id');

Expand Down
Loading