Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 14776db

Browse files
committed
Don't push if an user account has expired
Signed-off-by: Mathieu Velten <[email protected]>
1 parent d688b4b commit 14776db

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

changelog.d/8353.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't push if an user account has expired.

synapse/api/auth.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,7 @@ async def get_user_by_req(
218218
# Deny the request if the user account has expired.
219219
if self._account_validity.enabled and not allow_expired:
220220
user_id = user.to_string()
221-
expiration_ts = await self.store.get_expiration_ts_for_user(user_id)
222-
if (
223-
expiration_ts is not None
224-
and self.clock.time_msec() >= expiration_ts
225-
):
221+
if await self.store.is_account_expired(user_id, self.clock.time_msec()):
226222
raise AuthError(
227223
403, "User account has expired", errcode=Codes.EXPIRED_ACCOUNT
228224
)

synapse/push/pusherpool.py

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def __init__(self, hs: "HomeServer"):
6060
self.store = self.hs.get_datastore()
6161
self.clock = self.hs.get_clock()
6262

63+
self._account_validity = hs.config.account_validity
64+
6365
# We shard the handling of push notifications by user ID.
6466
self._pusher_shard_config = hs.config.push.pusher_shard_config
6567
self._instance_name = hs.get_instance_name()
@@ -202,6 +204,14 @@ async def on_new_notifications(self, max_stream_id: int):
202204
)
203205

204206
for u in users_affected:
207+
# Don't push if the user account has expired
208+
if self._account_validity.enabled:
209+
expired = await self.store.is_account_expired(
210+
u, self.clock.time_msec()
211+
)
212+
if expired:
213+
continue
214+
205215
if u in self.pushers:
206216
for p in self.pushers[u].values():
207217
p.on_new_notifications(max_stream_id)
@@ -222,6 +232,14 @@ async def on_new_receipts(self, min_stream_id, max_stream_id, affected_room_ids)
222232
)
223233

224234
for u in users_affected:
235+
# Don't push if the user account has expired
236+
if self._account_validity.enabled:
237+
expired = await self.store.is_account_expired(
238+
u, self.clock.time_msec()
239+
)
240+
if expired:
241+
continue
242+
225243
if u in self.pushers:
226244
for p in self.pushers[u].values():
227245
p.on_new_receipts(min_stream_id, max_stream_id)

synapse/storage/databases/main/registration.py

+16
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ async def get_expiration_ts_for_user(self, user_id: str) -> Optional[int]:
116116
desc="get_expiration_ts_for_user",
117117
)
118118

119+
async def is_account_expired(self, user_id: str, current_ts: int) -> bool:
120+
"""
121+
Returns whether an user account is expired.
122+
123+
Args:
124+
user_id: The user's ID
125+
current_ts: The current timestamp
126+
127+
Returns:
128+
Deferred[bool]: whether the user account has expired
129+
"""
130+
expiration_ts = await self.get_expiration_ts_for_user(user_id)
131+
if expiration_ts is not None and current_ts >= expiration_ts:
132+
return True
133+
return False
134+
119135
async def set_account_validity_for_user(
120136
self,
121137
user_id: str,

0 commit comments

Comments
 (0)