Skip to content

Commit

Permalink
16202 Mega menu: Hide "Customize" menu and menu items for users with …
Browse files Browse the repository at this point in the history
…no permission

This change hides "Customize" menu and its menu items depending on user
permissions. Permissions taken in account are:
* general.edit_pagetype_topic
* general.edit_bookmark_list
* general.edit_custom_snapin

* general.edit_views
* general.edit_dashboards

* general.edit_graph_collection
* general.edit_graph_tuning
* general.edit_custom_graph
* general.edit_forecast_graph

* general.edit_reports
* general.edit_sla_configuration

CMK-12087

Change-Id: I6506af73bd01b0e5078b941297f67fa411137b26
  • Loading branch information
lpetrora committed Oct 25, 2023
1 parent 7f11a98 commit 29960c9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 27 deletions.
13 changes: 13 additions & 0 deletions .werks/16202
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Title: Mega menu: Hide "Customize" menu and menu items for users with no permission
Class: feature
Compatible: compat
Component: wato
Date: 1698216784
Edition: cre
Level: 1
Version: 2.3.0b1

Before this Werk, users without permissions to access the "Customize" menu could still see it in the mega menu,
and then when accessing it they would get an error message. This Werk fixes that behaviour by hiding the menu
entries to which the user does not have access, or the entire menu in case the user does not have any
customisation permissions.
86 changes: 59 additions & 27 deletions cmk/gui/pagetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2309,37 +2309,50 @@ def _no_bi_aggregate_active() -> bool:

def _customize_menu_topics() -> list[TopicMenuTopic]:
general_items = []
monitoring_items = [
TopicMenuItem(
name="views",
title=_("Views"),
url="edit_views.py",
sort_index=10,
is_show_more=False,
icon="view",
),
TopicMenuItem(
name="dashboards",
title=_("Dashboards"),
url="edit_dashboards.py",
sort_index=20,
is_show_more=False,
icon="dashboard",
),
]
monitoring_items = []
graph_items = []
business_reporting_items = [
TopicMenuItem(
name="reports",
title=_("Reports"),
url="edit_reports.py",
sort_index=10,
is_show_more=True,
icon="report",
business_reporting_items = []

if user.may("general.edit_views"):
monitoring_items.append(
TopicMenuItem(
name="views",
title=_("Views"),
url="edit_views.py",
sort_index=10,
is_show_more=False,
icon="view",
),
)

if user.may("general.edit_dashboards"):
monitoring_items.append(
TopicMenuItem(
name="dashboards",
title=_("Dashboards"),
url="edit_dashboards.py",
sort_index=20,
is_show_more=False,
icon="dashboard",
),
)

if user.may("general.edit_reports"):
business_reporting_items.append(
TopicMenuItem(
name="reports",
title=_("Reports"),
url="edit_reports.py",
sort_index=10,
is_show_more=True,
icon="report",
)
)
]

for index, page_type_ in enumerate(all_page_types().values()):
if not user.may(f"general.edit_{page_type_.type_name()}"):
continue

item = TopicMenuItem(
name=page_type_.type_name(),
title=page_type_.phrase("title_plural"),
Expand Down Expand Up @@ -2392,13 +2405,32 @@ def _customize_menu_topics() -> list[TopicMenuTopic]:
return topics


def hide_customize_menu() -> bool:
permissions = [
"general.edit_pagetype_topic",
"general.edit_bookmark_list",
"general.edit_custom_snapin",
"general.edit_graph_collection",
"general.edit_graph_tuning",
"general.edit_custom_graph",
"general.edit_forecast_graph",
"general.edit_sla_configuration",
"general.edit_views",
"general.edit_dashboards",
"general.edit_reports",
]

return not any(user.may(perm) for perm in permissions)


mega_menu_registry.register(
MegaMenu(
name="customize",
title=_l("Customize"),
icon="main_customize",
sort_index=10,
topics=_customize_menu_topics,
hide=hide_customize_menu,
)
)

Expand Down

0 comments on commit 29960c9

Please sign in to comment.