Skip to content

Commit 0d57324

Browse files
feat: add restore_users (#134)
* feat: add restore_users * fix: apply linter fixes Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: make linter happy * fix: make linter happy 2 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 11072b2 commit 0d57324

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ disallow_untyped_defs = true
3838
disallow_untyped_calls = true
3939
check_untyped_defs = true
4040
warn_unused_configs = true
41+
strict_optional = false
4142

4243
[[tool.mypy.overrides]]
4344
module = "stream_chat.tests.*"

stream_chat/async_chat/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ async def delete_users(
171171
"users/delete", data=dict(options, user=delete_type, user_ids=user_ids)
172172
)
173173

174+
async def restore_users(self, user_ids: Iterable[str]) -> StreamResponse:
175+
return await self.post("users/restore", data={"user_ids": user_ids})
176+
174177
async def deactivate_user(self, user_id: str, **options: Any) -> StreamResponse:
175178
return await self.post(f"users/{user_id}/deactivate", data=options)
176179

stream_chat/base/client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ def delete_users(
218218
"""
219219
pass
220220

221+
@abc.abstractmethod
222+
def restore_users(
223+
self, user_ids: Iterable[str]
224+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
225+
"""
226+
Restores soft deleted users.
227+
"""
228+
pass
229+
221230
@abc.abstractmethod
222231
def deactivate_user(
223232
self, user_id: str, **options: Any
@@ -562,7 +571,7 @@ def delete_channel_type(
562571
@abc.abstractmethod
563572
def channel(
564573
self, channel_type: str, channel_id: str = None, data: Dict = None
565-
) -> TChannel:
574+
) -> TChannel: # type: ignore[type-var]
566575
"""
567576
Creates a channel object
568577
@@ -1141,6 +1150,7 @@ def create_import_url(
11411150
"""
11421151
pass
11431152

1153+
@abc.abstractmethod
11441154
def create_import(
11451155
self, path: str, mode: Literal["insert", "upsert"] = "upsert"
11461156
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
@@ -1162,6 +1172,7 @@ def create_import(
11621172
"""
11631173
pass
11641174

1175+
@abc.abstractmethod
11651176
def get_import(self, id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
11661177
"""
11671178
Get the status of an import task.
@@ -1181,6 +1192,7 @@ def get_import(self, id: str) -> Union[StreamResponse, Awaitable[StreamResponse]
11811192
"""
11821193
pass
11831194

1195+
@abc.abstractmethod
11841196
def list_imports(
11851197
self, options: Dict = None
11861198
) -> Union[StreamResponse, Awaitable[StreamResponse]]:

stream_chat/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def delete_users(
161161
"users/delete", data=dict(options, user=delete_type, user_ids=user_ids)
162162
)
163163

164+
def restore_users(self, user_ids: Iterable[str]) -> StreamResponse:
165+
return self.post("users/restore", data={"user_ids": user_ids})
166+
164167
def deactivate_user(self, user_id: str, **options: Any) -> StreamResponse:
165168
return self.post(f"users/{user_id}/deactivate", data=options)
166169

stream_chat/tests/async_chat/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ async def test_delete_users(self, client: StreamChatAsync, random_user: Dict):
164164

165165
pytest.fail("task did not succeed")
166166

167+
async def test_restore_users(self, client: StreamChatAsync, random_user: Dict):
168+
response = await client.delete_user(random_user["id"])
169+
assert random_user["id"] == response["user"]["id"]
170+
171+
await client.restore_users([random_user["id"]])
172+
173+
response = await client.query_users({"id": random_user["id"]})
174+
assert len(response["users"]) == 1
175+
167176
async def test_deactivate_user(self, client: StreamChatAsync, random_user: Dict):
168177
response = await client.deactivate_user(random_user["id"])
169178
assert "user" in response

stream_chat/tests/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ def test_delete_users(self, client: StreamChat, random_user: Dict):
154154

155155
pytest.fail("task did not succeed")
156156

157+
def test_restore_users(self, client: StreamChat, random_user: Dict):
158+
response = client.delete_user(random_user["id"])
159+
assert random_user["id"] == response["user"]["id"]
160+
161+
client.restore_users([random_user["id"]])
162+
163+
response = client.query_users({"id": random_user["id"]})
164+
assert len(response["users"]) == 1
165+
157166
def test_deactivate_user(self, client: StreamChat, random_user: Dict):
158167
response = client.deactivate_user(random_user["id"])
159168
assert "user" in response

0 commit comments

Comments
 (0)