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

Adds new license key section to plugin menu #21617

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions plugins/Marketplace/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public function subscriptionOverview()
));
}


public function manageLicenseKey()
{
Piwik::checkUserHasSuperUserAccess();

return $this->renderTemplate('@Marketplace/manageLicenseKey', array(
'hasValidLicenseKey' => $this->licenseKey->has() && $this->consumer->isValidConsumer(),
));
}

private function getPrettyLongDate($date)
{
if (empty($date)) {
Expand Down
1 change: 1 addition & 0 deletions plugins/Marketplace/Marketplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = 'CorePluginsAdmin_MissingRequirementsNotice';
$translationKeys[] = 'Marketplace_Marketplace';
$translationKeys[] = 'Marketplace_RichMenuIntro';
$translationKeys[] = 'Marketplace_ManageLicenseKeyIntro';
}

/**
Expand Down
20 changes: 15 additions & 5 deletions plugins/Marketplace/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\Marketplace;

use Piwik\Menu\MenuAdmin;
Expand All @@ -19,15 +20,24 @@ class Menu extends \Piwik\Plugin\Menu
public function configureAdminMenu(MenuAdmin $menu)
{
if (!Piwik::isUserIsAnonymous()) {
$menu->addPlatformItem('Marketplace_Marketplace',
$menu->addPlatformItem(
'Marketplace_Marketplace',
$this->urlForAction('overview', ['activated' => '', 'mode' => 'admin', 'type' => '', 'show' => '']),
5);
5
);
}

if (Piwik::hasUserSuperUserAccess()) {
$menu->addPluginItem(Piwik::translate('General_ManageSubscriptions'),
$menu->addPluginItem(
Piwik::translate('Marketplace_LicenseKey'),
$this->urlForAction('manageLicenseKey'),
10
);
$menu->addPluginItem(
Piwik::translate('General_ManageSubscriptions'),
$this->urlForAction('subscriptionOverview'),
20);
20
);
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/Marketplace/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"LastUpdated": "Last Updated",
"License": "License",
"LicenseKey": "License key",
"ManageLicenseKeyIntro": "You can extend Matomo's capabilities using our premium plugins. To install premium plugins, you need a valid license key, which can be obtained in two ways: you can start a trial for your selected plugin in the %1$smarketplace%2$s, or purchase a plugin subscription on %3$sour website%4$s. Starting a trial in the marketplace will automatically create a license key and add it to this instance. If you purchase a subscription on the website, you will receive a license key that you can add it in the field below. After your license key is added, you can update or remove it if needed.",
"LicenseKeyActivatedSuccess": "License key successfully activated!",
"LicenseKeyDeletedSuccess": "License key successfully deleted.",
"Exceeded": "Exceeded",
Expand Down
28 changes: 27 additions & 1 deletion plugins/Marketplace/stylesheets/marketplace.less
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,30 @@
margin-top: 20px;
margin-bottom: 20px;
}
}
}

.manage-license-key {
.manage-license-key-input {
mneudert marked this conversation as resolved.
Show resolved Hide resolved
width: 50%;
display: inline-block;
vertical-align: middle;

.row .col {
sgiehl marked this conversation as resolved.
Show resolved Hide resolved
padding-left: 0;
}
}

.loadingPiwik,
#submit_license_key {
display: inline-block;
}

#remove_license_key {
display: inline-block;
margin-left: 3.5px;

.btn {
background-color: @color-red-matomo;
}
}
}
12 changes: 12 additions & 0 deletions plugins/Marketplace/templates/manageLicenseKey.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "admin.twig" %}

{% set title %}{{ 'Marketplace_LicenseKey'|translate }}{% endset %}

{% block content %}

<div
vue-entry="Marketplace.ManageLicenseKey"
has-valid-license-key="{{ hasValidLicenseKey|default(false)|json_encode }}"
></div>

{% endblock %}
70 changes: 70 additions & 0 deletions plugins/Marketplace/tests/UI/ManageLicense_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*!
* Matomo - free/libre analytics platform
*
* Screenshot tests for Marketplace.
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

describe("ManageLicense", function () {
this.timeout(0);

this.fixture = "Piwik\\Plugins\\Marketplace\\tests\\Fixtures\\SimpleFixtureTrackFewVisits";

const urlBase = '?module=Marketplace&action=manageLicenseKey';

async function captureSelector(screenshotName, selector)
{
await page.evaluate(function () {
mneudert marked this conversation as resolved.
Show resolved Hide resolved
$('#secondNavBar').css('visibility', 'hidden'); // hide navbar so shadow isn't shown on screenshot
});
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(selector)).to.matchImage(screenshotName);
}

it('should show manage license key page', async function () {
await page.goto(urlBase);
await page.mouse.move(-10, -10);

await captureSelector('loaded', '.pageWrap,#notificationContainer');
});

it('should not accept invalid license key', async function () {
await page.type('#license_key', 'invalid_key');
await page.click('#submit_license_key input');

await captureSelector('invalid', '.pageWrap,#notificationContainer');
});

it('should accept valid license key', async function () {
await page.goto(urlBase);
await page.type('#license_key', 'valid');
await page.waitForTimeout(200);

testEnvironment.consumer = 'validLicense';
testEnvironment.mockMarketplaceApiService = 1;
testEnvironment.save();

await page.click('#submit_license_key input');

await captureSelector('valid', '.pageWrap,#notificationContainer');
});

it('should show dialog before removing license', async function () {
await page.click('#remove_license_key input');

await captureSelector('remove_dialog', '.modal.open');
});

it('should remove license on confirm', async function () {
delete testEnvironment.consumer;
delete testEnvironment.mockMarketplaceApiService;
testEnvironment.save();

const button = await page.jQuery('.modal.open .modal-footer a:contains(Yes)');
await button.click();

await captureSelector('removed', '.pageWrap,#notificationContainer');
});
});
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading