From 7cfa1b874462b6dc87205ee490164826d572242c Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Sat, 25 Jan 2025 11:24:05 +0100
Subject: [PATCH] =?UTF-8?q?DSN:=20Na=20=C3=BA=C4=8Dty=20s=20nedosa=C5=BEit?=
 =?UTF-8?q?elnou=20adresou=20nepos=C3=ADl=C3=A1me=20notifikace?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mo/db.py          | 4 ++++
 mo/jobs/notify.py | 2 +-
 mo/web/user.py    | 4 ++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/mo/db.py b/mo/db.py
index 185da8e1..6be1ff0d 100644
--- a/mo/db.py
+++ b/mo/db.py
@@ -467,6 +467,10 @@ class User(Base):
     def is_system(self) -> bool:
         return self.user_id == 0
 
+    @property
+    def wants_notify(self) -> bool:
+        return self.email_notify and self.dsn_id is None
+
 
 def get_system_user() -> User:
     """Uživatel s user_id=0 je systémový (viz db.ddl)"""
diff --git a/mo/jobs/notify.py b/mo/jobs/notify.py
index ea522b7d..50097dea 100644
--- a/mo/jobs/notify.py
+++ b/mo/jobs/notify.py
@@ -70,7 +70,7 @@ def handle_send_grading_info(the_job: TheJob):
 
     for user, sent in todo:
         num_total += 1
-        if not user.email_notify:
+        if not user.wants_notify:
             num_dont_want += 1
         elif sent:
             num_before += 1
diff --git a/mo/web/user.py b/mo/web/user.py
index 17364b2b..d39a61df 100644
--- a/mo/web/user.py
+++ b/mo/web/user.py
@@ -266,8 +266,8 @@ def join_notify(c: db.Contest) -> None:
         notify = {ur.user for ur in uroles if ur.applies_to(at=place, year=r.year, cat=r.category, seq=r.seq)}
         if notify:
             for org in notify:
-                logger.info(f'Join: {"Notifikuji" if org.email_notify else "Nenotifikuji"} orga <{org.email}> pro místo {place.get_code()}')
-                if org.email_notify:
+                logger.info(f'Join: {"Notifikuji" if org.wants_notify else "Nenotifikuji"} orga <{org.email}> pro místo {place.get_code()}')
+                if org.wants_notify:
                     mo.email.send_join_notify_email(org, g.user, c)
             return
         place = place.parent_place
-- 
GitLab