Skip to content
Snippets Groups Projects
Unverified Commit 13d77464 authored by Patrick Cloke's avatar Patrick Cloke Committed by GitHub
Browse files

Follow-up to admin API to re-activate accounts (#7908)

parent cc9bb3dc
Branches
Tags
No related merge requests found
Add the ability to re-activate an account from the admin API.
...@@ -30,6 +30,7 @@ class DeactivateAccountHandler(BaseHandler): ...@@ -30,6 +30,7 @@ class DeactivateAccountHandler(BaseHandler):
def __init__(self, hs): def __init__(self, hs):
super(DeactivateAccountHandler, self).__init__(hs) super(DeactivateAccountHandler, self).__init__(hs)
self.hs = hs
self._auth_handler = hs.get_auth_handler() self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler() self._device_handler = hs.get_device_handler()
self._room_member_handler = hs.get_room_member_handler() self._room_member_handler = hs.get_room_member_handler()
...@@ -222,13 +223,26 @@ class DeactivateAccountHandler(BaseHandler): ...@@ -222,13 +223,26 @@ class DeactivateAccountHandler(BaseHandler):
""" """
Activate an account that was previously deactivated. Activate an account that was previously deactivated.
This simply marks the user as activate in the database and does not This marks the user as active and not erased in the database, but does
attempt to rejoin rooms, re-add threepids, etc. not attempt to rejoin rooms, re-add threepids, etc.
If enabled, the user will be re-added to the user directory.
The user will also need a password hash set to actually login. The user will also need a password hash set to actually login.
Args: Args:
user_id: ID of user to be deactivated user_id: ID of user to be re-activated
""" """
# Mark the user as activate. # Add the user to the directory, if necessary.
user = UserID.from_string(user_id)
if self.hs.config.user_directory_search_all_users:
profile = await self.store.get_profileinfo(user.localpart)
await self.user_directory_handler.handle_local_profile_change(
user_id, profile
)
# Ensure the user is not marked as erased.
await self.store.mark_user_not_erased(user_id)
# Mark the user as active.
await self.store.set_user_deactivated_status(user_id, False) await self.store.set_user_deactivated_status(user_id, False)
...@@ -70,11 +70,11 @@ class UserErasureWorkerStore(SQLBaseStore): ...@@ -70,11 +70,11 @@ class UserErasureWorkerStore(SQLBaseStore):
class UserErasureStore(UserErasureWorkerStore): class UserErasureStore(UserErasureWorkerStore):
def mark_user_erased(self, user_id): def mark_user_erased(self, user_id: str) -> None:
"""Indicate that user_id wishes their message history to be erased. """Indicate that user_id wishes their message history to be erased.
Args: Args:
user_id (str): full user_id to be erased user_id: full user_id to be erased
""" """
def f(txn): def f(txn):
...@@ -89,3 +89,25 @@ class UserErasureStore(UserErasureWorkerStore): ...@@ -89,3 +89,25 @@ class UserErasureStore(UserErasureWorkerStore):
self._invalidate_cache_and_stream(txn, self.is_user_erased, (user_id,)) self._invalidate_cache_and_stream(txn, self.is_user_erased, (user_id,))
return self.db.runInteraction("mark_user_erased", f) return self.db.runInteraction("mark_user_erased", f)
def mark_user_not_erased(self, user_id: str) -> None:
"""Indicate that user_id is no longer erased.
Args:
user_id: full user_id to be un-erased
"""
def f(txn):
# first check if they are already in the list
txn.execute("SELECT 1 FROM erased_users WHERE user_id = ?", (user_id,))
if not txn.fetchone():
return
# They are there, delete them.
self.simple_delete_one_txn(
txn, "erased_users", keyvalues={"user_id": user_id}
)
self._invalidate_cache_and_stream(txn, self.is_user_erased, (user_id,))
return self.db.runInteraction("mark_user_not_erased", f)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment