-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: AdminUserActionsをClientと分けた
- Loading branch information
Showing
2 changed files
with
118 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,168 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
from typing import TYPE_CHECKING, override | ||
|
||
from mipac.abstract.action import AbstractAction | ||
from mipac.http import HTTPClient, Route | ||
from mipac.models.user import MeDetailed, UserDetailedNotMe, packed_user | ||
from mipac.utils.util import deprecated | ||
|
||
if TYPE_CHECKING: | ||
from mipac.manager.client import ClientManager | ||
|
||
|
||
class AdminUserActions(AbstractAction): | ||
def __init__(self, user_id: str | None = None, *, session: HTTPClient, client: ClientManager): | ||
self.__user_id = user_id | ||
self.__session = session | ||
self.__client = client | ||
class SharedAdminUserActions(AbstractAction): | ||
def __init__(self, *, session: HTTPClient, client: ClientManager): | ||
self._session = session | ||
self._client = client | ||
|
||
async def delete_account(self, user_id: str | None = None) -> bool: | ||
""" | ||
Deletes the user with the specified user ID. | ||
@deprecated | ||
async def delete_account(self, *, user_id: str) -> bool: | ||
"""対象のユーザーを削除します | ||
Endpoint: `/api/admin/accounts/delete` | ||
.. deprecated:: 0.6.2 | ||
Use :meth:`mipac.actions.admins.accounts.delete` instead. | ||
Parameters | ||
---------- | ||
user_id : str | None, default=None | ||
ID of the user to be deleted | ||
user_id : str | ||
対象のユーザーID | ||
Returns | ||
------- | ||
bool | ||
Success or failure | ||
成功ならTrue | ||
""" | ||
return await self._client.admin.account.action.delete(user_id=user_id) | ||
|
||
user_id = user_id or self.__user_id | ||
async def show_user(self, *, user_id: str): # TODO: 専用の型が必要 | ||
"""ユーザーの情報を取得します | ||
Parameters | ||
---------- | ||
user_id : str | ||
対象のユーザーID | ||
""" | ||
data = {"userId": user_id} | ||
res = await self.__session.request( | ||
Route("POST", "/api/admin/accounts/delete"), | ||
|
||
raw_user = await self._session.request( | ||
Route("GET", "/api/admin/show-user"), | ||
json=data, | ||
auth=True, | ||
lower=True, | ||
) | ||
return bool(res) | ||
return raw_user | ||
|
||
async def show_user(self, user_id: str | None = None) -> UserDetailedNotMe | MeDetailed: | ||
""" | ||
Shows the user with the specified user ID. | ||
async def suspend(self, *, user_id: str) -> bool: | ||
"""対象のユーザーを凍結します | ||
Parameters | ||
---------- | ||
user_id : str | None, default=None | ||
ID of the user to be shown | ||
user_id : str | ||
対象のユーザーID | ||
Returns | ||
------- | ||
UserDetailedNotMe | MeDetailed | ||
bool | ||
成功ならTrue | ||
""" | ||
|
||
user_id = user_id or self.__user_id | ||
data = {"userId": user_id} | ||
res = await self.__session.request( | ||
Route("GET", "/api/admin/show-user"), | ||
|
||
res: bool = await self._session.request( | ||
Route("POST", "/api/admin/suspend-user"), | ||
json=data, | ||
auth=True, | ||
lower=True, | ||
) | ||
return packed_user(res, client=self.__client) | ||
return res | ||
|
||
async def suspend(self, user_id: str | None = None) -> bool: | ||
""" | ||
Suspends the user with the specified user ID. | ||
async def unsuspend(self, *, user_id: str) -> bool: | ||
"""ユーザーの凍結を解除します | ||
Parameters | ||
---------- | ||
user_id : str | None, default=None | ||
ID of the user to be suspended | ||
user_id : str | ||
対象のユーザーID | ||
Returns | ||
------- | ||
bool | ||
Success or failure | ||
成功ならTrue | ||
""" | ||
|
||
user_id = user_id or self.__user_id | ||
data = {"userId": user_id} | ||
res = await self.__session.request( | ||
Route("POST", "/api/admin/suspend-user"), | ||
|
||
res: bool = await self._session.request( | ||
Route("POST", "/api/admin/unsuspend-user"), | ||
json=data, | ||
auth=True, | ||
lower=True, | ||
) | ||
return bool(res) | ||
return res | ||
|
||
|
||
class ClientAdminUserActions(SharedAdminUserActions): | ||
def __init__(self, user_id: str, *, session: HTTPClient, client: ClientManager): | ||
super().__init__(session=session, client=client) | ||
self.__user_id = user_id | ||
|
||
@override | ||
async def delete_account(self, *, user_id: str | None = None) -> bool: | ||
user_id = user_id or self.__user_id | ||
|
||
return await super().delete_account(user_id=user_id) | ||
|
||
async def unsuspend(self, user_id: str | None = None) -> bool: | ||
@override | ||
async def show_user(self, *, user_id: str | None = None): | ||
"""ユーザーの情報を取得します | ||
Parameters | ||
---------- | ||
user_id : str | ||
対象のユーザーID | ||
""" | ||
Unsuspends the user with the specified user ID. | ||
user_id = user_id or self.__user_id | ||
|
||
return await super().show_user(user_id=user_id) | ||
|
||
@override | ||
async def suspend(self, *, user_id: str | None = None) -> bool: | ||
"""対象のユーザーを凍結します | ||
Parameters | ||
---------- | ||
user_id : str | None, default=None | ||
ID of the user to be unsuspended | ||
user_id : str | ||
対象のユーザーID | ||
Returns | ||
------- | ||
bool | ||
Success or failure | ||
成功ならTrue | ||
""" | ||
|
||
user_id = user_id or self.__user_id | ||
data = {"userId": user_id} | ||
res: bool = await self.__session.request( | ||
Route("POST", "/api/admin/unsuspend-user"), | ||
json=data, | ||
auth=True, | ||
lower=True, | ||
) | ||
return bool(res) | ||
|
||
return await super().suspend(user_id=user_id) | ||
|
||
@override | ||
async def unsuspend(self, *, user_id: str | None = None) -> bool: | ||
"""ユーザーの凍結を解除します | ||
Parameters | ||
---------- | ||
user_id : str | ||
対象のユーザーID | ||
Returns | ||
------- | ||
bool | ||
成功ならTrue | ||
""" | ||
user_id = user_id or self.__user_id | ||
|
||
return await super().unsuspend(user_id=user_id) | ||
|
||
|
||
class AdminUserActions(SharedAdminUserActions): | ||
def __init__(self, *, session: HTTPClient, client: ClientManager): | ||
super().__init__(session=session, client=client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters