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

Add event to alter delete website confirmation #22484

Merged
merged 22 commits into from
Sep 4, 2024

Conversation

AltamashShaikh
Copy link
Contributor

@AltamashShaikh AltamashShaikh commented Aug 7, 2024

Description:

When a website is about to be deleted Matomo currently shows a confirmation.
As users might not be aware which additional plugin data might be removed with that, plugins should have the possibility to add some additional information/warning to that confirmation.

This PR introduces a new event SitesManager.getMessagesToWarnOnSiteRemoval, which allows plugins to provide additional text blocks that should be displayed within the modal.

Fixes: #PG-3574

Review

plugins/SitesManager/API.php Outdated Show resolved Hide resolved
@AltamashShaikh AltamashShaikh added the Needs Review PRs that need a code review label Aug 7, 2024
@AltamashShaikh AltamashShaikh requested a review from a team August 7, 2024 10:38
@michalkleiner michalkleiner changed the title Adds event to alter delete website explanation, #PG-3574 Add event to alter delete website explanation, #PG-3574 Aug 8, 2024
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

Hey @AltamashShaikh,
I've discussed the solution again in core team. As mentioned before the "perfect" solution would be using a javascript event, that plugins like the TagManager could easily use to add content to the confirmation. But as we currently do not have something like a global javascript event registry it is not really possible to solve it that way.
Such a javascript event registry would be beneficial for a lot other use cases as well, but core team would need to plan and work on that separately.

To be able to allow altering the removal confirmation already we might indeed need to go with a similar workaround like you implemented. But from our point of view the implementation - especially in TagManager - is too unflexible.
You are currently fully replacing the text of the confirmation. That for sure works, but if another plugin would aim to do the same the result is completely unpredictable. The plugin, that would be loaded last, would most likely "win the race" and place it's content, while the content of other plugins is simply overwritten.
When introducing new events you should always consider that other plugins might want to use those events as well.
My approach here would have been to have an event that only provides sort of a list of things to warn that the will be removed as well and keep a more general basic message as introduction.
So there would be an event like getThingsToWarnOnSiteRemoval, which receives the idSite and a variable, prefilled with an empty array. TagManager can then add the items that will be removed to that array. If the list contains items after calling the event, core would adjust the message to add them accordingly.

@AltamashShaikh
Copy link
Contributor Author

roducing new events you should always consider that other plugins might want to use those events as well.
My approach here would have been to have an event that only provides sort of a list of things to warn that the will be removed as well and keep a more general basic message as introductio

@sgiehl I changed the event to pass an array with a default message that as the first key and plugins can add into the array of update the first key as required, will that work for you guys ??

@sgiehl sgiehl added this to the 5.2.0 milestone Aug 28, 2024
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

I've left a couple of comments for further improvements. Let me know if you have questions on anything...

plugins/SitesManager/API.php Outdated Show resolved Hide resolved
plugins/SitesManager/API.php Outdated Show resolved Hide resolved
plugins/SitesManager/API.php Outdated Show resolved Hide resolved
plugins/SitesManager/API.php Outdated Show resolved Hide resolved
plugins/SitesManager/API.php Outdated Show resolved Hide resolved
plugins/SitesManager/vue/src/SiteFields/SiteFields.vue Outdated Show resolved Hide resolved
@AltamashShaikh
Copy link
Contributor Author

@sgiehl I have updated the code as per your suggestion if all okay please don't merge as I need to get the text checked from product once to ensure if we need to change anything in core.

@AltamashShaikh
Copy link
Contributor Author

@sgiehl All good from product team to merge this 👍
Please review and merge this

{
$messages = [];
Piwik::checkUserHasSuperUserAccess($idSite);
Piwik::postEvent('SitesManager.getMessagesToWarnOnSiteRemoval', [$idSite, &$messages]);
Copy link
Member

Choose a reason for hiding this comment

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

We should add a comment above the event to document what it is good for. Like it'S e.g. the case here:

/**
* Triggered before a task is executed.
*
* A plugin can listen to it and modify whether a specific task should be executed or not. This way
* you can force certain tasks to be executed more often or for example to be never executed.
*
* @param bool &$shouldExecuteTask Decides whether the task will be executed.
* @param Task $task The task that is about to be executed.
*/
Piwik::postEvent('ScheduledTasks.shouldExecuteTask', array(&$shouldExecuteTask, $task));

And when looking at other events it seems we use to pass the referenced parameter first, and then the other. So you may switch idSite and messages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sgiehl Added as suggested 👍

@sgiehl sgiehl changed the title Add event to alter delete website explanation, #PG-3574 Add event to alter delete website confirmation Sep 4, 2024
@sgiehl sgiehl added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Sep 4, 2024
@sgiehl sgiehl merged commit 50477f7 into 5.x-dev Sep 4, 2024
24 of 25 checks passed
@sgiehl sgiehl deleted the PG-3574-delete-website-message-event branch September 4, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants