Skip to content

Commit

Permalink
Add event to alter delete website confirmation (#22484)
Browse files Browse the repository at this point in the history
* Adds event to alter delete website explanation, #PG-3574

* Refactor code to getDeleteExplantionText only when deleteAction is triggered

* Ui test updated

* Updated UI screenshot

* Updated UI screenshot

* Apply PR feedback

* Updated UI screenshot

* Apply PR feedbacks

* Fixes failing tests

* Removes TagManager dependent test

* Changes for even space

* Applied PR feedback

---------

Co-authored-by: Michal Kleiner <[email protected]>
  • Loading branch information
AltamashShaikh and michalkleiner authored Sep 4, 2024
1 parent 7cbe3b4 commit 50477f7
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 33 deletions.
26 changes: 26 additions & 0 deletions plugins/SitesManager/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,32 @@ public function getSitesWithAdminAccess($fetchAliasUrls = false, $pattern = fals
return $sites;
}

/**
* Returns the messages to warn users on site deletion.
*
* @param int $idSite
* @return array messages to warn users
* @throws Exception if the website ID doesn't exist or the user doesn't have super user access to it
* @internal
* @unsanitized
*/
public function getMessagesToWarnOnSiteRemoval(int $idSite): array
{
$messages = [];
Piwik::checkUserHasSuperUserAccess();
/**
* Triggered before a modal to delete a measurable is displayed
*
* A plugin can listen to it and add additional information to be displayed in the measurable delete modal body
*
* @param array &$messages Additional messages to be shown in the delete measurable modal body
* @param int $idSite The idSite to be deleted
*/
Piwik::postEvent('SitesManager.getMessagesToWarnOnSiteRemoval', [&$messages, $idSite]);

return $messages;
}

/**
* Returns the list of websites with the 'view' access for the current user.
* For the superUser it doesn't return any result because the superUser has admin access on all the websites (use getSitesWithAtLeastViewAccess() instead).
Expand Down
19 changes: 19 additions & 0 deletions plugins/SitesManager/tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,25 @@ public function testGetSitesWithAdminAccessShouldApplyPatternAndLimit()
$this->assertReturnedSitesContainsSiteIds([5, 15], $sites);
}

public function testGetMessagesToWarnOnSiteRemovalShouldReturnDefaultValue()
{
$pluginManager = Plugin\Manager::getInstance();
if ($pluginManager->isPluginActivated('TagManager')) {
$pluginManager->deactivatePlugin('TagManager');
}
API::getInstance()->addSite("site1", ["http://piwik.net", "http://piwik.com"]);
API::getInstance()->addSite("site2", ["http://piwik.com", "http://piwik.net"]);
$this->assertEmpty(API::getInstance()->getMessagesToWarnOnSiteRemoval(1));
$this->assertEmpty(API::getInstance()->getMessagesToWarnOnSiteRemoval(2));
}

public function testGetMessagesToWarnOnSiteRemovalShouldThrowExceptionIfNotSuperUser()
{
$this->expectException(\Exception::class);
$this->createManySitesWithAdminAccess(1);
API::getInstance()->getMessagesToWarnOnSiteRemoval(1);
}

private function createManySitesWithAdminAccess($numSites)
{
for ($i = 1; $i <= $numSites; $i++) {
Expand Down
Loading

0 comments on commit 50477f7

Please sign in to comment.