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

Commit c3bca37

Browse files
authored
Don't push if an user account has expired (#58)
1 parent 8b234fb commit c3bca37

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

changelog.d/58.misc

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,10 @@ def get_user_by_req(
222222
# Deny the request if the user account has expired.
223223
if self._account_validity.enabled and not allow_expired:
224224
user_id = user.to_string()
225-
expiration_ts = yield self.store.get_expiration_ts_for_user(user_id)
226-
if (
227-
expiration_ts is not None
228-
and self.clock.time_msec() >= expiration_ts
229-
):
225+
expired = yield self.store.is_account_expired(
226+
user_id, self.clock.time_msec()
227+
)
228+
if expired:
230229
raise AuthError(
231230
403, "User account has expired", errcode=Codes.EXPIRED_ACCOUNT
232231
)

synapse/push/pusherpool.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self, hs: "HomeServer"):
6666
self._pusher_shard_config = hs.config.push.pusher_shard_config
6767
self._instance_name = hs.get_instance_name()
6868

69+
self._account_validity = hs.config.account_validity
70+
6971
# map from user id to app_id:pushkey to pusher
7072
self.pushers = {} # type: Dict[str, Dict[str, Union[HttpPusher, EmailPusher]]]
7173

@@ -196,6 +198,14 @@ def on_new_notifications(self, min_stream_id, max_stream_id):
196198

197199
for u in users_affected:
198200
if u in self.pushers:
201+
# Don't push if the user account has expired
202+
if self._account_validity.enabled:
203+
expired = yield self.store.is_account_expired(
204+
u, self.clock.time_msec()
205+
)
206+
if expired:
207+
continue
208+
199209
for p in self.pushers[u].values():
200210
p.on_new_notifications(min_stream_id, max_stream_id)
201211

@@ -217,6 +227,14 @@ def on_new_receipts(self, min_stream_id, max_stream_id, affected_room_ids):
217227

218228
for u in users_affected:
219229
if u in self.pushers:
230+
# Don't push if the user account has expired
231+
if self._account_validity.enabled:
232+
expired = yield self.store.is_account_expired(
233+
u, self.clock.time_msec()
234+
)
235+
if expired:
236+
continue
237+
220238
for p in self.pushers[u].values():
221239
p.on_new_receipts(min_stream_id, max_stream_id)
222240

synapse/storage/data_stores/main/registration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ def get_expiration_ts_for_user(self, user_id):
125125
)
126126
return res
127127

128+
@defer.inlineCallbacks
129+
def is_account_expired(self, user_id: str, current_ts: int):
130+
"""
131+
Returns whether an user account is expired.
132+
133+
Args:
134+
user_id: The user's ID
135+
current_ts: The current timestamp
136+
137+
Returns:
138+
Deferred[bool]: whether the user account has expired
139+
"""
140+
expiration_ts = yield self.get_expiration_ts_for_user(user_id)
141+
if expiration_ts is not None and current_ts >= expiration_ts:
142+
return True
143+
return False
144+
128145
@defer.inlineCallbacks
129146
def set_account_validity_for_user(
130147
self, user_id, expiration_ts, email_sent, renewal_token=None

0 commit comments

Comments
 (0)