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.py42
1 files changed, 40 insertions, 2 deletions
diff --git a/synapse/handlers/account_validity.py b/synapse/handlers/account_validity.py

index d752cf34f0..640c2e9fd6 100644 --- a/synapse/handlers/account_validity.py +++ b/synapse/handlers/account_validity.py
@@ -18,7 +18,10 @@ import logging from typing import TYPE_CHECKING, List, Optional, Tuple from synapse.api.errors import StoreError, SynapseError -from synapse.metrics.background_process_metrics import wrap_as_background_process +from synapse.metrics.background_process_metrics import ( + run_as_background_process, + wrap_as_background_process, +) from synapse.types import UserID from synapse.util import stringutils @@ -45,6 +48,9 @@ class AccountValidityHandler: hs.config.account_validity.account_validity_renew_by_email_enabled ) + self._show_users_in_user_directory = self.hs.config.show_users_in_user_directory + self.profile_handler = self.hs.get_profile_handler() + self._account_validity_period = None if self._account_validity_enabled: self._account_validity_period = ( @@ -70,6 +76,18 @@ class AccountValidityHandler: if hs.config.run_background_tasks: self.clock.looping_call(self._send_renewal_emails, 30 * 60 * 1000) + # Mark users as inactive when they expired. Check once every hour + if self._account_validity_enabled: + + 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) + @wrap_as_background_process("send_renewals") async def _send_renewal_emails(self) -> None: """Gets the list of users whose account is expiring in the amount of time @@ -214,7 +232,7 @@ class AccountValidityHandler: Returns: A tuple containing: * A bool representing whether the token is valid and unused. - * A bool which is `True` if the token is valid, but stale. + * A bool representing whether the token is stale. * An int representing the user's expiry timestamp as milliseconds since the epoch, or 0 if the token was invalid. """ @@ -284,4 +302,24 @@ class AccountValidityHandler: token_used_ts=now, ) + # Check if renewed users should be reintroduced to the user directory + if self._show_users_in_user_directory: + # Show the user in the directory again by setting them to active + await self.profile_handler.set_active( + [UserID.from_string(user_id)], True, True + ) + return expiration_ts + + 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. + + Returns: + Deferred + """ + # Get active, expired users + active_expired_users = await self.store.get_expired_users() + + # Mark each as non-active + await self.profile_handler.set_active(active_expired_users, False, True)