summary refs log tree commit diff
path: root/synapse/handlers/account_validity.py
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/handlers/account_validity.py')
-rw-r--r--synapse/handlers/account_validity.py46
1 files changed, 17 insertions, 29 deletions
diff --git a/synapse/handlers/account_validity.py b/synapse/handlers/account_validity.py

index 0c2bcda4d0..5162cc9a58 100644 --- a/synapse/handlers/account_validity.py +++ b/synapse/handlers/account_validity.py
@@ -20,23 +20,16 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from typing import List -from twisted.internet import defer - from synapse.api.errors import StoreError from synapse.logging.context import make_deferred_yieldable from synapse.metrics.background_process_metrics import run_as_background_process from synapse.types import UserID from synapse.util import stringutils -try: - from synapse.push.mailer import load_jinja2_templates -except ImportError: - load_jinja2_templates = None - logger = logging.getLogger(__name__) -class AccountValidityHandler(object): +class AccountValidityHandler: def __init__(self, hs): self.hs = hs self.config = hs.config @@ -51,9 +44,11 @@ class AccountValidityHandler(object): if ( self._account_validity.enabled and self._account_validity.renew_by_email_enabled - and load_jinja2_templates ): # Don't do email-specific configuration if renewal by email is disabled. + self._template_html = self.config.account_validity_template_html + self._template_text = self.config.account_validity_template_text + try: app_name = self.hs.config.email_app_name @@ -69,17 +64,6 @@ class AccountValidityHandler(object): self._raw_from = email.utils.parseaddr(self._from_string)[1] - self._template_html, self._template_text = load_jinja2_templates( - self.config.email_template_dir, - [ - self.config.email_expiry_template_html, - self.config.email_expiry_template_text, - ], - apply_format_ts_filter=True, - apply_mxc_to_http_filter=True, - public_baseurl=self.config.public_baseurl, - ) - # Check the renewal emails to send and send them every 30min. def send_emails(): # run as a background process to make sure that the database transactions @@ -90,12 +74,17 @@ class AccountValidityHandler(object): self.clock.looping_call(send_emails, 30 * 60 * 1000) - # If account_validity is enabled,check every hour to remove expired users from - # the user directory + # Mark users as inactive when they expired. Check once every hour if self._account_validity.enabled: - self.clock.looping_call( - self._mark_expired_users_as_inactive, 60 * 60 * 1000 - ) + + def mark_expired_users_as_inactive(): + # run as a background process to allow async functions to work + return run_as_background_process( + "_mark_expired_users_as_inactive", + self._mark_expired_users_as_inactive, + ) + + self.clock.looping_call(mark_expired_users_as_inactive, 60 * 60 * 1000) async def _send_renewal_emails(self): """Gets the list of users whose account is expiring in the amount of time @@ -286,8 +275,7 @@ class AccountValidityHandler(object): return expiration_ts - @defer.inlineCallbacks - def _mark_expired_users_as_inactive(self): + async def _mark_expired_users_as_inactive(self): """Iterate over active, expired users. Mark them as inactive in order to hide them from the user directory. @@ -295,7 +283,7 @@ class AccountValidityHandler(object): Deferred """ # Get active, expired users - active_expired_users = yield self.store.get_expired_users() + active_expired_users = await self.store.get_expired_users() # Mark each as non-active - yield self.profile_handler.set_active(active_expired_users, False, True) + await self.profile_handler.set_active(active_expired_users, False, True)