Module: check_mk
Branch: master
Commit: 018961ddfb14ef8375905a8c8a176b012deb8884
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=018961ddfb14ef…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Nov 2 14:05:37 2017 +0100
5238 FIX WATO users now only see their configured sites in the Site-DropdownChoice
A user can be configured only to see/configure a subset of the available sites.
The site dropdown choice, however, always showed all available sites. This has been
fixed.
Change-Id: I79c45746211df5c911b96604680631d8de342306
---
.werks/5238 | 12 ++++++++++++
web/htdocs/valuespec.py | 29 ++++++++++++++++++++++++-----
web/plugins/wato/builtin_attributes.py | 1 -
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/.werks/5238 b/.werks/5238
new file mode 100644
index 0000000..43661bb
--- /dev/null
+++ b/.werks/5238
@@ -0,0 +1,12 @@
+Title: WATO users now only see their configured sites in the Site-DropdownChoice
+Level: 1
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1509627717
+Class: fix
+
+A user can be configured only to see/configure a subset of the available sites.
+The site dropdown choice, however, always showed all available sites. This has been
fixed.
+
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index b29f9df..ee74dea 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -34,7 +34,7 @@
# -> rename to Boolean
# -> Add alternative rendering "dropdown"
-import math, os, time, re, sre_constants, urlparse, forms, tempfile
+import math, os, time, re, sre_constants, urlparse, forms, tempfile, types
import base64
import hashlib
import socket
@@ -99,7 +99,7 @@ class ValueSpec(object):
# for same cases where the default value is known.
def default_value(self):
try:
- if type(self._default_value) == type(lambda:True):
+ if type(self._default_value) in [types.FunctionType, types.MethodType]:
return self._default_value()
else:
return self._default_value
@@ -4583,14 +4583,13 @@ def ListOfCAs(**args):
class SiteChoice(DropdownChoice):
def __init__(self, **kwargs):
- import config
kwargs.setdefault("title", _("Site"))
kwargs.setdefault("help", _("Specify the site of your
choice"))
- kwargs.setdefault("default_value", config.default_site())
+ kwargs.setdefault("default_value", self._site_default_value)
kwargs.setdefault("invalid_choice_error", _("The configured site
is not known to this site."))
kwargs.update({
- "choices": config.site_choices,
+ "choices": self._site_choices,
"invalid_choice": "complain",
"invalid_choice_title": _("Unknown site (%s)"),
})
@@ -4598,6 +4597,26 @@ class SiteChoice(DropdownChoice):
super(SiteChoice, self).__init__(**kwargs)
+ def _site_default_value(self):
+ import watolib
+ if watolib.is_wato_slave_site():
+ 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
+ raise
+
+
+ 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)
+
+
+
class TimeperiodSelection(ElementSelection):
def __init__(self, **kwargs):
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index 03d91a5..adf2eeb 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -490,7 +490,6 @@ class SiteAttribute(ValueSpecAttribute):
ValueSpecAttribute.__init__(self, "site", SiteChoice(
title=_("Monitored on site"),
help=_("Specify the site that should monitor this host."),
- default_value = default_site,
invalid_choice_error = _("The configured site is not known to this site.
In case you "
"are configuring in a distributed slave, this
may be a host "
"monitored by another site. If you want to
modify this "