Merge pull request #1118 from modoboa/feature/disable_widget_for_admins

Added setting to control widget visibility.
This commit is contained in:
Antoine Nguyen
2017-05-05 13:50:46 +02:00
committed by GitHub
3 changed files with 38 additions and 12 deletions
+8
View File
@@ -225,6 +225,14 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
)
)
hide_features_widget = YesNoField(
label=ugettext_lazy("Hide features widget"),
initial=False,
help_text=ugettext_lazy(
"Hide features widget for resellers and domain administrators"
)
)
notif_sep = SeparatorField(label=ugettext_lazy("Notifications"))
sender_address = lib_fields.UTF8EmailField(
+15
View File
@@ -74,6 +74,20 @@ class DashboardTestCase(ModoTestCase):
response = self.client.get(url)
self.assertContains(response, "djangoproject")
def test_features_visibility(self):
"""Hide or not features widget."""
url = reverse("core:dashboard")
response = self.client.get(url)
self.assertContains(response, "Features looking for sponsoring")
self.client.force_login(self.dadmin)
response = self.client.get(url)
self.assertContains(response, "Features looking for sponsoring")
self.set_global_parameter("hide_features_widget", True)
response = self.client.get(url)
self.assertNotContains(response, "Features looking for sponsoring")
def test_root_dispatch(self):
"""Check root dispatching."""
url = reverse("core:root")
@@ -141,6 +155,7 @@ class SettingsTestCase(ModoTestCase):
"core-ldap_user_dn_template": "",
"core-default_password": "Toto1000",
"limits-deflt_user_quota_limit": "0",
"core-hide_features_widget": "False",
}
def test_get_settings(self):
+15 -12
View File
@@ -52,18 +52,21 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
context["widgets"]["left"].append("core/_latest_news_widget.html")
context.update({"news": entries})
url = "{}{}/api/projects/?featured=true".format(
MODOBOA_WEBSITE_URL, lang)
features = []
try:
response = requests.get(url)
except RequestException:
pass
else:
if response.status_code == 200:
features = response.json()
context["widgets"]["right"].append("core/_current_features.html")
context.update({"features": features})
hide_features_widget = self.request.localconfig.parameters.get_value(
"hide_features_widget")
if self.request.user.is_superuser or not hide_features_widget:
url = "{}{}/api/projects/?featured=true".format(
MODOBOA_WEBSITE_URL, lang)
features = []
try:
response = requests.get(url)
except RequestException:
pass
else:
if response.status_code == 200:
features = response.json()
context["widgets"]["right"].append("core/_current_features.html")
context.update({"features": features})
# Extra widgets
result = signals.extra_admin_dashboard_widgets.send(