Skip to content

Commit

Permalink
Ensure plugin updates are not offered in UI if plugin admin is disabl…
Browse files Browse the repository at this point in the history
…ed in config (#22538)
  • Loading branch information
sgiehl authored Aug 29, 2024
1 parent 52feda6 commit ecb4f2b
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 87 deletions.
6 changes: 3 additions & 3 deletions config/environment/ui-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
'tests.ui.url_normalizer_blacklist.controller' => [],

// disable check for plugin updates during UI tests, allow for override
'dev.disable_plugin_update_checks' => Piwik\DI::decorate(function ($previous, Container $c) {
return !$c->get('test.vars.forceEnablePluginUpdateChecks');
'dev.forced_plugin_update_result' => Piwik\DI::decorate(function ($previous, Container $c) {
return $c->get('test.vars.forceEnablePluginUpdateChecks') ? null : [];
}),

'twig.cache' => function (\Piwik\Container\Container $container) {
$templatesPath = $container->get('path.tmp.templates');
return new class($templatesPath) extends \Twig\Cache\FilesystemCache {
return new class ($templatesPath) extends \Twig\Cache\FilesystemCache {
public function write(string $key, string $content): void
{
$retryCount = 3;
Expand Down
2 changes: 1 addition & 1 deletion config/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

'observers.global' => [],

'dev.disable_plugin_update_checks' => false,
'dev.forced_plugin_update_result' => null,

/**
* By setting this option to false, the check that the DB schema version matches the version of the source code will
Expand Down
3 changes: 1 addition & 2 deletions plugins/CorePluginsAdmin/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function configureAdminMenu(MenuAdmin $menu)

$pluginsUpdateMessage = '';

$skipPluginUpdateCheck = StaticContainer::get('dev.disable_plugin_update_checks');
if (!$skipPluginUpdateCheck && $hasSuperUserAccess && $isMarketplaceEnabled && $this->marketplacePlugins) {
if ($hasSuperUserAccess && $isMarketplaceEnabled && $this->marketplacePlugins) {
$pluginsHavingUpdate = $this->marketplacePlugins->getPluginsHavingUpdate();

if (!empty($pluginsHavingUpdate)) {
Expand Down
1 change: 1 addition & 0 deletions plugins/CorePluginsAdmin/templates/plugins.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
plugin-update-nonces="{{ pluginUpdateNonces|default({})|json_encode }}"
update-nonce="{{ updateNonce|json_encode }}"
is-multi-server-environment="{{ isMultiServerEnvironment|default(false)|json_encode }}"
is-plugins-admin-enabled="{{ isPluginsAdminEnabled|default(null)|json_encode }}"
></div>

<div
Expand Down
43 changes: 43 additions & 0 deletions plugins/CorePluginsAdmin/tests/Fixtures/PluginUpdatesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\CorePluginsAdmin\tests\Fixtures;

use Piwik\Tests\Framework\Fixture;

/**
* Fixture that fakes plugin updates to be available
*/
class PluginUpdatesFixture extends Fixture
{
public $idSite = 1;
public function setUp(): void
{
Fixture::createSuperUser();
$this->setUpWebsites();
}

private function setUpWebsites()
{
if (!self::siteCreated($idSite = 1)) {
self::createWebsite('2024-01-01');
}
}

public function provideContainerConfig()
{
$updates = <<<JSON
{"DeviceDetectorCache":{"name":"DeviceDetectorCache","displayName":"Device Detector Cache","owner":"matomo-org","description":"Makes tracking faster by detecting many devices, operating systems, bots, and browsers from a cache.","homepage":"https:\/\/matomo.org","createdDateTime":"2019-10-23 20:14:04","donate":[],"support":[{"name":"Issues \/ Bugs","key":"issues","value":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache\/issues","type":"url"}],"isTheme":false,"keywords":["performance","tracking","device","detector"],"basePrice":0,"authors":[{"name":"Matomo","email":"[email protected]","homepage":"https:\/\/matomo.org"}],"repositoryUrl":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache","lastUpdated":"2024-04-22 05:58:02","latestVersion":"5.0.3","numDownloads":22896,"screenshots":[],"coverImage":"https:\/\/plugins.matomo.org\/img\/categories\/database.png","previews":[],"activity":{"numCommits":"148","numContributors":"20","lastCommitDate":"2024-08-15 06:18:49"},"featured":false,"isFree":true,"isPaid":false,"isBundle":false,"isCustomPlugin":false,"shop":null,"bundle":{"plugins":[]},"specialOffer":"","category":"database","versions":[{"name":"5.0.0","release":"2023-05-05 00:28:03","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":67,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/DeviceDetectorCache\/5.0.0\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache\/commits\/5.0.0-b1","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/DeviceDetectorCache\/download\/5.0.0"},{"name":"5.0.1","release":"2023-10-03 04:32:03","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":96,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/DeviceDetectorCache\/5.0.1\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache\/commits\/5.0.1","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/DeviceDetectorCache\/download\/5.0.1"},{"name":"5.0.2","release":"2023-11-21 00:40:03","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":2058,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/DeviceDetectorCache\/5.0.2\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache\/commits\/5.0.2","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/DeviceDetectorCache\/download\/5.0.2"},{"name":"5.0.3","release":"2024-04-22 05:58:02","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":2403,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/DeviceDetectorCache\/5.0.3\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache\/commits\/5.0.3","readmeHtml":{"description":"Dummy Plugin Description"},"download":"\/api\/2.0\/plugins\/DeviceDetectorCache\/download\/5.0.3"}],"isDownloadable":true,"changelog":{"url":"https:\/\/plugins.matomo.org\/DeviceDetectorCache\/changelog?matomoversion=5"},"consumer":{"license":null},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-DeviceDetectorCache\/compare\/5.0.2...5.0.3","currentVersion":"5.0.2","isActivated":false,"missingRequirements":[]},"QueuedTracking":{"name":"QueuedTracking","displayName":"Queued Tracking","owner":"matomo-org","description":"Scale your large traffic Matomo service by queuing tracking requests in Redis or MySQL for better performance and reliability when experiencing peaks.","homepage":"https:\/\/matomo.org","createdDateTime":"2015-01-05 23:28:04","donate":[],"support":[{"name":"Wiki","key":"wiki","value":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/wiki","type":"url"},{"name":"Forum","key":"forum","value":"https:\/\/forum.matomo.org","type":"url"},{"name":"Email","key":"email","value":"[email protected]","type":"email"},{"name":"Issues \/ Bugs","key":"issues","value":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/issues","type":"url"},{"name":"Source","key":"source","value":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking","type":"url"}],"isTheme":false,"keywords":["tracker","tracking","queue","redis"],"basePrice":0,"authors":[{"name":"Matomo","email":"[email protected]","homepage":"https:\/\/matomo.org"}],"repositoryUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking","lastUpdated":"2024-08-26 04:30:04","latestVersion":"5.0.7","numDownloads":603565,"screenshots":["https:\/\/plugins.matomo.org\/QueuedTracking\/images\/5.0.7\/Settings.png"],"coverImage":"https:\/\/plugins.matomo.org\/img\/categories\/development.png","previews":[],"activity":{"numCommits":"362","numContributors":"38","lastCommitDate":"2024-08-26 04:29:16"},"featured":false,"isFree":true,"isPaid":false,"isBundle":false,"isCustomPlugin":false,"shop":null,"bundle":{"plugins":[]},"specialOffer":"","category":"development","versions":[{"name":"5.0.0","release":"2023-05-05 05:36:06","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":2237,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.0\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.0-b1","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.0"},{"name":"5.0.1","release":"2023-08-08 22:40:03","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":0,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.1\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.0-b2","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.1"},{"name":"5.0.2","release":"2023-08-09 02:24:03","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":107207,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.2\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.0-b2","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.2"},{"name":"5.0.3","release":"2024-03-11 04:08:03","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":2329,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.3\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.3","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.3"},{"name":"5.0.4","release":"2024-04-22 07:14:04","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":3560,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.4\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.4","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.4"},{"name":"5.0.5","release":"2024-06-27 06:50:49","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":1305,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.5\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.5","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.5"},{"name":"5.0.6","release":"2024-07-31 02:46:04","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":1447,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.6\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.6","readmeHtml":{"description":"","faq":"","changelog":"","documentation":""},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.6"},{"name":"5.0.7","release":"2024-08-26 04:30:04","requires":{"matomo":">=5.0.0-b1,<6.0.0-b1"},"wordPressCompatible":true,"onPremiseCompatible":true,"numDownloads":227,"license":{"name":"GPL v3+","url":"https:\/\/plugins.matomo.org\/QueuedTracking\/5.0.7\/license"},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/commits\/5.0.7","readmeHtml":{"description":"Dummy README content"},"download":"\/api\/2.0\/plugins\/QueuedTracking\/download\/5.0.7"}],"isDownloadable":true,"changelog":{"url":"https:\/\/plugins.matomo.org\/QueuedTracking\/changelog?matomoversion=5"},"consumer":{"license":null},"repositoryChangelogUrl":"https:\/\/github.com\/matomo-org\/plugin-QueuedTracking\/compare\/5.0.6...5.0.7","currentVersion":"5.0.6","isActivated":false,"missingRequirements":[{"requirement":"php","actualVersion":"7.2.24","requiredVersion":">=7.3.0","causedBy":">=7.3.0"}]}}
JSON;

return [
'dev.forced_plugin_update_result' => json_decode($updates, true)
];
}
}
56 changes: 56 additions & 0 deletions plugins/CorePluginsAdmin/tests/UI/PluginsAdmin_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*!
* Matomo - free/libre analytics platform
*
* Screenshot integration tests.
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

describe("PluginsAdmin", function () {

this.fixture = "Piwik\\Plugins\\CorePluginsAdmin\\tests\\Fixtures\\PluginUpdatesFixture"

var generalParams = 'idSite=1&period=year&date=2024-08-09';

async function screenshotPageWrap() {
const pageWrap = await page.$('.pageWrap');
const screenshot = await pageWrap.screenshot();
return screenshot;
}

it('should load the themes admin page correctly', async function () {
await page.goto("?" + generalParams + "&module=CorePluginsAdmin&action=themes");

expect(await screenshotPageWrap()).to.matchImage('themes');
});

it('should load the plugins admin page correctly', async function () {
await page.goto("?" + generalParams + "&module=CorePluginsAdmin&action=plugins");

expect(await screenshotPageWrap()).to.matchImage('plugins');
});

it('should load the plugins admin page correctly when internet disabled', async function () {
testEnvironment.overrideConfig('General', {
enable_internet_features: 0
});
testEnvironment.save();

await page.goto("?" + generalParams + "&module=CorePluginsAdmin&action=plugins");

expect(await screenshotPageWrap()).to.matchImage('plugins_no_internet');
});

it('should load the plugins admin page correctly when admin disabled', async function () {
testEnvironment.overrideConfig('General', {
enable_plugins_admin: 0
});
testEnvironment.save();

await page.goto("?" + generalParams + "&module=CorePluginsAdmin&action=plugins");

expect(await screenshotPageWrap()).to.matchImage('plugins_admin_disabled');
});

});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ecb4f2b

Please sign in to comment.