Skip to content

Commit

Permalink
Fix missing permissions for custom icons and actions
Browse files Browse the repository at this point in the history
CMK-21974

Change-Id: Ia14ef23e5a564d22376687d2d8178ce87980a8ff
  • Loading branch information
makanakoeln committed Feb 27, 2025
1 parent b261713 commit 7b48ebe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmk/gui/views/icon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from cmk.gui.config import active_config
from cmk.gui.painter.v0 import PainterRegistry
from cmk.gui.permissions import PermissionSectionRegistry
from cmk.gui.permissions import (
declare_dynamic_permissions,
PermissionSectionRegistry,
)

from .base import Icon
from .builtin import (
Expand Down Expand Up @@ -32,6 +36,7 @@
StalenessIcon,
StarsIcon,
)
from .config_icons import declare_icons_and_actions_perm
from .page_ajax_popup_action_menu import ajax_popup_action_menu
from .painter import PainterHostIcons, PainterServiceIcons
from .permission_section import PermissionSectionIconsAndActions
Expand Down Expand Up @@ -72,6 +77,11 @@ def register(
icon_registry.register(CrashdumpsIcon)
icon_registry.register(CheckPeriodIcon)

# also declare permissions for custom icons
declare_dynamic_permissions(
lambda: declare_icons_and_actions_perm(active_config.user_icons_and_actions)
)


__all__ = [
"icon_and_action_registry",
Expand Down
18 changes: 18 additions & 0 deletions cmk/gui/views/icon/config_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# conditions defined in the file COPYING, which is part of this source code package.


from cmk.gui.config import default_authorized_builtin_role_ids
from cmk.gui.i18n import _
from cmk.gui.permissions import declare_permission, permission_registry
from cmk.gui.type_defs import BuiltinIconVisibility, IconSpec

from .base import Icon
Expand All @@ -26,6 +29,8 @@ def update_builtin_icons_from_config(


def config_based_icons(user_icons_and_actions: dict[str, IconSpec]) -> dict[str, Icon]:
declare_icons_and_actions_perm(user_icons_and_actions)

return {
icon_id: type(
"CustomIcon%s" % icon_id.title(),
Expand All @@ -47,3 +52,16 @@ def config_based_icons(user_icons_and_actions: dict[str, IconSpec]) -> dict[str,
)()
for icon_id, icon_cfg in user_icons_and_actions.items()
}


def declare_icons_and_actions_perm(icons: dict[str, IconSpec]) -> None:
for ident, _icon in icons.items():
if (permname := f"icons_and_actions.{ident}") in permission_registry:
continue

declare_permission(
permname,
ident,
_("Allow to see the icon %s in the host and service views") % ident,
default_authorized_builtin_role_ids,
)

0 comments on commit 7b48ebe

Please sign in to comment.