diff options
author | diosmosis <benaka@piwik.pro> | 2014-09-10 13:33:37 +0400 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2014-09-10 13:33:37 +0400 |
commit | e79784e0f1274fa76c395e9a84357f7ca3dd6ad6 (patch) | |
tree | 756edc0b30fbcd8b8c42f151f1fb418ac6f52507 /plugins | |
parent | ef61529d414af219e64e42a0578b8df1222d8c5d (diff) |
Fixes #5923, add INI config option allow_adding_segments_for_all_websites that allows users to disable the ability to add segments affecting all websites.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/SegmentEditor/API.php | 8 | ||||
-rw-r--r-- | plugins/SegmentEditor/SegmentEditor.php | 11 | ||||
-rw-r--r-- | plugins/SegmentEditor/SegmentSelectorControl.php | 2 | ||||
-rw-r--r-- | plugins/SegmentEditor/lang/en.json | 3 | ||||
-rw-r--r-- | plugins/SegmentEditor/templates/_segmentSelector.twig | 2 |
5 files changed, 23 insertions, 3 deletions
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> |