Module: check_mk
Branch: master
Commit: b9e7d24128f4a653a67fa7c698165c92750fb9de
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b9e7d24128f4a6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 9 13:57:01 2019 +0100
7025 Icons & actions visibility can now be controlled by user permissions
The visibility of the standard and custom icons & actions can now be controlled
by user permissions. By default the users of all roles may see all icons & actions.
Each icon can be hidden for a role by disabling the permission to see an icon.
CMK-995
Change-Id: Ic0c24167b42a280e462ddb089d7c75055919cc13
---
.werks/7025 | 12 ++++++++++++
cmk/gui/permissions.py | 1 +
cmk/gui/plugins/views/icons/__init__.py | 3 +++
cmk/gui/plugins/views/icons/utils.py | 28 ++++++++++++++++++++++++++-
tests/unit/cmk/gui/test_gui_config.py | 34 +++++++++++++++++++++++++++++++++
5 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/.werks/7025 b/.werks/7025
new file mode 100644
index 0000000..7fd914e
--- /dev/null
+++ b/.werks/7025
@@ -0,0 +1,12 @@
+Title: Icons & actions visibility can now be controlled by user permissions
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1547038453
+Class: feature
+
+The visibility of the standard and custom icons & actions can now be controlled
+by user permissions. By default the users of all roles may see all icons & actions.
+Each icon can be hidden for a role by disabling the permission to see an icon.
diff --git a/cmk/gui/permissions.py b/cmk/gui/permissions.py
index 0601438..1f7db41 100644
--- a/cmk/gui/permissions.py
+++ b/cmk/gui/permissions.py
@@ -164,6 +164,7 @@ def declare_permission_section(name, title, prio=50, do_sort=False):
# Kept for compatibility with pre 1.6 GUI plugins
+# Some dynamically registered permissions still use this
def declare_permission(name, title, description, defaults):
if isinstance(name, unicode):
name = name.encode("utf-8")
diff --git a/cmk/gui/plugins/views/icons/__init__.py
b/cmk/gui/plugins/views/icons/__init__.py
index 9f470bf..d2d1f86 100644
--- a/cmk/gui/plugins/views/icons/__init__.py
+++ b/cmk/gui/plugins/views/icons/__init__.py
@@ -105,6 +105,9 @@ def _process_icons(what, row, tags, custom_vars, toplevel,
user_icon_ids):
if icon.type() == "custom_icon" and icon_id not in user_icon_ids:
continue
+ if not config.user.may("icons_and_actions.%s" % icon_id):
+ continue
+
try:
for icon in _process_icon(what, row, tags, custom_vars, icon_id, icon):
icons.append(icon)
diff --git a/cmk/gui/plugins/views/icons/utils.py b/cmk/gui/plugins/views/icons/utils.py
index 34b5f6e..764a0f8 100644
--- a/cmk/gui/plugins/views/icons/utils.py
+++ b/cmk/gui/plugins/views/icons/utils.py
@@ -28,7 +28,28 @@ import abc
from typing import Union, Optional, Tuple # pylint: disable=unused-import
import cmk.gui.config as config
+from cmk.gui.i18n import _
import cmk.utils.plugin_registry
+from cmk.gui.permissions import (
+ permission_section_registry,
+ PermissionSection,
+ declare_permission,
+)
+
+
+(a)permission_section_registry.register
+class PermissionSectionIconsAndActions(PermissionSection):
+ @property
+ def name(self):
+ return "icons_and_actions"
+
+ @property
+ def title(self):
+ return _("Icons")
+
+ @property
+ def do_sort(self):
+ return True
class Icon(object):
@@ -111,7 +132,12 @@ class IconRegistry(cmk.utils.plugin_registry.ClassRegistry):
return Icon
def _register(self, plugin_class):
- self._entries[plugin_class.ident()] = plugin_class
+ ident = plugin_class.ident()
+ self._entries[ident] = plugin_class
+
+ declare_permission("icons_and_actions.%s" % ident, ident,
+ _("Allow to see the icon %s in the host and service
views") % ident,
+ config.builtin_role_ids)
icon_and_action_registry = IconRegistry()
diff --git a/tests/unit/cmk/gui/test_gui_config.py
b/tests/unit/cmk/gui/test_gui_config.py
index 4c560a6..121b0ab 100644
--- a/tests/unit/cmk/gui/test_gui_config.py
+++ b/tests/unit/cmk/gui/test_gui_config.py
@@ -38,6 +38,7 @@ def test_registered_permission_sections():
('report', (50, u'Reports', True)),
('nagvis', (50, u'NagVis', False)),
('view', (50, u'Views', True)),
+ ('icons_and_actions', (50, u'Icons', True)),
]
section_names = permission_section_registry.keys()
@@ -162,6 +163,39 @@ def test_registered_permissions():
'general.use',
'general.view_option_columns',
'general.view_option_refresh',
+ 'icons_and_actions.action_menu',
+ 'icons_and_actions.agent_deployment',
+ 'icons_and_actions.aggregation_checks',
+ 'icons_and_actions.aggregations',
+ 'icons_and_actions.check_manpage',
+ 'icons_and_actions.check_period',
+ 'icons_and_actions.crashed_check',
+ 'icons_and_actions.custom_action',
+ 'icons_and_actions.deployment_status',
+ 'icons_and_actions.download_agent_output',
+ 'icons_and_actions.download_snmp_walk',
+ 'icons_and_actions.icon_image',
+ 'icons_and_actions.inventory',
+ 'icons_and_actions.logwatch',
+ 'icons_and_actions.mkeventd',
+ 'icons_and_actions.notes',
+ 'icons_and_actions.perfgraph',
+ 'icons_and_actions.prediction',
+ 'icons_and_actions.reschedule',
+ 'icons_and_actions.rule_editor',
+ 'icons_and_actions.stars',
+ 'icons_and_actions.status_acknowledged',
+ 'icons_and_actions.status_active_checks',
+ 'icons_and_actions.status_comments',
+ 'icons_and_actions.status_downtimes',
+ 'icons_and_actions.status_flapping',
+ 'icons_and_actions.status_notification_period',
+ 'icons_and_actions.status_notifications_enabled',
+ 'icons_and_actions.status_passive_checks',
+ 'icons_and_actions.status_service_period',
+ 'icons_and_actions.status_shadow',
+ 'icons_and_actions.status_stale',
+ 'icons_and_actions.wato',
'mkeventd.actions',
'mkeventd.activate',
'mkeventd.archive_events_of_hosts',