Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Drop support for calling /_matrix/client/v3/rooms/{roomId}/invite without an id_access_token #13241

Merged
merged 33 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f6487e
Drop v1 lookup
Vetchu Jul 11, 2022
ef1c794
Add changelog
Vetchu Jul 11, 2022
e9c789a
Address code review
Vetchu Jul 11, 2022
e354ec6
Repair tests PoC.
Vetchu Jul 11, 2022
eb5ba09
Update changelog.d/13241.removal
Vetchu Jul 12, 2022
72313f6
merge develop
Vetchu Jul 21, 2022
779e78c
Add tests, address concerns
Vetchu Jul 21, 2022
5668dcd
minify test
Vetchu Jul 22, 2022
6e908e4
missing comma
Vetchu Jul 25, 2022
242fa48
Merge branch 'develop' into misc/drop-v1-lookup
Vetchu Jul 25, 2022
6698279
Address comments
Vetchu Jul 25, 2022
48d88f0
Merge branch 'misc/drop-v1-lookup' of github.com:Vetchu/synapse into …
Vetchu Jul 25, 2022
6b1413b
Merge branch 'develop' into misc/drop-v1-lookup
Vetchu Jul 25, 2022
dacd33d
Merge branch 'matrix-org:develop' into misc/drop-v1-lookup
Vetchu Aug 11, 2022
9a04234
Update tests/rest/client/test_rooms.py
Vetchu Aug 15, 2022
e115f60
addressed the comments
Vetchu Aug 15, 2022
c535ea8
Merge branch 'develop' into misc/drop-v1-lookup
Vetchu Aug 15, 2022
f2a74b2
add missing check
Vetchu Aug 15, 2022
bb84fe4
Merge branch 'develop' into misc/drop-v1-lookup
Vetchu Aug 15, 2022
8ab4b35
Merge branch 'develop' into misc/drop-v1-lookup
Vetchu Aug 15, 2022
f9600bb
fixed test
Vetchu Aug 15, 2022
0073118
catch missing param for 3pid
Vetchu Aug 15, 2022
ebcdbba
synapseerror
Vetchu Aug 15, 2022
b97b27f
validate earlier
Vetchu Aug 15, 2022
23be3b9
merge develop
Vetchu Aug 23, 2022
d1b6ae8
Merge remote-tracking branch 'origin' into misc/drop-v1-lookup
Vetchu Aug 23, 2022
21d9be1
Next iteration
Vetchu Aug 23, 2022
caeee4d
allow exception to go up
Vetchu Aug 23, 2022
3792e8c
Merge branch 'develop' into misc/drop-v1-lookup
Vetchu Aug 24, 2022
3dfd8fb
beautify code
Vetchu Aug 25, 2022
5b237aa
hopefully addresses the comments
Vetchu Aug 26, 2022
27951c5
Update synapse/handlers/room.py
richvdh Aug 31, 2022
c6aa582
Merge branch 'develop' into misc/drop-v1-lookup
richvdh Aug 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import random
import string
from collections import OrderedDict
from http import HTTPStatus
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -678,12 +679,6 @@ async def _move_aliases_to_new_room(
# we returned the new room to the client at this point.
logger.error("Unable to send updated alias events in new room: %s", e)

def _has_all_3pid_keys(self, invite_3pid: dict) -> bool:
return all(
key in invite_3pid
for key in ("medium", "address", "id_server", "id_access_token")
)

async def create_room(
self,
requester: Requester,
Expand Down Expand Up @@ -711,8 +706,8 @@ async def create_room(
was, requested, `room_alias`. Secondly, the stream_id of the
last persisted event.
Raises:
SynapseError if the room ID couldn't be stored, or something went
horribly wrong.
SynapseError if the room ID couldn't be stored, 3pid invitation config
validation failed, or something went horribly wrong.
ResourceLimitError if server is blocked to some resource being
exceeded
"""
Expand Down Expand Up @@ -740,10 +735,14 @@ async def create_room(

# validate each entry for correctness
for invite_3pid in invite_3pid_list:
if not self._has_all_3pid_keys(invite_3pid):
if not all(
key in invite_3pid
for key in ("medium", "address", "id_server", "id_access_token")
):
raise SynapseError(
richvdh marked this conversation as resolved.
Show resolved Hide resolved
400,
f"`id_server` and `id_access_token` are required when doing 3pid invite, caused by {invite_3pid}",
HTTPStatus.BAD_REQUEST,
"all of: `medium`, `address`, `id_server` and `id_access_token` "
f"are required when doing 3pid invite, caused by {invite_3pid}",
richvdh marked this conversation as resolved.
Show resolved Hide resolved
Codes.MISSING_PARAM,
)

Expand Down
42 changes: 21 additions & 21 deletions synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
import re
from enum import Enum
from http import HTTPStatus
from typing import TYPE_CHECKING, Awaitable, Dict, List, Optional, Tuple
from urllib import parse as urlparse

Expand Down Expand Up @@ -916,9 +917,6 @@ def __init__(self, hs: "HomeServer"):
self.room_member_handler = hs.get_room_member_handler()
self.auth = hs.get_auth()

def _has_3pid_invite_keys(self, content: JsonDict) -> bool:
return all(key in content for key in ("medium", "address"))

def register(self, http_server: HttpServer) -> None:
# /rooms/$roomid/[invite|join|leave]
PATTERNS = (
Expand Down Expand Up @@ -949,29 +947,31 @@ async def on_POST(
# cheekily send invalid bodies.
content = {}

if self._has_3pid_invite_keys(content):
if membership_action == "invite" and all(
key in content for key in ("medium", "address")
):
if not all(key in content for key in ("id_server", "id_access_token")):
raise SynapseError(
400,
HTTPStatus.BAD_REQUEST,
"`id_server` and `id_access_token` are required when doing 3pid invite",
Codes.MISSING_PARAM,
)
if membership_action == "invite":
try:
await self.room_member_handler.do_3pid_invite(
room_id,
requester.user,
content["medium"],
content["address"],
content["id_server"],
requester,
txn_id,
content["id_access_token"],
)
except ShadowBanError:
# Pretend the request succeeded.
pass
return 200, {}

try:
await self.room_member_handler.do_3pid_invite(
room_id,
requester.user,
content["medium"],
content["address"],
content["id_server"],
requester,
txn_id,
content["id_access_token"],
)
except ShadowBanError:
# Pretend the request succeeded.
pass
return 200, {}

target = requester.user
if membership_action in ["invite", "ban", "unban", "kick"]:
Expand Down