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

Remove pushers when deleting 3pid from account #10581

Merged
merged 16 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10581.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove pushers when deleting 3pid from account.
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
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
47 changes: 47 additions & 0 deletions synapse/storage/databases/main/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,53 @@ def delete_pusher_txn(txn, stream_id):
"delete_pusher", delete_pusher_txn, stream_id
)

async def delete_all_pushers_with_pushkey_and_user_id(
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
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.
pushers = list(
await self.get_pushers_by({"user_name": user_id, "pushkey": pushkey})
)

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

# remove the pushers from the pushers table
self.db_pool.simple_delete_txn(
txn,
table="pushers",
keyvalues={"user_name": user_id, "pushkey": pushkey},
)

# store a record of these deletions in the deleted_pushers table
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_with_pushkey_and_user_id",
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