Module: check_mk
Branch: master
Commit: 82bb40508ab6fe850eb12a0ebf03b8a3bed7e9fd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=82bb40508ab6fe…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Mar 5 16:54:26 2018 +0100
5785 FIX User notification rules: Now also checks if the user is restricted to authorized
sites
If a user gets a restriction to authorized sites, it will also restrict the notifications
to these sites.
Previously, if no </i>Match site</i> filter was set as specific condition, the
user rule matched on all sites.
So, with this change a user notification rule is only checked on the users authorized
sites.
Change-Id: I52065e4119075a70a91a9d68ee78dfd5df3ddce4
---
.werks/5785 | 17 +++++++++++++++++
cmk_base/notify.py | 4 ++++
web/htdocs/config.py | 12 ++++++++++++
web/htdocs/valuespec.py | 13 ++++++-------
web/htdocs/wato.py | 3 ++-
5 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/.werks/5785 b/.werks/5785
new file mode 100644
index 0000000..de47572
--- /dev/null
+++ b/.werks/5785
@@ -0,0 +1,17 @@
+Title: User notification rules: Now also checks if the user is restricted to authorized
sites
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1520264909
+Class: fix
+
+If a user gets a restriction to authorized sites, it will also restrict the notifications
to these sites.
+Previously, if no </i>Match site</i> filter was set as specific condition,
the user rule matched on all sites.
+
+
+With this change a user notification rule is only checked on the users authorized sites.
+
+
+Furthermore, a user can no longer select foreign (non-authorized) sites in the
<i>Match site</i> dropdown field.
diff --git a/cmk_base/notify.py b/cmk_base/notify.py
index 4ecffbe..cf1e6f4 100644
--- a/cmk_base/notify.py
+++ b/cmk_base/notify.py
@@ -606,6 +606,10 @@ def user_notification_rules():
# is handled by WATO. Contact specific rules are a
# WATO-only feature anyway...
user_rules.append(rule)
+
+ if "authorized_sites" in config.contacts[contactname] and not
"match_site" in rule:
+ rule["match_site"] =
config.contacts[contactname]["authorized_sites"]
+
notify_log_debug("Found %d user specific rules" % len(user_rules))
return user_rules
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 86f63e2..cdb288d 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -812,6 +812,18 @@ def is_single_local_site():
return site_is_local(sitename)
+def site_attribute_default_value():
+ default_site = default_site()
+ authorized_site_ids = map(lambda x: x[0],
user.authorized_sites(unfiltered_sites=configured_sites()))
+ if default_site and default_site in authorized_site_ids:
+ return default_site
+
+
+def site_attribute_choices():
+ authorized_site_ids = map(lambda x: x[0],
user.authorized_sites(unfiltered_sites=configured_sites()))
+ return site_choices(filter_func=lambda site_id, site: site_id in
authorized_site_ids)
+
+
def site_choices(filter_func=None):
choices = []
for site_id, site in sites.items():
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 6472fd7..ad46ae1 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -4608,18 +4608,17 @@ class SiteChoice(DropdownChoice):
return False
import config
- default_site = config.default_site()
- authorized_site_ids = map(lambda x: x[0],
config.user.authorized_sites(unfiltered_sites=config.configured_sites()))
- if default_site and default_site in authorized_site_ids:
- return default_site
- return self.canonical_value()
+ default_value = config.site_attribute_default_value()
+ if default_value:
+ return default_value
+ else:
+ return self.canonical_value()
def _site_choices(self):
import config
- authorized_site_ids = map(lambda x: x[0],
config.user.authorized_sites(unfiltered_sites=config.configured_sites()))
- return config.site_choices(filter_func=lambda site_id, site: site_id in
authorized_site_ids)
+ return config.site_attribute_choices()
class TimeperiodSelection(DropdownChoice):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 6c752fd..9b279f3 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7972,6 +7972,7 @@ def vs_notification_rule(userid = None):
validate = validate_notification_rule,
)
+
def simple_host_rule_match_conditions():
return [
( "match_site",
@@ -7979,7 +7980,7 @@ def simple_host_rule_match_conditions():
title = _("Match site"),
help = _("This condition makes the rule match only notifications that
have been "
"created on the selected sites."),
- choices = config.site_choices,
+ choices = config.site_attribute_choices,
),
),
( "match_folder",