From 3aaa17ee15cd581dd61c3d43cdab5a48f66004b2 Mon Sep 17 00:00:00 2001 From: Lukas Schauer <lukas@schauer.so> Date: Wed, 29 Apr 2020 23:28:30 +0200 Subject: [PATCH] only send admin notifications to selected admins --- fhuser/migrations/0002_user_admin_mails.py | 18 ++++++++++++++++++ fhuser/models.py | 1 + fhuser/views.py | 2 ++ jitsimod/views.py | 2 +- videos/views.py | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 fhuser/migrations/0002_user_admin_mails.py diff --git a/fhuser/migrations/0002_user_admin_mails.py b/fhuser/migrations/0002_user_admin_mails.py new file mode 100644 index 0000000..f62eb58 --- /dev/null +++ b/fhuser/migrations/0002_user_admin_mails.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-29 21:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fhuser', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='admin_mails', + field=models.BooleanField(default=False), + ), + ] diff --git a/fhuser/models.py b/fhuser/models.py index 1571e7a..166492b 100755 --- a/fhuser/models.py +++ b/fhuser/models.py @@ -16,3 +16,4 @@ def random_key_30(): class User(AbstractUser): is_activated = models.BooleanField(default=True, null=False, blank=True) activation_code = models.CharField(max_length=30, default=random_key_30, null=False, blank=True) + admin_mails = models.BooleanField(default=False) diff --git a/fhuser/views.py b/fhuser/views.py index 5747353..2fc6c73 100755 --- a/fhuser/views.py +++ b/fhuser/views.py @@ -27,6 +27,8 @@ def activate_view(request, activation_code): login(request, user, backend='django.contrib.auth.backends.ModelBackend') for admin in get_user_model().objects.filter(is_superuser=True, is_active=True): + if not admin.admin_mails: + continue msg = "Hello %s,\n\na new account has been activated:\n\nUser: %s\nE-Mail: %s" % (admin.first_name, user.username, user.email) email = EmailMessage('lectures.fslab.de – Admin – Account activated', msg, to=[admin.email]) try: diff --git a/jitsimod/views.py b/jitsimod/views.py index efc095b..db22560 100644 --- a/jitsimod/views.py +++ b/jitsimod/views.py @@ -35,7 +35,7 @@ def newroom(request): room.save() for admin in get_user_model().objects.filter(is_superuser=True, is_active=True): - if admin.username != "lschau2s": + if not admin.admin_mails: continue subject = 'created (pattern-approved)' if autoapproved else 'requested' msg = "Hello %s,\n\na new Jitsi room has been %s:\nhttps://lectures.fslab.de/admin/jitsimod/pattern/%d/change/\nName: %s\nUser: %s\nReason:\n%s" % (admin.first_name, subject, room.id, room.name, request.user.username, room.reason) diff --git a/videos/views.py b/videos/views.py index c904c85..1bd49fd 100755 --- a/videos/views.py +++ b/videos/views.py @@ -65,6 +65,8 @@ def newcourse(request): course.save() for admin in get_user_model().objects.filter(is_superuser=True, is_active=True): + if not admin.admin_mails: + continue msg = "Hello %s,\n\na new course has been created:\nhttps://lectures.fslab.de/course/%d\nOwner: %s\nTitle: %s\nDescription:\n%s" % (admin.first_name, course.id, request.user.username, course.title, course.description) email = EmailMessage('lectures.fslab.de – Admin – Course creation', msg, to=[admin.email]) try: -- GitLab