Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/global.ini.php5
-rw-r--r--plugins/SegmentEditor/API.php8
-rw-r--r--plugins/SegmentEditor/SegmentEditor.php11
-rw-r--r--plugins/SegmentEditor/SegmentSelectorControl.php2
-rw-r--r--plugins/SegmentEditor/lang/en.json3
-rw-r--r--plugins/SegmentEditor/templates/_segmentSelector.twig2
6 files changed, 28 insertions, 3 deletions
diff --git a/config/global.ini.php b/config/global.ini.php
index ff987583d2..d72d5e6150 100644
--- a/config/global.ini.php
+++ b/config/global.ini.php
@@ -177,6 +177,11 @@ enable_segment_suggested_values = 1
; Possible values are "view", "admin", "superuser"
adding_segment_requires_access = "view"
+; Whether it is allowed for users to add segments that affect all websites or not. If there are many websites
+; this admin option can be used to prevent users from performing an action that will have a major impact
+; on Piwik performance.
+allow_adding_segments_for_all_websites = 1
+
; this action name is used when the URL ends with a slash /
; it is useful to have an actual string to write in the UI
action_default_name = index
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index 301fe44a50..98b752cc2a 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -115,7 +115,13 @@ class API extends \Piwik\Plugin\API
protected function checkUserCanAddNewSegment($idSite)
{
- if(!$this->isUserCanAddNewSegment($idSite)) {
+ if (empty($idSite)
+ && !SegmentEditor::isAddingSegmentsForAllWebsitesEnabled()
+ ) {
+ throw new Exception(Piwik::translate('SegmentEditor_AddingSegmentForAllWebsitesDisabled'));
+ }
+
+ if (!$this->isUserCanAddNewSegment($idSite)) {
throw new Exception(Piwik::translate('SegmentEditor_YouDontHaveAccessToCreateSegments'));
}
}
diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php
index a79cc0be24..bd957c54c0 100644
--- a/plugins/SegmentEditor/SegmentEditor.php
+++ b/plugins/SegmentEditor/SegmentEditor.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\SegmentEditor;
+use Piwik\Config;
use Piwik\Db;
use Piwik\DbHelper;
use Piwik\Version;
@@ -98,4 +99,14 @@ class SegmentEditor extends \Piwik\Plugin
{
$stylesheets[] = "plugins/SegmentEditor/stylesheets/segmentation.less";
}
+
+ /**
+ * Returns whether adding segments for all websites is enabled or not.
+ *
+ * @return bool
+ */
+ public static function isAddingSegmentsForAllWebsitesEnabled()
+ {
+ return Config::getInstance()->General['allow_adding_segments_for_all_websites'] == 1;
+ }
}
diff --git a/plugins/SegmentEditor/SegmentSelectorControl.php b/plugins/SegmentEditor/SegmentSelectorControl.php
index bb58caa297..4e88d2191f 100644
--- a/plugins/SegmentEditor/SegmentSelectorControl.php
+++ b/plugins/SegmentEditor/SegmentSelectorControl.php
@@ -37,6 +37,8 @@ class SegmentSelectorControl extends UIControl
$this->selectedSegment = Common::getRequestVar('segment', false, 'string');
+ $this->isAddingSegmentsForAllWebsitesEnabled = SegmentEditor::isAddingSegmentsForAllWebsitesEnabled();
+
$segments = APIMetadata::getInstance()->getSegmentsMetadata($this->idSite);
$segmentsByCategory = array();
diff --git a/plugins/SegmentEditor/lang/en.json b/plugins/SegmentEditor/lang/en.json
index 999b0d41bb..a3f03751d8 100644
--- a/plugins/SegmentEditor/lang/en.json
+++ b/plugins/SegmentEditor/lang/en.json
@@ -24,6 +24,7 @@
"VisibleToMe": "me",
"YouMayChangeSetting": "Alternatively you may change the setting in the config file (%s), or edit this Segment and choose '%s'.",
"YouMustBeLoggedInToCreateSegments": "You must be logged in to create and edit custom visitor segments.",
- "YouDontHaveAccessToCreateSegments": "You don't have the required access level to create and edit segments."
+ "YouDontHaveAccessToCreateSegments": "You don't have the required access level to create and edit segments.",
+ "AddingSegmentForAllWebsitesDisabled": "Adding segments for all websites has been disabled."
}
} \ No newline at end of file
diff --git a/plugins/SegmentEditor/templates/_segmentSelector.twig b/plugins/SegmentEditor/templates/_segmentSelector.twig
index 89c8a314bf..1d1b2275d8 100644
--- a/plugins/SegmentEditor/templates/_segmentSelector.twig
+++ b/plugins/SegmentEditor/templates/_segmentSelector.twig
@@ -122,7 +122,7 @@
{{ 'SegmentEditor_SegmentIsDisplayedForWebsite'|translate }}<span class="visible_to_website"><strong>
<select class="visible_to_website_select">
<option selected="" value="{{ idSite }}">{{ 'SegmentEditor_SegmentDisplayedThisWebsiteOnly'|translate }}</option>
- <option value="0">{{ 'SegmentEditor_SegmentDisplayedAllWebsites'|translate }}</option>
+ {% if isAddingSegmentsForAllWebsitesEnabled %}<option value="0">{{ 'SegmentEditor_SegmentDisplayedAllWebsites'|translate }}</option>{% endif %}
</select>
</strong></span>
{{ 'General_And'|translate }} <span class="auto_archive"><strong>