-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[5.0][Events] Privacy event classes #41486
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1bcbaf4
CollectCapabilities event
Fedik c01b60f
CheckPrivacyPolicyPublished Event
Fedik 1f0d656
ExportRequest Event
Fedik 0f5b80c
ExportRequest Event
Fedik 3216e56
Can remove
Fedik aed1c07
RemoveData Event
Fedik 4d17608
User privacy plugin
Fedik ffbea47
Better validation
Fedik d6627aa
Testing test
Fedik 287b6c1
Comments
Fedik 6a21505
Merge branch '5.0-dev' into event-privacy
Fedik 7db63ab
Merge branch '5.0-dev' into event-privacy
Fedik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,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
79
libraries/src/Event/Privacy/CheckPrivacyPolicyPublishedEvent.php
This file contains hidden or 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,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']; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
userplugins for each page load?There was a problem hiding this comment.
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