summary refs log tree commit diff
path: root/synapse/handlers/account_validity.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-12-31 13:40:07 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-12-31 13:40:07 +0000
commit47c25048c551570c97fa71db60c41d3dffa23773 (patch)
tree0ab55796a669536f110b3d2ee022ae73c3f2c13f /synapse/handlers/account_validity.py
parentMerge commit 'fedfdfd75' into anoa/dinsic_release_1_23_1 (diff)
parentMerge branch 'master' into develop (diff)
downloadsynapse-47c25048c551570c97fa71db60c41d3dffa23773.tar.xz
Merge commit '24229fac0' into anoa/dinsic_release_1_23_1
Diffstat (limited to 'synapse/handlers/account_validity.py')
-rw-r--r--synapse/handlers/account_validity.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/synapse/handlers/account_validity.py b/synapse/handlers/account_validity.py

index 6f987a4c5a..2ed6d7d248 100644 --- a/synapse/handlers/account_validity.py +++ b/synapse/handlers/account_validity.py
@@ -18,9 +18,9 @@ import email.utils import logging from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText -from typing import List, Optional, Tuple +from typing import TYPE_CHECKING, List, Optional, Tuple -from synapse.api.errors import StoreError +from synapse.api.errors import StoreError, SynapseError from synapse.logging.context import make_deferred_yieldable from synapse.metrics.background_process_metrics import ( run_as_background_process, @@ -29,11 +29,14 @@ from synapse.metrics.background_process_metrics import ( from synapse.types import UserID from synapse.util import stringutils +if TYPE_CHECKING: + from synapse.app.homeserver import HomeServer + logger = logging.getLogger(__name__) class AccountValidityHandler: - def __init__(self, hs): + def __init__(self, hs: "HomeServer"): self.hs = hs self.config = hs.config self.store = self.hs.get_datastore() @@ -92,7 +95,7 @@ class AccountValidityHandler: self.clock.looping_call(mark_expired_users_as_inactive, 60 * 60 * 1000) @wrap_as_background_process("send_renewals") - async def _send_renewal_emails(self): + async def _send_renewal_emails(self) -> None: """Gets the list of users whose account is expiring in the amount of time configured in the ``renew_at`` parameter from the ``account_validity`` configuration, and sends renewal emails to all of these users as long as they @@ -106,11 +109,25 @@ class AccountValidityHandler: user_id=user["user_id"], expiration_ts=user["expiration_ts_ms"] ) - async def send_renewal_email_to_user(self, user_id: str): + async def send_renewal_email_to_user(self, user_id: str) -> None: + """ + Send a renewal email for a specific user. + + Args: + user_id: The user ID to send a renewal email for. + + Raises: + SynapseError if the user is not set to renew. + """ expiration_ts = await self.store.get_expiration_ts_for_user(user_id) + + # If this user isn't set to be expired, raise an error. + if expiration_ts is None: + raise SynapseError(400, "User has no expiration time: %s" % (user_id,)) + await self._send_renewal_email(user_id, expiration_ts) - async def _send_renewal_email(self, user_id: str, expiration_ts: int): + async def _send_renewal_email(self, user_id: str, expiration_ts: int) -> None: """Sends out a renewal email to every email address attached to the given user with a unique link allowing them to renew their account.