From cefa2cb63a00df6d1c293ce9f48c11084dccdf20 Mon Sep 17 00:00:00 2001 From: "Ph. SW." Date: Sat, 7 Sep 2024 19:50:38 +0200 Subject: [PATCH] Ajoute des statistiques Munin concernant les membres (#6639) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - le nombre de membres bannis - le nombre de membres qui ont l'attribut `is_active=True` - le nombre de membres qui se sont connectés au moins une fois --- django_munin/munin/views.py | 11 +++++++++-- zds/munin/tests.py | 16 ++++++++++++++++ zds/munin/urls.py | 11 ++++++++++- zds/munin/views.py | 11 +++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/django_munin/munin/views.py b/django_munin/munin/views.py index e92895db08..5dc5332a52 100644 --- a/django_munin/munin/views.py +++ b/django_munin/munin/views.py @@ -4,6 +4,7 @@ from django.conf import settings from django.contrib.auth import get_user_model +from django.db.models import Q from .helpers import muninview from .models import Test @@ -14,10 +15,16 @@ @muninview( config="""graph_title Total Users -graph_vlabel users""" +graph_vlabel users +graph_args --lower-limit 0 +graph_scale no""" ) def total_users(request): - return [("users", User.objects.all().count())] + return [ + ("users", User.objects.all().count()), + ("confirmed_users", User.objects.filter(is_active=True).count()), + ("logged_once_users", User.objects.filter(~Q(last_login=None)).count()), + ] @muninview( diff --git a/zds/munin/tests.py b/zds/munin/tests.py index 8c73a2f2ec..c3324b6e69 100644 --- a/zds/munin/tests.py +++ b/zds/munin/tests.py @@ -12,6 +12,7 @@ def setUp(self): "base:total-sessions", "base:active-sessions", "base:db-performance", + "banned-users", "total-topics", "total-posts", "total-mp", @@ -44,3 +45,18 @@ def test_sessions(self): response = self.client.get(reverse("munin:base:total-sessions")) self.assertEqual(response.content.decode(), "sessions 1") + + def test_banned_users(self): + response = self.client.get(reverse("munin:banned-users")) + self.assertEqual(response.content.decode(), "banned_users 0") + + profile = ProfileFactory() + + response = self.client.get(reverse("munin:banned-users")) + self.assertEqual(response.content.decode(), "banned_users 0") + + profile.can_read = False + profile.save() + + response = self.client.get(reverse("munin:banned-users")) + self.assertEqual(response.content.decode(), "banned_users 1") diff --git a/zds/munin/urls.py b/zds/munin/urls.py index ea54720cee..8e1b542087 100644 --- a/zds/munin/urls.py +++ b/zds/munin/urls.py @@ -1,10 +1,19 @@ from django.urls import path, include -from zds.munin.views import total_topics, total_posts, total_mps, total_tutorials, total_articles, total_opinions +from zds.munin.views import ( + banned_users, + total_topics, + total_posts, + total_mps, + total_tutorials, + total_articles, + total_opinions, +) urlpatterns = [ path("", include(("django_munin.munin.urls", "base"))), + path("banned_users/", banned_users, name="banned-users"), path("total_topics/", total_topics, name="total-topics"), path("total_posts/", total_posts, name="total-posts"), path("total_mps/", total_mps, name="total-mp"), diff --git a/zds/munin/views.py b/zds/munin/views.py index 49ebf1568c..9c2bd03a66 100644 --- a/zds/munin/views.py +++ b/zds/munin/views.py @@ -1,9 +1,20 @@ from django_munin.munin.helpers import muninview from zds.forum.models import Topic, Post +from zds.member.models import Profile from zds.mp.models import PrivateTopic, PrivatePost from zds.tutorialv2.models.database import PublishableContent, ContentReaction +@muninview( + config="""graph_title Banned Users +graph_vlabel Banned Users +graph_args --lower-limit 0 +graph_scale no""" +) +def banned_users(request): + return [("banned_users", Profile.objects.filter(can_read=False, end_ban_read=None).count())] + + @muninview( config="""graph_title Total Topics graph_vlabel topics"""