Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Joomla\Component\Privacy\Administrator\Model;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Privacy\CollectCapabilitiesEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseModel;
Expand Down Expand Up @@ -70,13 +71,18 @@ public function getCapabilities()
* This is in addition to plugin groups which are imported before this method is triggered, generally this is the system group.
*/

PluginHelper::importPlugin('authentication');
PluginHelper::importPlugin('captcha');
PluginHelper::importPlugin('installer');
PluginHelper::importPlugin('privacy');
PluginHelper::importPlugin('user');
$dispatcher = $app->getDispatcher();

$pluginResults = $app->triggerEvent('onPrivacyCollectAdminCapabilities');
PluginHelper::importPlugin('authentication', null, true, $dispatcher);
PluginHelper::importPlugin('captcha', null, true, $dispatcher);
PluginHelper::importPlugin('installer', null, true, $dispatcher);
PluginHelper::importPlugin('privacy', null, true, $dispatcher);
PluginHelper::importPlugin('user', null, true, $dispatcher);

$pluginResults = $dispatcher->dispatch(
'onPrivacyCollectAdminCapabilities',
new CollectCapabilitiesEvent('onPrivacyCollectAdminCapabilities')
)->getArgument('result', []);

// We are going to "cheat" here and include this component's capabilities without using a plugin
$extensionCapabilities = [
Expand Down
10 changes: 8 additions & 2 deletions administrator/components/com_privacy/src/Model/ExportModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Joomla\Component\Privacy\Administrator\Model;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Privacy\ExportRequestEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Language;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -97,9 +98,14 @@ public function collectDataForExportRequest($id = null)
// Log the export
$this->logExport($table);

PluginHelper::importPlugin('privacy');
$dispatcher = $this->getDispatcher();

$pluginResults = Factory::getApplication()->triggerEvent('onPrivacyExportRequest', [$table, $user]);
PluginHelper::importPlugin('privacy', null, true, $dispatcher);

$pluginResults = $dispatcher->dispatch('onPrivacyExportRequest', new ExportRequestEvent('onPrivacyExportRequest', [
'subject' => $table,
'user' => $user,
]))->getArgument('result', []);

$domains = [];

Expand Down
17 changes: 13 additions & 4 deletions administrator/components/com_privacy/src/Model/RemoveModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace Joomla\Component\Privacy\Administrator\Model;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Privacy\CanRemoveDataEvent;
use Joomla\CMS\Event\Privacy\RemoveDataEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
Expand Down Expand Up @@ -89,12 +91,16 @@ public function removeDataForRequest($id = null)

$user = $userId ? $this->getUserFactory()->loadUserById($userId) : null;

$canRemove = true;
$canRemove = true;
$dispatcher = $this->getDispatcher();

PluginHelper::importPlugin('privacy');
PluginHelper::importPlugin('privacy', null, true, $dispatcher);

/** @var Status[] $pluginResults */
$pluginResults = Factory::getApplication()->triggerEvent('onPrivacyCanRemoveData', [$table, $user]);
$pluginResults = $dispatcher->dispatch('onPrivacyCanRemoveData', new CanRemoveDataEvent('onPrivacyCanRemoveData', [
'subject' => $table,
'user' => $user,
]))->getArgument('result', []);

foreach ($pluginResults as $status) {
if (!$status->canRemove) {
Expand All @@ -113,7 +119,10 @@ public function removeDataForRequest($id = null)
// Log the removal
$this->logRemove($table);

Factory::getApplication()->triggerEvent('onPrivacyRemoveData', [$table, $user]);
$dispatcher->dispatch('onPrivacyRemoveData', new RemoveDataEvent('onPrivacyRemoveData', [
'subject' => $table,
'user' => $user,
]));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
namespace Joomla\Module\PrivacyStatus\Administrator\Helper;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Privacy\CheckPrivacyPolicyPublishedEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Proxy\ArrayProxy;
use Joomla\CMS\Router\Route;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -36,7 +38,8 @@ class PrivacyStatusHelper
*/
public static function getPrivacyPolicyInfo()
{
$policy = [
$dispatcher = Factory::getApplication()->getDispatcher();
$policy = [
'published' => false,
'articlePublished' => false,
'editLink' => '',
Expand All @@ -46,10 +49,15 @@ public static function getPrivacyPolicyInfo()
* Prior to 3.9.0 it was common for a plugin such as the User - Profile plugin to define a privacy policy or
* terms of service article, therefore we will also import the user plugin group to process this event.
*/
PluginHelper::importPlugin('privacy');
PluginHelper::importPlugin('user');

Factory::getApplication()->triggerEvent('onPrivacyCheckPrivacyPolicyPublished', [&$policy]);
PluginHelper::importPlugin('privacy', null, true, $dispatcher);
PluginHelper::importPlugin('user', null, true, $dispatcher);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for later, have we a chance to deprecate this? if or if not can you add this to the migration documentation to not use "user" plugins for privacy stuff so we can remove this import here in Joomla 7.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I not sure what a reason for these imports, But I think we can just add deprecation here. It is our module.
And 'user' group should be already imported, while login.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has a description 2 lines above that's it's b/c for < 3.9 ;-)

I'm not sure if we always import user plugins for each page load?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmhm, probably not, I thought it always up with onUserAuthorisation,
but not sure currently


$dispatcher->dispatch(
'onPrivacyCheckPrivacyPolicyPublished',
new CheckPrivacyPolicyPublishedEvent('onPrivacyCheckPrivacyPolicyPublished', [
'subject' => new ArrayProxy($policy),
])
);

return $policy;
}
Expand Down
6 changes: 6 additions & 0 deletions libraries/src/Event/CoreEventAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ trait CoreEventAware
'onBuildIndex' => Finder\BuildIndexEvent::class,
'onStartIndex' => Finder\StartIndexEvent::class,
'onFinderGarbageCollection' => Finder\GarbageCollectionEvent::class,
// Privacy
'onPrivacyCollectAdminCapabilities' => Privacy\CollectCapabilitiesEvent::class,
'onPrivacyCheckPrivacyPolicyPublished' => Privacy\CheckPrivacyPolicyPublishedEvent::class,
'onPrivacyExportRequest' => Privacy\ExportRequestEvent::class,
'onPrivacyCanRemoveData' => Privacy\CanRemoveDataEvent::class,
'onPrivacyRemoveData' => Privacy\RemoveDataEvent::class,
];

/**
Expand Down
135 changes: 135 additions & 0 deletions libraries/src/Event/Privacy/CanRemoveDataEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Privacy;

use Joomla\CMS\Event\Result\ResultAware;
use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\CMS\User\User;
use Joomla\Component\Privacy\Administrator\Removal\Status;
use Joomla\Component\Privacy\Administrator\Table\RequestTable;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Privacy events.
* Example:
* new CanRemoveDataEvent('onEventName', ['subject' => $requestTable, 'user' => $user]);
*
* @since __DEPLOY_VERSION__
*/
class CanRemoveDataEvent extends PrivacyEvent implements ResultAwareInterface
{
use ResultAware;

/**
* The argument names, in order expected by legacy plugins.
*
* @var array
*
* @since __DEPLOY_VERSION__
* @deprecated 5.0 will be removed in 6.0
*/
protected $legacyArgumentsOrder = ['subject', 'user'];

/**
* Constructor.
*
* @param string $name The event name.
* @param array $arguments The event arguments.
*
* @throws \BadMethodCallException
*
* @since __DEPLOY_VERSION__
*/
public function __construct($name, array $arguments = [])
{
parent::__construct($name, $arguments);

if (!\array_key_exists('subject', $this->arguments)) {
throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided");
}

if (!\array_key_exists('user', $this->arguments)) {
throw new \BadMethodCallException("Argument 'user' of event {$name} is required but has not been provided");
}
}

/**
* Setter for the subject argument.
*
* @param RequestTable $value The value to set
*
* @return RequestTable
*
* @since __DEPLOY_VERSION__
*/
protected function setSubject(RequestTable $value): RequestTable
{
return $value;
}

/**
* Setter for the user argument.
*
* @param ?User $value The value to set
*
* @return ?User
*
* @since __DEPLOY_VERSION__
*/
protected function setUser(?User $value): ?User
{
return $value;
}

/**
* Checks the type of the data being appended to the result argument.
*
* @param mixed $data The data to type check
*
* @return void
* @throws \InvalidArgumentException
*
* @internal
* @since __DEPLOY_VERSION__
*/
public function typeCheckResult($data): void
{
if (!$data instanceof Status) {
throw new \InvalidArgumentException(sprintf('Event %s only accepts Joomla\Component\Privacy\Administrator\Removal\Status results.', \get_class($this)));
}
}

/**
* Getter for the request.
*
* @return RequestTable
*
* @since __DEPLOY_VERSION__
*/
public function getRequest(): RequestTable
{
return $this->arguments['subject'];
}

/**
* Getter for the user.
*
* @return ?User
*
* @since __DEPLOY_VERSION__
*/
public function getUser(): ?User
{
return $this->arguments['user'];
}
}
79 changes: 79 additions & 0 deletions libraries/src/Event/Privacy/CheckPrivacyPolicyPublishedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Privacy;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Privacy events.
* Example:
* new CheckPrivacyPolicyPublishedEvent('onEventName', ['subject' => $policyInfo]);
*
* @since __DEPLOY_VERSION__
*/
class CheckPrivacyPolicyPublishedEvent extends PrivacyEvent
{
/**
* The argument names, in order expected by legacy plugins.
*
* @var array
*
* @since __DEPLOY_VERSION__
* @deprecated 5.0 will be removed in 6.0
*/
protected $legacyArgumentsOrder = ['subject'];

/**
* Constructor.
*
* @param string $name The event name.
* @param array $arguments The event arguments.
*
* @throws \BadMethodCallException
*
* @since __DEPLOY_VERSION__
*/
public function __construct($name, array $arguments = [])
{
parent::__construct($name, $arguments);

if (!\array_key_exists('subject', $this->arguments)) {
throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided");
}
}

/**
* Setter for the subject argument.
*
* @param array|\ArrayAccess $value The value to set
*
* @return array|\ArrayAccess
*
* @since __DEPLOY_VERSION__
*/
protected function setSubject(array|\ArrayAccess $value): array|\ArrayAccess
{
return $value;
}

/**
* Getter for the policy check.
*
* @return array|\ArrayAccess
*
* @since __DEPLOY_VERSION__
*/
public function getPolicyInfo(): array|\ArrayAccess
{
return $this->arguments['subject'];
}
}
Loading