Skip to content

Commit

Permalink
action logs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Mar 27, 2023
1 parent 554c8c6 commit d2503b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
7 changes: 4 additions & 3 deletions plugins/system/actionlogs/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
Expand All @@ -34,9 +35,9 @@ public function register(Container $container): void
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new ActionLogs(
$dispatcher,
$plugin = new ActionLogs(
$container->get(UserFactoryInterface::class),
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'actionlogs')
);
$plugin->setApplication(Factory::getApplication());
Expand Down
36 changes: 22 additions & 14 deletions plugins/system/actionlogs/src/Extension/ActionLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
namespace Joomla\Plugin\System\ActionLogs\Extension;

use Exception;
use JLoader;
use Joomla\CMS\Cache\Cache;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\User;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Database\ParameterType;
use Joomla\Event\DispatcherInterface;
use RuntimeException;
use stdClass;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -39,6 +40,15 @@ final class ActionLogs extends CMSPlugin
{
use DatabaseAwareTrait;

/**
* The user factory
*
* @var UserFactoryInterface
*
* @since __DEPLOY_VERSION__
*/
private $userFactory;

/**
* Constructor.
*
Expand All @@ -47,9 +57,11 @@ final class ActionLogs extends CMSPlugin
*
* @since 3.9.0
*/
public function __construct(&$subject, $config)
public function __construct(UserFactoryInterface $userFactory, DispatcherInterface $dispatcher,array $config)
{
parent::__construct($subject, $config);
parent::__construct($dispatcher, $config);

$this->userFactory = $userFactory;

// Import actionlog plugin group so that these plugins will be triggered for events
PluginHelper::importPlugin('actionlog');
Expand Down Expand Up @@ -97,10 +109,9 @@ public function onContentPrepareForm(Form $form, $data)
* We only allow users who have Super User permission to change this setting for themselves or for other
* users who have the same Super User permission
*/
$user = $this->getApplication()->getIdentity();

$user = Factory::getUser();

if (!$user->authorise('core.admin')) {
if (!$user || !$user->authorise('core.admin')) {
return true;
}

Expand All @@ -115,11 +126,11 @@ public function onContentPrepareForm(Form $form, $data)
$data = (object) $data;
}

if (empty($data->id) || !User::getInstance($data->id)->authorise('core.admin')) {
if (empty($data->id) || !$this->userFactory->loadUserById($data->id)->authorise('core.admin')) {
return true;
}

Form::addFormPath(__DIR__ . '/forms');
Form::addFormPath(JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name . '/forms');

if ((!PluginHelper::isEnabled('actionlog', 'joomla')) && ($this->getApplication()->isClient('administrator'))) {
$form->loadFile('information', false);
Expand Down Expand Up @@ -156,7 +167,7 @@ public function onContentPrepareData($context, $data)
$data = (object) $data;
}

if (!User::getInstance($data->id)->authorise('core.admin')) {
if (!$this->userFactory->loadUserById($data->id)->authorise('core.admin')) {
return true;
}

Expand Down Expand Up @@ -336,7 +347,7 @@ public function onUserAfterSave($user, $isNew, $success, $msg): void
}

// Clear access rights in case user groups were changed.
$userObject = new User($user['id']);
$userObject = $this->userFactory->loadUserById($user['id']);
$userObject->clearAccessRights();

$authorised = $userObject->authorise('core.admin');
Expand Down Expand Up @@ -473,9 +484,6 @@ public static function renderActionlogsExtensions($extensions)
return Text::_('JNONE');
}

// Load the helper.
JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php');

foreach ($extensions as &$extension) {
// Load extension language files and translate extension name.
ActionlogsHelper::loadTranslationFiles($extension);
Expand Down

0 comments on commit d2503b3

Please sign in to comment.