Skip to content

Commit

Permalink
feat: admin/system-webhook/* 系のエンドポイントをサポート
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Nov 11, 2024
1 parent 6d529f9 commit cf99b06
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 11 deletions.
10 changes: 5 additions & 5 deletions compiler/datas/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -2241,31 +2241,31 @@
},
"/admin/system-webhook/create": {
"path": "/admin/system-webhook/create",
"status": "notSupported",
"status": "supported",
"request_body_hash": "5bdf221beffb4e97ea9f80b94e0a15708db0926b472f4a8938f882b7ae5401d2",
"response_body_hash": "8a706b3d642206f37fd2b58155b272dc8725211b8316b7455912a1bb42992edf"
},
"/admin/system-webhook/delete": {
"path": "/admin/system-webhook/delete",
"status": "notSupported",
"status": "supported",
"request_body_hash": "3e47b10418dc28d7a702f3c13c8f0cd061a88803f92ad7d9009e930a8ba8d004",
"response_body_hash": "df9c0f9df08effe88b00991f12e46077998bd6d6c3442ec518e5f463680a2c54"
},
"/admin/system-webhook/list": {
"path": "/admin/system-webhook/list",
"status": "notSupported",
"status": "supported",
"request_body_hash": "ad94744b31c0b3c6a4f18b7d8eb3e4295fb263a6f8db5f06c016d73a74acf886",
"response_body_hash": "59c0e782f8b501d0ee1d9dbfcadf86ac845e5e1c2a878a594bd0bb65f1bbc102"
},
"/admin/system-webhook/show": {
"path": "/admin/system-webhook/show",
"status": "notSupported",
"status": "supported",
"request_body_hash": "3e47b10418dc28d7a702f3c13c8f0cd061a88803f92ad7d9009e930a8ba8d004",
"response_body_hash": "b3e51d24fa36b875bcddf8af5aa9563773430ae9de3cc36b13fd845199a203f7"
},
"/admin/system-webhook/update": {
"path": "/admin/system-webhook/update",
"status": "notSupported",
"status": "supported",
"request_body_hash": "c9106bef2410dcc5e22f3d4321d65b8c211dc70740cce3bcdcaa3c0654e6451f",
"response_body_hash": "8a706b3d642206f37fd2b58155b272dc8725211b8316b7455912a1bb42992edf"
},
Expand Down
12 changes: 6 additions & 6 deletions compiler/datas/support_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`2024.10.0-beta.6`

## Supported endpoints (177/383)
## Supported endpoints (182/383)

- [x] /admin/accounts/create
- [x] /admin/accounts/delete
Expand Down Expand Up @@ -114,6 +114,11 @@
- [x] /users/lists/update-membership
- [x] /admin/unset-user-avatar
- [x] /admin/unset-user-banner
- [x] /admin/system-webhook/create
- [x] /admin/system-webhook/delete
- [x] /admin/system-webhook/list
- [x] /admin/system-webhook/show
- [x] /admin/system-webhook/update


## Not supported endpoints
Expand Down Expand Up @@ -314,11 +319,6 @@
- [ ] /admin/abuse-report/notification-recipient/create
- [ ] /admin/abuse-report/notification-recipient/update
- [ ] /admin/abuse-report/notification-recipient/delete
- [ ] /admin/system-webhook/create
- [ ] /admin/system-webhook/delete
- [ ] /admin/system-webhook/list
- [ ] /admin/system-webhook/show
- [ ] /admin/system-webhook/update
- [ ] /announcements/show
- [ ] /admin/forward-abuse-user-report
- [ ] /admin/update-abuse-user-report
Expand Down
112 changes: 112 additions & 0 deletions mipac/actions/admins/system_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Literal, override

from mipac.abstract.action import AbstractAction
from mipac.http import HTTPClient, Route
from mipac.models.system_webhook import SystemWebhook
from mipac.types.system_webhook import ISystemWebhook, SystemWebhookEventTypes

if TYPE_CHECKING:
from mipac.client import ClientManager


class SharedSystemWebhookActions(AbstractAction):
def __init__(self, *, session: HTTPClient, client: ClientManager):
self._session: HTTPClient = session
self._client: ClientManager = client

async def delete(self, *, webhook_id: str) -> bool:
is_success: bool = await self._session.request(
Route("POST", "/api/admin/system-webhook/delete"), json={"id": webhook_id}
)
return is_success

async def update(
self,
is_active: bool,
name: str,
on: SystemWebhookEventTypes,
url: str,
secret: str,
*,
webhook_id: str,
) -> SystemWebhook:
body = {"isActive": is_active, "name": name, "on": on, "url": url, "secret": secret}
system_webhook_payload: ISystemWebhook = await self._session.request(
Route("POST", "/api/admin/system-webhook/update"), json={"id": webhook_id, **body}
)

return SystemWebhook(system_webhook_payload, client=self._client)


class ClientSystemWebhookActions(SharedSystemWebhookActions):
def __init__(self, webhook_id: str, *, session: HTTPClient, client: ClientManager):
super().__init__(session=session, client=client)
self.__webhook_id: str = webhook_id

@override
async def delete(self, *, webhook_id: str | None = None) -> bool:
webhook_id = webhook_id or self.__webhook_id
return await super().delete(webhook_id=webhook_id)

@override
async def update(
self,
is_active: bool,
name: str,
on: SystemWebhookEventTypes,
url: str,
secret: str,
*,
webhook_id: str | None = None,
) -> SystemWebhook:
webhook_id = webhook_id or self.__webhook_id
return await super().update(is_active, name, on, url, secret, webhook_id=webhook_id)


class SystemWebhookActions(SharedSystemWebhookActions):
def __init__(self, *, session: HTTPClient, client: ClientManager):
super().__init__(session=session, client=client)

async def create(
self,
is_active: bool,
name: str,
on: list[Literal["abuseReport", "abuseReportResolved", "userCreated"]],
url: str,
secret: str,
):
body = {"isActive": is_active, "name": name, "on": on, "url": url, "secret": secret}

system_webhook_payload: ISystemWebhook = await self._session.request(
Route("POST", "/api/admin/system-webhook/create"), json=body
)
return SystemWebhook(system_webhook_payload, client=self._client)

async def get_list(
self,
is_active: bool | None = None,
abuse_report: bool | None = None,
abuse_report_resolved: bool | None = None,
user_created: bool | None = None,
):
body = {
"isActive": is_active,
"abuseReport": abuse_report,
"abuseReportResolved": abuse_report_resolved,
"userCreated": user_created,
}
system_webhook_payload: list[ISystemWebhook] = await self._session.request(
Route("POST", "/api/admin/system-webhook/list"), json=body
)
return [
SystemWebhook(system_webhook, client=self._client)
for system_webhook in system_webhook_payload
]

async def show(self, *, webhook_id: str):
system_webhook_payload: ISystemWebhook = await self._session.request(
Route("POST", "/api/admin/system-webhook/show"), json={"id": webhook_id}
)
return SystemWebhook(system_webhook_payload, client=self._client)
11 changes: 11 additions & 0 deletions mipac/manager/admins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from mipac.manager.admins.emoji import AdminEmojiManager, ClientAdminEmojiManager
from mipac.manager.admins.invite import AdminInviteManager
from mipac.manager.admins.roles import AdminRoleManager, ClientAdminRoleManager
from mipac.manager.admins.system_webhook import SystemWebhookManager, ClientSystemWebhookManager
from mipac.manager.admins.user import AdminUserManager

if TYPE_CHECKING:
Expand All @@ -43,6 +44,9 @@ def __init__(self, session: HTTPClient, client: ClientManager):
self.avatar_decoration: AdminAvatarDecorationManager = AdminAvatarDecorationManager(
session=session, client=client
)
self.system_webhook: SystemWebhookManager = SystemWebhookManager(
session=session, client=client
)

@property
def action(self) -> AdminActions:
Expand Down Expand Up @@ -78,3 +82,10 @@ def _create_client_admin_avatar_decoration_manager(
session=self.__session,
client=self.__client,
)

def _create_client_system_webhook_manager(self, webhook_id: str) -> ClientSystemWebhookManager:
return ClientSystemWebhookManager(
webhook_id=webhook_id,
session=self.__session,
client=self.__client,
)
29 changes: 29 additions & 0 deletions mipac/manager/admins/system_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations
from typing import TYPE_CHECKING

from mipac.abstract.manager import AbstractManager
from mipac.http import HTTPClient
from mipac.actions.admins.system_webhook import SystemWebhookActions, ClientSystemWebhookActions

if TYPE_CHECKING:
from mipac.manager.client import ClientManager


class ClientSystemWebhookManager(AbstractManager):
def __init__(self, webhook_id: str, *, session: HTTPClient, client: ClientManager):
self.__action: ClientSystemWebhookActions = ClientSystemWebhookActions(
webhook_id, session=session, client=client
)

@property
def action(self) -> ClientSystemWebhookActions:
return self.__action


class SystemWebhookManager(AbstractManager):
def __init__(self, *, session: HTTPClient, client: ClientManager):
self.__action: SystemWebhookActions = SystemWebhookActions(session=session, client=client)

@property
def action(self) -> SystemWebhookActions:
return self.__action
5 changes: 5 additions & 0 deletions mipac/models/system_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

if TYPE_CHECKING:
from mipac.client import ClientManager
from mipac.manager.admins.system_webhook import ClientSystemWebhookManager


class SystemWebhook:
Expand Down Expand Up @@ -54,3 +55,7 @@ def url(self) -> str:
@property
def secret(self) -> str:
return self.__raw_system_webhook["secret"]

@property
def api(self) -> ClientSystemWebhookManager:
return self.___client.admin._create_client_system_webhook_manager(self.id)

0 comments on commit cf99b06

Please sign in to comment.