From 8c2355e907375b66f40e36818a2372c988164b3d Mon Sep 17 00:00:00 2001 From: Davide Porrovecchio Date: Fri, 16 Apr 2021 14:53:17 +0200 Subject: [PATCH] Simple refactoring Rename plugin Extend the restrictions to some other modules/actions --- CHANGELOG.md | 5 +++++ README.md | 10 +++++----- ...uperUser.php => SuperUserOnlyRestrictions.php | 16 +++++++++------- docs/faq.md | 4 ++-- docs/index.md | 4 ++-- plugin.json | 6 +++--- 6 files changed, 26 insertions(+), 19 deletions(-) rename UsersManagerOnlySuperUser.php => SuperUserOnlyRestrictions.php (59%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f43d13e..fbdc8b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.0.0 + +Rename plugin +Extend the restrictions to some other modules/actions + ## 0.1.0 First release diff --git a/README.md b/README.md index 088df8c..f29ad1a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Matomo UsersManagerOnlySuperUser Plugin +# Matomo SuperUserOnlyRestrictions Plugin ## Description -This plugin restricts the ability to edit users via userSettings to super users only. +This plugin restricts some modules/actions to super users only. ## Installation @@ -13,9 +13,9 @@ Refer to [this Matomo FAQ](https://matomo.org/faq/plugins/faq_21/). Add the following section to your `config.ini.php`: ```ini -[UsersManagerOnlySuperUser] -users_manager_only_super_user_enabled = true +[SuperUserOnlyRestrictions] +super_user_only_restrictions_enabled = true ``` -**Make sure you have direct access to the `config.ini.php` file before using this plugin** \ No newline at end of file +**Make sure you have direct access to the `config.ini.php` file before using this plugin** diff --git a/UsersManagerOnlySuperUser.php b/SuperUserOnlyRestrictions.php similarity index 59% rename from UsersManagerOnlySuperUser.php rename to SuperUserOnlyRestrictions.php index 5bbf156..c4b39ea 100644 --- a/UsersManagerOnlySuperUser.php +++ b/SuperUserOnlyRestrictions.php @@ -7,13 +7,13 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\UsersManagerOnlySuperUser; +namespace Piwik\Plugins\SuperUserOnlyRestrictions; use Piwik\Config; use Piwik\Piwik; use Piwik\Plugins\UsersManager\UsersManager; -class UsersManagerOnlySuperUser extends \Piwik\Plugin +class SuperUserOnlyRestrictions extends \Piwik\Plugin { /** * The configuration array. @@ -23,7 +23,7 @@ class UsersManagerOnlySuperUser extends \Piwik\Plugin protected $pluginConfig; /** - * Construct a new LoginFilterIp instance. + * Construct a new SuperUserOnlyRestrictions instance. */ public function __construct() { parent::__construct(); @@ -39,16 +39,18 @@ public function __construct() { public function registerEvents() { return [ - 'Controller.UsersManager.userSettings' => 'checkUserHasSuperUserAccess', + 'Controller.UsersManager.userSettings' => 'restrictAccess', + 'Controller.Widgetize.index' => 'restrictAccess', + 'Controller.API.listAllAPI' => 'restrictAccess', ]; } /** - * Check if user has super user access. + * Restrict access to super users only, if the plugin is enabled. */ - public function checkUserHasSuperUserAccess() + public function restrictAccess() { - if(isset($this->pluginConfig['users_manager_only_super_user_enabled']) && $this->pluginConfig['users_manager_only_super_user_enabled']){ + if(isset($this->pluginConfig['super_user_only_restrictions_enabled']) && $this->pluginConfig['super_user_only_restrictions_enabled']){ Piwik::checkUserIsNotAnonymous(); Piwik::checkUserHasSuperUserAccess(); } diff --git a/docs/faq.md b/docs/faq.md index ef45094..a40a959 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,3 +1,3 @@ -## FAQ +# FAQ -See readme. \ No newline at end of file +See readme. diff --git a/docs/index.md b/docs/index.md index 991bcac..7554602 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,3 +1,3 @@ -## Documentation +# Documentation -See readme. \ No newline at end of file +See readme. diff --git a/plugin.json b/plugin.json index ebb3881..9415eea 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { - "name": "UsersManagerOnlySuperUser", - "description": "This plugin restricts the ability to edit users via userSettings to super users only", - "version": "0.2.0", + "name": "SuperUserOnlyRestrictions", + "description": "This plugin restricts some modules/actions to super users only", + "version": "1.0.0", "theme": false, "require": { "piwik": ">=3.13.0-stable,<4.0.0-b1"