]> git.ipfire.org Git - ipfire.org.git/commitdiff
accounts: Simplify sending messages
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Nov 2024 16:11:44 +0000 (16:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Nov 2024 16:11:44 +0000 (16:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/backend/blog.py
src/backend/campaigns.py
src/backend/wiki.py

index 397f217c2a8c32f40466d98bf397ad60f4802d87..8e1ec53586559fd7bf2ecb26cf60bc4de0f8293c 100644 (file)
@@ -793,8 +793,7 @@ class Account(LDAPObject):
                        VALUES(%s, %s, %s)", self.uid, reset_code, address)
 
                # Send a password reset email
-               self.backend.messages.send_template("auth/messages/password-reset",
-                       priority=100, account=self, reset_code=reset_code)
+               self.send_message("auth/messages/password-reset", priority=100, reset_code=reset_code)
 
        def reset_password(self, reset_code, new_password):
                # Delete the reset token
@@ -1415,6 +1414,14 @@ class Account(LDAPObject):
                set_contents_to_promotional_emails,
        )
 
+       # Messages
+
+       def send_message(self, *args, **kwargs):
+               """
+                       Sends an email
+               """
+               return self.backend.messages.send_template(*args, account=self, **kwargs)
+
        # Bugzilla
 
        async def _disable_on_bugzilla(self, text=None):
index 45621b9eac3a9a0160e7523809da379efe0e279b..bde543e81c6e55ac6a6eb25f589a11763d423bc2 100644 (file)
@@ -400,8 +400,7 @@ class Post(misc.Object):
                with self.db.transaction():
                        # Generate an email for everybody in this group
                        for account in group:
-                               self.backend.messages.send_template("blog/messages/announcement",
-                                       account=account, post=self)
+                               account.send_message("blog/messages/announcement", post=self)
 
                        # Mark this post as announced
                        self.db.execute("UPDATE blog SET announced_at = CURRENT_TIMESTAMP \
index ab305ff43071d138ae35346a42f3dac7f74d68de..cf191b61a94a177fb52180d4aff8157d18b39f1e 100644 (file)
@@ -82,7 +82,7 @@ class CampaignEmail(Object):
 
                # Generate the email
                if self.should_be_sent:
-                       self.backend.messages.send_template(self.template, account=self.account)
+                       account.send_message(self.template)
 
                # Update this email for the next launch
                self._update()
index 56d15cfd5115595172ff8aadd418312af9eb1baa..c90e1989202adac63fdc94e4cd7aaa006c4ff4d9 100644 (file)
@@ -596,8 +596,7 @@ class Page(misc.Object):
                        logging.debug("Sending watcher email to %s" % watcher)
 
                        # Compose message
-                       self.backend.messages.send_template("wiki/messages/page-changed",
-                               account=watcher, page=self, priority=-10)
+                       watcher.send_message("wiki/messages/page-changed", page=self, priority=-10)
 
        def restore(self, author, address, comment=None):
                changes = "Restore to revision from %s" % self.timestamp.isoformat()