Add a flag to indicate if the requesting user can unbridge the portal
This commit is contained in:
@@ -184,6 +184,21 @@ class Portal:
|
|||||||
return tgid not in self.filter_list
|
return tgid not in self.filter_list
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
# region Permission checks
|
||||||
|
|
||||||
|
async def can_user_perform(self, user: 'u.User', event: str, default: int = 50) -> bool:
|
||||||
|
if user.is_admin:
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
await self.main_intent.get_power_levels(self.mxid)
|
||||||
|
except MatrixRequestError:
|
||||||
|
return False
|
||||||
|
return self.main_intent.state_store.has_power_level(
|
||||||
|
self.mxid, user.mxid,
|
||||||
|
event=f"net.maunium.telegram.{event}",
|
||||||
|
default=default)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
# region Deduplication
|
# region Deduplication
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ class ProvisioningAPI(AuthAPI):
|
|||||||
if not portal:
|
if not portal:
|
||||||
return self.get_error_response(404, "portal_not_found",
|
return self.get_error_response(404, "portal_not_found",
|
||||||
"Portal with given Matrix ID not found.")
|
"Portal with given Matrix ID not found.")
|
||||||
|
user, _ = await self.get_user(request.query.get("user_id", None), expect_logged_in=None,
|
||||||
|
require_puppeting=False)
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
"mxid": portal.mxid,
|
"mxid": portal.mxid,
|
||||||
"chat_id": get_peer_id(portal.peer),
|
"chat_id": get_peer_id(portal.peer),
|
||||||
@@ -82,6 +84,7 @@ class ProvisioningAPI(AuthAPI):
|
|||||||
"about": portal.about,
|
"about": portal.about,
|
||||||
"username": portal.username,
|
"username": portal.username,
|
||||||
"megagroup": portal.megagroup,
|
"megagroup": portal.megagroup,
|
||||||
|
"can_unbridge": (await portal.can_user_perform(user, "unbridge")) if user else False,
|
||||||
})
|
})
|
||||||
|
|
||||||
async def get_portal_by_tgid(self, request: web.Request) -> web.Response:
|
async def get_portal_by_tgid(self, request: web.Request) -> web.Response:
|
||||||
@@ -98,6 +101,8 @@ class ProvisioningAPI(AuthAPI):
|
|||||||
if not portal:
|
if not portal:
|
||||||
return self.get_error_response(404, "portal_not_found",
|
return self.get_error_response(404, "portal_not_found",
|
||||||
"Portal to given Telegram chat not found.")
|
"Portal to given Telegram chat not found.")
|
||||||
|
user, _ = await self.get_user(request.query.get("user_id", None), expect_logged_in=None,
|
||||||
|
require_puppeting=False)
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
"mxid": portal.mxid,
|
"mxid": portal.mxid,
|
||||||
"chat_id": get_peer_id(portal.peer),
|
"chat_id": get_peer_id(portal.peer),
|
||||||
@@ -106,6 +111,7 @@ class ProvisioningAPI(AuthAPI):
|
|||||||
"about": portal.about,
|
"about": portal.about,
|
||||||
"username": portal.username,
|
"username": portal.username,
|
||||||
"megagroup": portal.megagroup,
|
"megagroup": portal.megagroup,
|
||||||
|
"can_unbridge": (await portal.can_user_perform(user, "unbridge")) if user else False,
|
||||||
})
|
})
|
||||||
|
|
||||||
async def connect_chat(self, request: web.Request) -> web.Response:
|
async def connect_chat(self, request: web.Request) -> web.Response:
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
pattern: "![^/]+"
|
pattern: "![^/]+"
|
||||||
|
- name: user_id
|
||||||
|
in: query
|
||||||
|
description: Optional Matrix user ID to check if the user has permissions to do bridging.
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
/portal/{chat_id}:
|
/portal/{chat_id}:
|
||||||
get:
|
get:
|
||||||
operationId: get_portal_by_tgid
|
operationId: get_portal_by_tgid
|
||||||
@@ -102,6 +107,11 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
type: integer
|
type: integer
|
||||||
pattern: "-[0-9]+"
|
pattern: "-[0-9]+"
|
||||||
|
- name: user_id
|
||||||
|
in: query
|
||||||
|
description: Optional Matrix user ID to check if the user has permissions to do bridging.
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
/portal/{room_id}/connect/{chat_id}:
|
/portal/{room_id}/connect/{chat_id}:
|
||||||
post:
|
post:
|
||||||
operationId: connect_portal
|
operationId: connect_portal
|
||||||
@@ -829,6 +839,9 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
about:
|
about:
|
||||||
type: string
|
type: string
|
||||||
|
can_unbridge:
|
||||||
|
type: boolean
|
||||||
|
description: If a user ID was provided with the request, this will indicate whether or not the user can unbridge the room.
|
||||||
|
|
||||||
AuthSuccess:
|
AuthSuccess:
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
Reference in New Issue
Block a user