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

Commit

Permalink
Remove pushers when deleting 3pid from account
Browse files Browse the repository at this point in the history
When a user deletes an email from their account it will
now also remove all pushers for that email and that user
(even if these pushers were created by a different client)
  • Loading branch information
Azrenbeth authored and Azrenbeth committed Aug 11, 2021
1 parent fab352a commit fb6e21b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,9 @@ async def delete_threepid(
)

await self.store.user_delete_threepid(user_id, medium, address)
await self.store.delete_all_pushers_with_pushkey_and_user_id(
pushkey=address, user_id=user_id
)
return result

async def hash(self, password: str) -> str:
Expand Down
46 changes: 46 additions & 0 deletions synapse/storage/databases/main/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,52 @@ def delete_pusher_txn(txn, stream_id):
"delete_pusher", delete_pusher_txn, stream_id
)

async def delete_all_pushers_with_pushkey_and_user_id(
self, pushkey: str, user_id: str
) -> None:
"""Delete all pushers associated with an account with a certain pushkey."""

# We want to generate a row in `deleted_pushers` for each pusher we're
# deleting, so we fetch the list now so we can generate the appropriate
# number of stream IDs.
#
# Note: technically there could be a race here between adding/deleting
# pushers, but a) the worst case if we don't stop a pusher until the
# next restart and b) this is only called when we're deactivating an
# account.

pushers = list(await self.get_pushers_by({"user_name": user_id, "pushkey": pushkey}))

def delete_pushers_txn(txn, stream_ids):
self._invalidate_cache_and_stream( # type: ignore
txn, self.get_if_user_has_pusher, (user_id,)
)

self.db_pool.simple_delete_txn(
txn,
table="pushers",
keyvalues={"user_name": user_id},
)

self.db_pool.simple_insert_many_txn(
txn,
table="deleted_pushers",
values=[
{
"stream_id": stream_id,
"app_id": pusher.app_id,
"pushkey": pushkey,
"user_id": user_id,
}
for stream_id, pusher in zip(stream_ids, pushers)
],
)

async with self._pushers_id_gen.get_next_mult(len(pushers)) as stream_ids:
await self.db_pool.runInteraction(
"delete_all_pushers_for_user", delete_pushers_txn, stream_ids
)

async def delete_all_pushers_for_user(self, user_id: str) -> None:
"""Delete all pushers associated with an account."""

Expand Down

0 comments on commit fb6e21b

Please sign in to comment.