From 628842424426acfd5ed972063e53245cc90399dc Mon Sep 17 00:00:00 2001
From: Lloyd Meins <git@lloydmeins.de>
Date: Fri, 4 Jun 2021 13:44:21 +0200
Subject: [PATCH] Add preferences to disable dashboard auto updating (per
 site/person)

---
 CHANGELOG.rst                          |  5 +++++
 aleksis/core/preferences.py            | 20 ++++++++++++++++++++
 aleksis/core/templates/core/index.html |  4 +++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 4e8a1db16..d6294abcf 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning`_.
 `2.0b2` - 2021-06-15
 --------------------
 
+Added
+~~~~~~~
+
+* Add option to disable dashboard auto updating as a user and sitewide.
+
 Changed
 ~~~~~~~
 
diff --git a/aleksis/core/preferences.py b/aleksis/core/preferences.py
index 2dc131ead..588992f60 100644
--- a/aleksis/core/preferences.py
+++ b/aleksis/core/preferences.py
@@ -386,3 +386,23 @@ class PDFFileExpirationDuration(IntegerPreference):
     default = 3
     verbose_name = _("PDF file expiration duration")
     help_text = _("in minutes")
+
+
+@person_preferences_registry.register
+class AutoUpdatingDashboard(BooleanPreference):
+    """User preference for automatically updating the dashboard."""
+
+    section = general
+    name = "automatically_update_dashboard"
+    default = True
+    verbose_name = _("Automatically update the dashboard and its widgets")
+
+
+@site_preferences_registry.register
+class AutoUpdatingDashboardSite(BooleanPreference):
+    """Automatic updating of dashboard."""
+
+    section = general
+    name = "automatically_update_dashboard_site"
+    default = True
+    verbose_name = _("Automatically update the dashboard and its widgets sitewide")
diff --git a/aleksis/core/templates/core/index.html b/aleksis/core/templates/core/index.html
index b2c1f3f5f..cfc5d7214 100644
--- a/aleksis/core/templates/core/index.html
+++ b/aleksis/core/templates/core/index.html
@@ -108,5 +108,7 @@
     </div>
   {% endif %}
 
-  <script type="text/javascript" src="{% static "js/include_ajax_live.js" %}"></script>
+  {% if user.person.preferences.general__automatically_update_dashboard and request.site.preferences.general__automatically_update_dashboard_site %}
+    <script type="text/javascript" src="{% static "js/include_ajax_live.js" %}"></script>
+  {% endif %}
 {% endblock %}
-- 
GitLab