From fadc375c510693a87a2e1acb090605bbeed52fe4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 14 Feb 2018 14:15:05 +0100 Subject: Global: Only show "Warning" badge at the top if user can view event log, also hide warnings on the main page from modules the user has no access to --- inc/dashboard.inc.php | 2 +- inc/permission.inc.php | 9 ++++++++- modules-available/main/page.inc.php | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/inc/dashboard.inc.php b/inc/dashboard.inc.php index 3db42efb..59d81c2d 100644 --- a/inc/dashboard.inc.php +++ b/inc/dashboard.inc.php @@ -68,7 +68,7 @@ class Dashboard 'url' => urlencode($_SERVER['REQUEST_URI']), 'langs' => Dictionary::getLanguages(true), 'user' => User::getName(), - 'warning' => User::getName() !== false && User::getLastSeenEvent() < Property::getLastWarningId(), + 'warning' => User::getName() !== false && User::hasPermission('.eventlog.*') && User::getLastSeenEvent() < Property::getLastWarningId(), 'needsSetup' => User::getName() !== false && Property::getNeedsSetup() )); } diff --git a/inc/permission.inc.php b/inc/permission.inc.php index cd41e986..d6977e32 100644 --- a/inc/permission.inc.php +++ b/inc/permission.inc.php @@ -19,7 +19,7 @@ class Permission // TODO: Doc/Refactor public static function addGlobalTags(&$array, $locationid, $disabled, $noneAvailDisabled = null) { - if (!Module::isAvailable('permissionmanager')) + if (Module::get('permissionmanager') === false) return; $one = false; foreach ($disabled as $perm) { @@ -44,5 +44,12 @@ class Permission } } + public static function moduleHasPermissions($moduleId) + { + if (Module::get('permissionmanager') === false) + return true; + return file_exists('modules/' . $moduleId . '/permissions/permissions.json'); + } + } diff --git a/modules-available/main/page.inc.php b/modules-available/main/page.inc.php index 70296a59..baea8350 100644 --- a/modules-available/main/page.inc.php +++ b/modules-available/main/page.inc.php @@ -26,7 +26,10 @@ class Page_Main extends Page // Warnings $needSetup = false; foreach (Hook::load('main-warning') as $hook) { - include $hook->file; + if (Permission::moduleHasPermissions($hook->moduleId) + && User::hasPermission('.' . $hook->moduleId . '.*')) { + include $hook->file; + } } // Update warning state -- cgit v1.2.3-55-g7522