Skip to content

Commit

Permalink
SAASDEV-2188: add banner to UserEffect
Browse files Browse the repository at this point in the history
Change-Id: I31796dd03d45cb91fa536d10fb0088e662894cbd
  • Loading branch information
bleenders committed Dec 3, 2024
1 parent 2176cb8 commit 998951d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cmk/gui/htmllib/top_heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def top_heading(
browser_reload=browser_reload,
)

_may_show_license_banner(writer)

if page_state:
PageStateRenderer().show(page_state)

Expand Down Expand Up @@ -95,6 +97,17 @@ def _may_show_license_expiry(writer: HTMLWriter) -> None:
writer.show_warning(HTML.without_escaping(header_effect.message_html))


def _may_show_license_banner(writer: HTMLWriter) -> None:
if (
header_effect := get_licensing_user_effect(
licensing_settings_link=makeuri_contextless(
_request, [("mode", "licensing")], filename="wato.py"
)
).banner
) and (set(header_effect.roles).intersection(user.role_ids)):
writer.write_html(HTML.without_escaping(header_effect.message_html))


def _make_default_page_state(
writer: HTMLWriter, request: Request, *, browser_reload: float
) -> PageState | None:
Expand Down
1 change: 1 addition & 0 deletions cmk/utils/licensing/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class UserEffect:
header: HeaderNotification | HeaderNotificationSingleLine | None
email: EmailNotification | None
block: ActivationBlock | None
banner: HeaderNotificationSingleLine | None = None


class NotificationHandler(abc.ABC):
Expand Down
41 changes: 41 additions & 0 deletions packages/cmk-frontend/src/themes/facelift/scss/_cse_banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@charset "UTF-8";
// Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
// 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.

/* Styles used to show the banner in CSE */

.cse-banner {
display: flex;
align-items: center;
padding-left: 20px;
color: $font-color-white;

&:not(:last-child) {
padding-right: 20px;
}

&__message {
font-weight: $font-weight-default;
}

&__button {
margin-left: 10px;
padding: 5px 15px;
border-radius: $theme-border-radius;
background-color: $success-dimmed;
line-height: 1.5;
color: $font-color-black !important;
font-weight: $font-weight-bold;
text-decoration: none;
white-space: nowrap;

&:hover {
background-color: mix($black, $success-dimmed, 10%);
}

&:visited {
color: $font-color-black !important;
}
}
}
1 change: 1 addition & 0 deletions packages/cmk-frontend/src/themes/facelift/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
@import "scss/_ntop.scss";
@import "scss/_license_usage.scss";
@import "scss/_robotmk.scss";
@import "scss/_cse_banner.scss";
1 change: 1 addition & 0 deletions packages/cmk-frontend/src/themes/modern-dark/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
@import "../facelift/scss/_ntop.scss";
@import "../facelift/scss/_license_usage.scss";
@import "../facelift/scss/_robotmk.scss";
@import "../facelift/scss/_cse_banner.scss";
2 changes: 1 addition & 1 deletion tests/unit/cmk/gui/views/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ def test_get_inventory_display_hint() -> None:
assert isinstance(hint, dict)


@pytest.mark.usefixtures("suppress_license_expiry_header", "patch_theme")
@pytest.mark.usefixtures("suppress_license_expiry_header", "patch_theme", "suppress_license_banner")
def test_view_page(
logged_in_admin_wsgi_app: WebTestAppForCMK, mock_livestatus: MockLiveStatusConnection
) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/cmk/gui/wato/pages/test_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@pytest.mark.usefixtures("patch_theme")
@pytest.mark.usefixtures("suppress_license_expiry_header")
@pytest.mark.usefixtures("suppress_license_banner")
def test_ajax_call(logged_in_wsgi_app: WebTestAppForCMK) -> None:
ajax_page = "/NO_SITE/check_mk/ajax_popup_move_to_folder.py"
app = logged_in_wsgi_app
Expand All @@ -31,6 +32,7 @@ def test_ajax_call(logged_in_wsgi_app: WebTestAppForCMK) -> None:

@pytest.mark.usefixtures("patch_theme")
@pytest.mark.usefixtures("suppress_license_expiry_header")
@pytest.mark.usefixtures("suppress_license_banner")
def test_ajax_call_2(
wsgi_app: WebTestAppForCMK,
mock_livestatus: MockLiveStatusConnection,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cmk/gui/wsgi/test_wsgi_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_options_disabled(wsgi_app: WebTestAppForCMK) -> None:
wsgi_app.options("/", status=404)


@pytest.mark.usefixtures("suppress_license_expiry_header", "patch_theme")
@pytest.mark.usefixtures("suppress_license_expiry_header", "patch_theme", "suppress_license_banner")
def test_pnp_template(wsgi_app: WebTestAppForCMK) -> None:
# This got removed some time ago and "Not found" pages are 404 now.
resp = wsgi_app.get("/NO_SITE/check_mk/pnp_template.py", status=404)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,11 @@ def fixture_suppress_license_expiry_header(monkeypatch_module: pytest.MonkeyPatc
monkeypatch_module.setattr(
"cmk.gui.htmllib.top_heading._may_show_license_expiry", lambda x: None
)


@pytest.fixture(name="suppress_license_banner")
def fixture_suppress_license_banner(monkeypatch_module: pytest.MonkeyPatch) -> None:
"""Don't check if message about license expiration should be shown"""
monkeypatch_module.setattr(
"cmk.gui.htmllib.top_heading._may_show_license_banner", lambda x: None
)

0 comments on commit 998951d

Please sign in to comment.