Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions core/Plugin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ protected function setBasicVariablesNoneAdminView($view)
{
$view->clientSideConfig = PiwikConfig::getInstance()->getClientSideOptions();
$view->isSuperUser = Access::getInstance()->hasSuperUserAccess();
$view->userCurrentRole = Access::getInstance()->getRoleForSite($this->idSite);
$view->hasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
$view->hasSomeViewAccess = Piwik::isUserHasSomeViewAccess();
$view->isUserIsAnonymous = Piwik::isUserIsAnonymous();
Expand Down
42 changes: 42 additions & 0 deletions core/Updates/5.7.0-b1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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\Updates;

use Piwik\Updater;
use Piwik\Updater\Migration\Factory as MigrationFactory;
use Piwik\Updates;

class Updates_5_7_0_b1 extends Updates
{
/**
* @var MigrationFactory
*/
private $migration;

public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}

public function getMigrations(Updater $updater)
{
return [
$this->migration->db->addColumns('segment', [
'starred' => 'TINYINT(1) NOT NULL DEFAULT 0',
Comment thread
sgiehl marked this conversation as resolved.
'starred_by' => 'VARCHAR(100) NULL DEFAULT NULL',
]),
];
}

public function doUpdate(Updater $updater)
{
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
}
}
2 changes: 1 addition & 1 deletion core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Version
* The current Matomo version.
* @var string
*/
public const VERSION = '5.7.0-alpha';
public const VERSION = '5.7.0-b1';

public const MAJOR_VERSION = 5;

Expand Down
15 changes: 15 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
"BrokenDownReportDocumentation": "It is broken down into various reports, which are displayed in sparklines at the bottom of the page. You can enlarge the graphs by clicking on the report you'd like to see.",
"Cancel": "Cancel",
"CannotUnzipFile": "Cannot unzip file %1$s: %2$s",
"CanNotEditGlobalSegment": "This is a global segment. Only super users can edit global segments.",
"CanNotStarGlobalSegment": "This is a global segment. Only super users can star global segments.",
"CanNotUnstarGlobalSegment": "This is a global segment. Only super users can unstar global segments.",
"CanEditGlobalSegment": "This is a global segment. Any changes will apply across all websites.",
"CanStarGlobalSegment": "This is a global segment. Adding to Starred will apply across all websites.",
"CanUnstarGlobalSegment": "This is a global segment. Removing from Starred will apply across all websites.",
"CanNotEditSiteSegment": "You can only edit the segments you created yourself.",
"CanNotStarSiteSegment": "You can only add to Starred the segments you created yourself.",
"CanNotUnstarSiteSegment": "You can only remove from Starred the segments you created yourself.",
"CanEditSiteSegment": "Edit the segment for this website.",
"CanStarSiteSegment": "Add to Starred segments for this website.",
"CanUnstarSiteSegment": "Remove from Starred segments for this website.",
"ChangeInX": "Change in %1$s",
"ChangePassword": "Change password",
"ChangeTagCloudView": "Please note, that you can view the report in other ways than as a tag cloud. Use the controls at the bottom of the report to do so.",
Expand Down Expand Up @@ -463,6 +475,9 @@
"SmtpServerAddress": "SMTP server address",
"SmtpUsername": "SMTP username",
"Source": "Source",
"Star": "Star",
"StarredBy": "Starred by",
Comment thread
michalkleiner marked this conversation as resolved.
"StarredByYou": "Starred by you",
"StatisticsAreNotRecorded": "Matomo Visitor Tracking is currently disabled! Re-enable tracking by setting record_statistics = 1 in your config/config.ini.php file.",
"Subtotal": "Subtotal",
"Summary": "Summary",
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4658,11 +4658,6 @@ parameters:
count: 1
path: plugins/ScheduledReports/ScheduledReports.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
path: plugins/SegmentEditor/API.php

-
message: "#^Parameter \\#2 \\$idSites of class Piwik\\\\Segment constructor expects array, int\\|null given\\.$#"
count: 1
Expand Down
14 changes: 14 additions & 0 deletions plugins/CoreHome/vue/dist/CoreHome.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/CoreHome/vue/dist/CoreHome.umd.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions plugins/CoreHome/vue/src/Comparisons/Comparisons.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ export default class ComparisonsStore {
);
}

