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

Support MSC3283: Expose set_displayname, set_avatar_url and 3pid_changes in capabilities #10452

Merged
merged 8 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/10452.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for [MSC3283](https://github.com/matrix-org/matrix-doc/pull/3283): Expose enable_set_displayname in capabilities.
3 changes: 3 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ def read_config(self, config: JsonDict, **kwargs):
# MSC3244 (room version capabilities)
self.msc3244_enabled: bool = experimental.get("msc3244_enabled", False)

# MSC3283 (set displayname, avatar_url and change 3pid capabilities)
self.msc3283_enabled: bool = experimental.get("msc3283_enabled", False)

# MSC3266 (room summary api)
self.msc3266_enabled: bool = experimental.get("msc3266_enabled", False)
11 changes: 11 additions & 0 deletions synapse/rest/client/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
"org.matrix.msc3244.room_capabilities"
] = MSC3244_CAPABILITIES

if self.config.experimental.msc3283_enabled:
response["capabilities"]["org.matrix.msc3283.set_displayname"] = {
"enabled": self.config.enable_set_displayname
}
response["capabilities"]["org.matrix.msc3283.set_avatar_url"] = {
"enabled": self.config.enable_set_avatar_url
}
response["capabilities"]["org.matrix.msc3283.3pid_changes"] = {
"enabled": self.config.enable_3pid_changes
}

return 200, response


Expand Down
109 changes: 86 additions & 23 deletions tests/rest/client/v2_alpha/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
def make_homeserver(self, reactor, clock):
self.url = b"/_matrix/client/r0/capabilities"
hs = self.setup_test_homeserver()
self.store = hs.get_datastore()
self.config = hs.config
self.auth_handler = hs.get_auth_handler()
return hs

def prepare(self, reactor, clock, hs):
self.localpart = "user"
self.password = "pass"
self.user = self.register_user(self.localpart, self.password)

def test_check_auth_required(self):
channel = self.make_request("GET", self.url)

self.assertEqual(channel.code, 401)

def test_get_room_version_capabilities(self):
self.register_user("user", "pass")
access_token = self.login("user", "pass")
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
Expand All @@ -57,10 +60,7 @@ def test_get_room_version_capabilities(self):
)

def test_get_change_password_capabilities_password_login(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.login(user, password)
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
Expand All @@ -70,12 +70,9 @@ def test_get_change_password_capabilities_password_login(self):

@override_config({"password_config": {"localdb_enabled": False}})
def test_get_change_password_capabilities_localdb_disabled(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)

Expand All @@ -87,12 +84,9 @@ def test_get_change_password_capabilities_localdb_disabled(self):

@override_config({"password_config": {"enabled": False}})
def test_get_change_password_capabilities_password_disabled(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)

Expand All @@ -102,13 +96,85 @@ def test_get_change_password_capabilities_password_disabled(self):
self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["m.change_password"]["enabled"])

def test_get_change_users_attributes_capabilities_when_msc3283_disabled(self):
"""Test that per default msc3283 is disabled server returns `m.change_password`."""
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]

self.assertEqual(channel.code, 200)
self.assertTrue(capabilities["m.change_password"]["enabled"])
self.assertNotIn("org.matrix.msc3283.set_displayname", capabilities)
self.assertNotIn("org.matrix.msc3283.set_avatar_url", capabilities)
self.assertNotIn("org.matrix.msc3283.3pid_changes", capabilities)

@override_config({"experimental_features": {"msc3283_enabled": True}})
def test_get_change_users_attributes_capabilities_when_msc3283_enabled(self):
"""Test if msc3283 is enabled server returns capabilities."""
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]

self.assertEqual(channel.code, 200)
self.assertTrue(capabilities["m.change_password"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3283.set_displayname"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3283.set_avatar_url"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3283.3pid_changes"]["enabled"])

@override_config(
{
"enable_set_displayname": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_get_set_displayname_capabilities_displayname_disabled(self):
"""Test if set displayname is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]

self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["org.matrix.msc3283.set_displayname"]["enabled"])

@override_config(
{
"enable_set_avatar_url": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_get_set_avatar_url_capabilities_avatar_url_disabled(self):
"""Test if set avatar_url is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]

self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["org.matrix.msc3283.set_avatar_url"]["enabled"])

@override_config(
{
"enable_3pid_changes": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_change_3pid_capabilities_3pid_disabled(self):
"""Test if change 3pid is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password)

channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]

self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["org.matrix.msc3283.3pid_changes"]["enabled"])

def test_get_does_not_include_msc3244_fields_by_default(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)

Expand All @@ -122,12 +188,9 @@ def test_get_does_not_include_msc3244_fields_by_default(self):

@override_config({"experimental_features": {"msc3244_enabled": True}})
def test_get_does_include_msc3244_fields_when_enabled(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)

Expand Down