Skip to content

Commit

Permalink
Adding new setting allowing to disable Geolocation tab for super users
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Jan 7, 2014
1 parent 70f689a commit 7cf62c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@
; the access to disk and install custom PHP code (Piwik plugins).
enable_marketplace = 1

; By setting this option to 0, you can prevent Super User from editing the Geolocation settings.
enable_geolocation_admin = 1

; If php is running in a chroot environment, when trying to import CSV files with createTableFromCSVFile(),
; Mysql will try to load the chrooted path (which is imcomplete). To prevent an error, here you can specify the
; absolute path to the chroot environment. eg. '/path/to/piwik/chrooted/'
Expand Down
15 changes: 13 additions & 2 deletions plugins/UserCountry/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function index()

public function adminIndex()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserIsSuperUser();
$view = new View('@UserCountry/adminIndex');

$allProviderInfo = LocationProvider::getAllProviderInfo(
$newline = '<br/>', $includeExtra = true);
$allProviderInfo = LocationProvider::getAllProviderInfo($newline = '<br/>', $includeExtra = true);
$view->locationProviders = $allProviderInfo;
$view->currentProviderId = LocationProvider::getCurrentProviderId();
$view->thisIP = IP::getIpFromHeader();
Expand Down Expand Up @@ -108,6 +108,7 @@ public function adminIndex()
*/
public function downloadFreeGeoIPDB()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserIsSuperUser();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Expand Down Expand Up @@ -191,6 +192,7 @@ private function setUpdaterManageVars($view)
*/
public function updateGeoIPLinks()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserIsSuperUser();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
Json::sendHeaderJSON();
Expand Down Expand Up @@ -232,6 +234,7 @@ public function updateGeoIPLinks()
*/
public function downloadMissingGeoIpDb()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserIsSuperUser();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
Expand Down Expand Up @@ -284,6 +287,7 @@ public function downloadMissingGeoIpDb()
*/
public function setCurrentLocationProvider()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserIsSuperUser();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Expand Down Expand Up @@ -387,4 +391,11 @@ private function getNextMissingDbUrlInfo()
}
return false;
}

private function dieIfGeolocationAdminIsDisabled()
{
if(!UserCountry::isGeoLocationAdminEnabled()) {
throw new \Exception('Geo location setting page has been disabled.');
}
}
}
16 changes: 12 additions & 4 deletions plugins/UserCountry/UserCountry.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ public function addMenu()
*/
public function addAdminMenu()
{
MenuAdmin::getInstance()->add('General_Settings', 'UserCountry_Geolocation',
array('module' => 'UserCountry', 'action' => 'adminIndex'),
Piwik::isUserIsSuperUser(),
$order = 8);
if($this->isGeoLocationAdminEnabled()) {
MenuAdmin::getInstance()->add('General_Settings', 'UserCountry_Geolocation',
array('module' => 'UserCountry', 'action' => 'adminIndex'),
Piwik::isUserIsSuperUser(),
$order = 8);
}
}

public function getSegmentsMetadata(&$segments)
Expand Down Expand Up @@ -480,4 +482,10 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = "UserCountry_SetupAutomaticUpdatesOfGeoIP";
$translationKeys[] = "General_Done";
}

public static function isGeoLocationAdminEnabled()
{
return (bool) Config::getInstance()->General['enable_geolocation_admin'];
}

}

0 comments on commit 7cf62c4

Please sign in to comment.