removeSegmentComparisonByDefinition(segmentDefinition: string): void {
if (!this.isComparisonEnabled()) {
throw new Error('Comparison disabled.');
}
let segmentIndex = null;
this.getSegmentComparisons().forEach((segment: SegmentComparison, index: number) => {
if (segment && segment.params && segment.params.segment === segmentDefinition) {
segmentIndex = index;
}
});
if (segmentIndex !== null) {
this.removeSegmentComparison(segmentIndex);
}
}

addSegmentComparison(params: { [name: string]: string }): void {
if (!this.isComparisonEnabled()) {
throw new Error('Comparison disabled.');
Expand Down
2 changes: 2 additions & 0 deletions plugins/CoreVue/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ declare global {
languageName: string;
isPagesComparisonApiDisabled: boolean; // can be set to avoid checks on Api.getPagesComparisonsDisabledFor
userLogin?: string;
userCurrentRole: string;
isUserAnonymous: boolean;
userHasSomeAdminAccess: boolean;
requiresPasswordConfirmation: boolean;
disableTrackingMatomoAppLinks: boolean;
Expand Down
2 changes: 2 additions & 0 deletions plugins/Morpheus/templates/_jsGlobalVariables.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@

piwik.hasSuperUserAccess = {{ hasSuperUserAccess|default(0)|e('js')}};
piwik.userHasSomeAdminAccess = {{ userHasSomeAdminAccess|json_encode|raw }};
piwik.userCurrentRole = "{{ userCurrentRole|default('view')|e('js') }}";
piwik.isUserIsAnonymous = {{ isUserIsAnonymous|default(0)|e('js') }};
piwik.userCapabilities = {{ userCapabilities|default([])|json_encode|raw }};
piwik.config = {};
{% if clientSideConfig is defined %}
Expand Down
68 changes: 60 additions & 8 deletions plugins/SegmentEditor/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function checkUserCanEditOrDeleteSegment(array $segment): void
throw new Exception($this->getMessageCannotEditSegmentCreatedBySuperUser());
}

if ((int) $segment['enable_only_idsite'] === 0 && !Piwik::hasUserSuperUserAccess()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ Already tested few lines before

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fix a PHPStan error in the same time

if ((int) $segment['enable_only_idsite'] === 0) {
throw new Exception(Piwik::translate('SegmentEditor_UpdatingAllSitesSegmentPermittedToSuperUser'));
}
}
Expand All @@ -215,7 +215,7 @@ public function delete(int $idSegment): void
*
* @param int $idSegment The ID of the segment being deleted.
*/
Piwik::postEvent('SegmentEditor.deactivate', array($idSegment));
Piwik::postEvent('SegmentEditor.deactivate', [$idSegment]);

$this->getModel()->deleteSegment($idSegment);

Expand Down Expand Up @@ -263,14 +263,14 @@ public function update(

$autoArchive = $this->checkAutoArchive($autoArchive, $idSite);

$bind = array(
$bind = [
'name' => $name,
'definition' => $definition,
'enable_all_users' => (int) $enabledAllUsers,
'enable_only_idsite' => (int) $idSite,
'auto_archive' => (int) $autoArchive,
'ts_last_edit' => Date::now()->getDatetime(),
);
];

/**
* Triggered before a segment is modified.
Expand All @@ -280,7 +280,7 @@ public function update(
*
* @param int $idSegment The ID of the segment which visibility is reduced.
*/
Piwik::postEvent('SegmentEditor.update', array($idSegment, $bind));
Piwik::postEvent('SegmentEditor.update', [$idSegment, $bind]);

$this->getModel()->updateSegment($idSegment, $bind);

Expand Down Expand Up @@ -321,16 +321,18 @@ public function add(
$enabledAllUsers = $this->checkEnabledAllUsers($enabledAllUsers);
$autoArchive = $this->checkAutoArchive($autoArchive, $idSite);

$bind = array(
$bind = [
'name' => $name,
'definition' => $definition,
'login' => Piwik::getCurrentUserLogin(),
'enable_all_users' => (int) $enabledAllUsers,
'enable_only_idsite' => (int) $idSite,
'auto_archive' => (int) $autoArchive,
'ts_created' => Date::now()->getDatetime(),
'starred' => 0,
'starred_by' => null,
'deleted' => 0,
);
];

$id = $this->getModel()->createSegment($bind);

Expand All @@ -348,6 +350,56 @@ public function add(
return $id;
}

/**
* Stars a stored segment.
*
* @param int $idSegment
* @return array{result: boolean, starred_by: string}
* @throws Exception if the user is not logged in or does not have the required permissions.
*/
public function star(int $idSegment): array
{
Piwik::checkUserHasSomeViewAccess();
$segment = $this->getSegmentOrFail($idSegment);
Comment thread
tzi marked this conversation as resolved.
$this->checkUserCanEditOrDeleteSegment($segment);
$login = Piwik::getCurrentUserLogin();
$bind = [
'starred' => 1,
'starred_by' => $login,
];

$result = $this->getModel()->updateSegment($idSegment, $bind);

return [
'result' => $result,
'starred_by' => $login,
];
}

/**
* Unstars a stored segment.
*
* @param int $idSegment
* @return array{result: boolean}
* @throws Exception if the user is not logged in or does not have the required permissions.
*/
public function unstar(int $idSegment): array
{
Piwik::checkUserHasSomeViewAccess();
$segment = $this->getSegmentOrFail($idSegment);
$this->checkUserCanEditOrDeleteSegment($segment);
$bind = [
'starred' => 0,
'starred_by' => null,
];

$result = $this->getModel()->updateSegment($idSegment, $bind);

return [
'result' => $result,
];
}

/**
* Returns a stored segment by ID
*
Expand Down Expand Up @@ -444,7 +496,7 @@ private function filterSegmentsWithDisabledElements(array $segments, $idSite = n
*/
private function sortSegmentsCreatedByUserFirst(array $segments): array
{
$orderedSegments = array();
$orderedSegments = [];
foreach ($segments as $id => &$segment) {
if ($segment['login'] == Piwik::getCurrentUserLogin()) {
$orderedSegments[] = $segment;
Expand Down
2 changes: 2 additions & 0 deletions plugins/SegmentEditor/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ public static function install()
`auto_archive` tinyint(4) NOT NULL default 0,
`ts_created` TIMESTAMP NULL,
`ts_last_edit` TIMESTAMP NULL,
`starred` tinyint(4) NOT NULL default 0,
`starred_by` VARCHAR(100) NULL default NULL,
`deleted` tinyint(4) NOT NULL default 0,
PRIMARY KEY (`idsegment`)";

Expand Down
15 changes: 15 additions & 0 deletions plugins/SegmentEditor/SegmentSelectorControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ private function wouldApplySegment($savedSegment)
private function getTranslations()
{
$translationKeys = array(
'General_CanNotEditGlobalSegment',
'General_CanNotStarGlobalSegment',
'General_CanNotUnstarGlobalSegment',
'General_CanEditGlobalSegment',
'General_CanStarGlobalSegment',
'General_CanUnstarGlobalSegment',
'General_CanNotEditSiteSegment',
'General_CanNotStarSiteSegment',
'General_CanNotUnstarSiteSegment',
'General_CanEditSiteSegment',
'General_CanStarSiteSegment',
'General_CanUnstarSiteSegment',
'General_OperationEquals',
'General_OperationNotEquals',
'General_OperationAtMost',
Expand All @@ -127,6 +139,9 @@ private function getTranslations()
'General_DefaultAppended',
'SegmentEditor_AddNewSegment',
'General_Edit',
'General_StarredBy',
'General_StarredByYou',
'General_Edit',
'General_Search',
'General_SearchNoResults',
);
Expand Down
Binary file removed plugins/SegmentEditor/images/edit_segment.png
Binary file not shown.
3 changes: 3 additions & 0 deletions plugins/SegmentEditor/images/edit_segment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading