Support the stable API endpoint for MSC3283: new settings in /capabilities endpoint (#11933)

This commit is contained in:
Dirk Klimpel 2022-02-11 10:32:11 +01:00 committed by GitHub
parent 1e12efa1b2
commit d36943c4df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 47 deletions

View File

@ -0,0 +1 @@
Support the stable API endpoint for [MSC3283](https://github.com/matrix-org/matrix-doc/pull/3283): new settings in `/capabilities` endpoint.

View File

@ -100,6 +100,25 @@ to:
Please update any relevant reverse proxy or firewall configurations appropriately. Please update any relevant reverse proxy or firewall configurations appropriately.
## Deprecation of `capability` `org.matrix.msc3283.*`
The `capabilities` of MSC3283 from the REST API `/_matrix/client/r0/capabilities`
becomes stable.
The old `capabilities`
- `org.matrix.msc3283.set_displayname`,
- `org.matrix.msc3283.set_avatar_url` and
- `org.matrix.msc3283.3pid_changes`
are deprecated and scheduled to be removed in Synapse v1.(next+1).0.
The new `capabilities`
- `m.set_displayname`,
- `m.set_avatar_url` and
- `m.3pid_changes`
are now active by default.
# Upgrading to v1.53.0 # Upgrading to v1.53.0
## Dropping support for `webclient` listeners and non-HTTP(S) `web_client_location` ## Dropping support for `webclient` listeners and non-HTTP(S) `web_client_location`

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
from http import HTTPStatus
from typing import TYPE_CHECKING, Tuple from typing import TYPE_CHECKING, Tuple
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, MSC3244_CAPABILITIES from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, MSC3244_CAPABILITIES
@ -54,6 +55,15 @@ class CapabilitiesRestServlet(RestServlet):
}, },
}, },
"m.change_password": {"enabled": change_password}, "m.change_password": {"enabled": change_password},
"m.set_displayname": {
"enabled": self.config.registration.enable_set_displayname
},
"m.set_avatar_url": {
"enabled": self.config.registration.enable_set_avatar_url
},
"m.3pid_changes": {
"enabled": self.config.registration.enable_3pid_changes
},
} }
} }
@ -62,6 +72,9 @@ class CapabilitiesRestServlet(RestServlet):
"org.matrix.msc3244.room_capabilities" "org.matrix.msc3244.room_capabilities"
] = MSC3244_CAPABILITIES ] = MSC3244_CAPABILITIES
# Must be removed in later versions.
# Is only included for migration.
# Also the parts in `synapse/config/experimental.py`.
if self.config.experimental.msc3283_enabled: if self.config.experimental.msc3283_enabled:
response["capabilities"]["org.matrix.msc3283.set_displayname"] = { response["capabilities"]["org.matrix.msc3283.set_displayname"] = {
"enabled": self.config.registration.enable_set_displayname "enabled": self.config.registration.enable_set_displayname
@ -76,7 +89,7 @@ class CapabilitiesRestServlet(RestServlet):
if self.config.experimental.msc3440_enabled: if self.config.experimental.msc3440_enabled:
response["capabilities"]["io.element.thread"] = {"enabled": True} response["capabilities"]["io.element.thread"] = {"enabled": True}
return 200, response return HTTPStatus.OK, response
def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:

View File

@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from http import HTTPStatus
import synapse.rest.admin import synapse.rest.admin
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
from synapse.rest.client import capabilities, login from synapse.rest.client import capabilities, login
@ -28,7 +30,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
] ]
def make_homeserver(self, reactor, clock): def make_homeserver(self, reactor, clock):
self.url = b"/_matrix/client/r0/capabilities" self.url = b"/capabilities"
hs = self.setup_test_homeserver() hs = self.setup_test_homeserver()
self.config = hs.config self.config = hs.config
self.auth_handler = hs.get_auth_handler() self.auth_handler = hs.get_auth_handler()
@ -96,39 +98,20 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
self.assertEqual(channel.code, 200) self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["m.change_password"]["enabled"]) self.assertFalse(capabilities["m.change_password"]["enabled"])
def test_get_change_users_attributes_capabilities_when_msc3283_disabled(self): def test_get_change_users_attributes_capabilities(self):
"""Test that per default msc3283 is disabled server returns `m.change_password`.""" """Test that server returns capabilities by default."""
access_token = self.login(self.localpart, self.password) access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token) channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"] capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200) self.assertEqual(channel.code, HTTPStatus.OK)
self.assertTrue(capabilities["m.change_password"]["enabled"]) self.assertTrue(capabilities["m.change_password"]["enabled"])
self.assertNotIn("org.matrix.msc3283.set_displayname", capabilities) self.assertTrue(capabilities["m.set_displayname"]["enabled"])
self.assertNotIn("org.matrix.msc3283.set_avatar_url", capabilities) self.assertTrue(capabilities["m.set_avatar_url"]["enabled"])
self.assertNotIn("org.matrix.msc3283.3pid_changes", capabilities) self.assertTrue(capabilities["m.3pid_changes"]["enabled"])
@override_config({"experimental_features": {"msc3283_enabled": True}}) @override_config({"enable_set_displayname": False})
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): def test_get_set_displayname_capabilities_displayname_disabled(self):
"""Test if set displayname is disabled that the server responds it.""" """Test if set displayname is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password) access_token = self.login(self.localpart, self.password)
@ -136,15 +119,10 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
channel = self.make_request("GET", self.url, access_token=access_token) channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"] capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200) self.assertEqual(channel.code, HTTPStatus.OK)
self.assertFalse(capabilities["org.matrix.msc3283.set_displayname"]["enabled"]) self.assertFalse(capabilities["m.set_displayname"]["enabled"])
@override_config( @override_config({"enable_set_avatar_url": False})
{
"enable_set_avatar_url": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_get_set_avatar_url_capabilities_avatar_url_disabled(self): def test_get_set_avatar_url_capabilities_avatar_url_disabled(self):
"""Test if set avatar_url is disabled that the server responds it.""" """Test if set avatar_url is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password) access_token = self.login(self.localpart, self.password)
@ -152,24 +130,19 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
channel = self.make_request("GET", self.url, access_token=access_token) channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"] capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200) self.assertEqual(channel.code, HTTPStatus.OK)
self.assertFalse(capabilities["org.matrix.msc3283.set_avatar_url"]["enabled"]) self.assertFalse(capabilities["m.set_avatar_url"]["enabled"])
@override_config( @override_config({"enable_3pid_changes": False})
{ def test_get_change_3pid_capabilities_3pid_disabled(self):
"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.""" """Test if change 3pid is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password) access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token) channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"] capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200) self.assertEqual(channel.code, HTTPStatus.OK)
self.assertFalse(capabilities["org.matrix.msc3283.3pid_changes"]["enabled"]) self.assertFalse(capabilities["m.3pid_changes"]["enabled"])
@override_config({"experimental_features": {"msc3244_enabled": False}}) @override_config({"experimental_features": {"msc3244_enabled": False}})
def test_get_does_not_include_msc3244_fields_when_disabled(self): def test_get_does_not_include_msc3244_fields_when_disabled(self):