| | |
| | | return "бан" if value == "ban" else "мут" |
| | | |
| | | |
| | | async def chat_perm(request) -> web.Response: |
| | | user = await _user(request) |
| | | data = await request.post() |
| | | chat_id = int(data["chat_id"]) |
| | | target_id = int(data["user_id"]) |
| | | perm = data["perm"] |
| | | allow = data.get("allow") == "1" |
| | | if chat_id not in await _allowed_ids(user["user_id"]): |
| | | raise web.HTTPForbidden() |
| | | async def _do_perm(user, chat_id: int, target_id: int, perm: str, allow: bool): |
| | | # Общая логика смены права: применяем, логируем и уведомляем чат. |
| | | if perm not in PERM_LABELS: |
| | | raise web.HTTPFound(f"/chats/{chat_id}") |
| | | ok, _msg = await pm.set_perm(chat_id, user["user_id"], target_id, perm, allow) |
| | | return False, "Неизвестное право." |
| | | ok, msg = await pm.set_perm(chat_id, user["user_id"], target_id, perm, allow) |
| | | if ok: |
| | | actor = user["user_id"] |
| | | name = user.get("first_name") or str(actor) |
| | |
| | | f"Право «{PERM_LABELS[perm]}» для {mention(target_id)} {state} через веб-панель.\n" |
| | | f"Изменил: {mention(actor, name)}", |
| | | ) |
| | | return ok, msg |
| | | |
| | | |
| | | async def chat_perm(request) -> web.Response: |
| | | user = await _user(request) |
| | | data = await request.post() |
| | | chat_id = int(data["chat_id"]) |
| | | target_id = int(data["user_id"]) |
| | | perm = data["perm"] |
| | | allow = data.get("allow") == "1" |
| | | if chat_id not in await _allowed_ids(user["user_id"]): |
| | | raise web.HTTPForbidden() |
| | | await _do_perm(user, chat_id, target_id, perm, allow) |
| | | raise web.HTTPFound(f"/chats/{chat_id}") |
| | | |
| | | |
| | | async def api_perm(request) -> web.Response: |
| | | # Тот же путь, но с JSON-ответом: используется для переключения чипов без перезагрузки. |
| | | user = await _user(request) |
| | | data = await request.post() |
| | | try: |
| | | chat_id = int(data["chat_id"]) |
| | | target_id = int(data["user_id"]) |
| | | perm = data["perm"] |
| | | except (KeyError, ValueError): |
| | | return web.json_response({"ok": False, "msg": "Некорректные данные."}, status=400) |
| | | allow = data.get("allow") == "1" |
| | | if chat_id not in await _allowed_ids(user["user_id"]): |
| | | return web.json_response({"ok": False, "msg": "Нет доступа."}, status=403) |
| | | ok, msg = await _do_perm(user, chat_id, target_id, perm, allow) |
| | | return web.json_response({"ok": ok, "allow": allow, "msg": msg}) |
| | | |
| | | |
| | | async def users_page(request) -> web.Response: |
| | | user = await _user(request) |
| | | chats = await allowed_chats(user["user_id"]) |