mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-01-07 17:07:57 -05:00
Further improvements to requesting the public rooms list on a homeserver which has it set to private (#7368)
This commit is contained in:
parent
b2dba06079
commit
2e8955f4a6
1
changelog.d/7368.bugfix
Normal file
1
changelog.d/7368.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Improve error responses when accessing remote public room lists.
|
@ -883,18 +883,37 @@ class FederationClient(FederationBase):
|
|||||||
|
|
||||||
def get_public_rooms(
|
def get_public_rooms(
|
||||||
self,
|
self,
|
||||||
destination,
|
remote_server: str,
|
||||||
limit=None,
|
limit: Optional[int] = None,
|
||||||
since_token=None,
|
since_token: Optional[str] = None,
|
||||||
search_filter=None,
|
search_filter: Optional[Dict] = None,
|
||||||
include_all_networks=False,
|
include_all_networks: bool = False,
|
||||||
third_party_instance_id=None,
|
third_party_instance_id: Optional[str] = None,
|
||||||
):
|
):
|
||||||
if destination == self.server_name:
|
"""Get the list of public rooms from a remote homeserver
|
||||||
return
|
|
||||||
|
|
||||||
|
Args:
|
||||||
|
remote_server: The name of the remote server
|
||||||
|
limit: Maximum amount of rooms to return
|
||||||
|
since_token: Used for result pagination
|
||||||
|
search_filter: A filter dictionary to send the remote homeserver
|
||||||
|
and filter the result set
|
||||||
|
include_all_networks: Whether to include results from all third party instances
|
||||||
|
third_party_instance_id: Whether to only include results from a specific third
|
||||||
|
party instance
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Deferred[Dict[str, Any]]: The response from the remote server, or None if
|
||||||
|
`remote_server` is the same as the local server_name
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HttpResponseException: There was an exception returned from the remote server
|
||||||
|
SynapseException: M_FORBIDDEN when the remote server has disallowed publicRoom
|
||||||
|
requests over federation
|
||||||
|
|
||||||
|
"""
|
||||||
return self.transport_layer.get_public_rooms(
|
return self.transport_layer.get_public_rooms(
|
||||||
destination,
|
remote_server,
|
||||||
limit,
|
limit,
|
||||||
since_token,
|
since_token,
|
||||||
search_filter,
|
search_filter,
|
||||||
|
@ -15,13 +15,14 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import Membership
|
from synapse.api.constants import Membership
|
||||||
|
from synapse.api.errors import Codes, HttpResponseException, SynapseError
|
||||||
from synapse.api.urls import (
|
from synapse.api.urls import (
|
||||||
FEDERATION_UNSTABLE_PREFIX,
|
FEDERATION_UNSTABLE_PREFIX,
|
||||||
FEDERATION_V1_PREFIX,
|
FEDERATION_V1_PREFIX,
|
||||||
@ -326,18 +327,25 @@ class TransportLayerClient(object):
|
|||||||
@log_function
|
@log_function
|
||||||
def get_public_rooms(
|
def get_public_rooms(
|
||||||
self,
|
self,
|
||||||
remote_server,
|
remote_server: str,
|
||||||
limit,
|
limit: Optional[int] = None,
|
||||||
since_token,
|
since_token: Optional[str] = None,
|
||||||
search_filter=None,
|
search_filter: Optional[Dict] = None,
|
||||||
include_all_networks=False,
|
include_all_networks: bool = False,
|
||||||
third_party_instance_id=None,
|
third_party_instance_id: Optional[str] = None,
|
||||||
):
|
):
|
||||||
|
"""Get the list of public rooms from a remote homeserver
|
||||||
|
|
||||||
|
See synapse.federation.federation_client.FederationClient.get_public_rooms for
|
||||||
|
more information.
|
||||||
|
"""
|
||||||
if search_filter:
|
if search_filter:
|
||||||
# this uses MSC2197 (Search Filtering over Federation)
|
# this uses MSC2197 (Search Filtering over Federation)
|
||||||
path = _create_v1_path("/publicRooms")
|
path = _create_v1_path("/publicRooms")
|
||||||
|
|
||||||
data = {"include_all_networks": "true" if include_all_networks else "false"}
|
data = {
|
||||||
|
"include_all_networks": "true" if include_all_networks else "false"
|
||||||
|
} # type: Dict[str, Any]
|
||||||
if third_party_instance_id:
|
if third_party_instance_id:
|
||||||
data["third_party_instance_id"] = third_party_instance_id
|
data["third_party_instance_id"] = third_party_instance_id
|
||||||
if limit:
|
if limit:
|
||||||
@ -347,9 +355,19 @@ class TransportLayerClient(object):
|
|||||||
|
|
||||||
data["filter"] = search_filter
|
data["filter"] = search_filter
|
||||||
|
|
||||||
response = yield self.client.post_json(
|
try:
|
||||||
destination=remote_server, path=path, data=data, ignore_backoff=True
|
response = yield self.client.post_json(
|
||||||
)
|
destination=remote_server, path=path, data=data, ignore_backoff=True
|
||||||
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
if e.code == 403:
|
||||||
|
raise SynapseError(
|
||||||
|
403,
|
||||||
|
"You are not allowed to view the public rooms list of %s"
|
||||||
|
% (remote_server,),
|
||||||
|
errcode=Codes.FORBIDDEN,
|
||||||
|
)
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
path = _create_v1_path("/publicRooms")
|
path = _create_v1_path("/publicRooms")
|
||||||
|
|
||||||
@ -363,9 +381,19 @@ class TransportLayerClient(object):
|
|||||||
if since_token:
|
if since_token:
|
||||||
args["since"] = [since_token]
|
args["since"] = [since_token]
|
||||||
|
|
||||||
response = yield self.client.get_json(
|
try:
|
||||||
destination=remote_server, path=path, args=args, ignore_backoff=True
|
response = yield self.client.get_json(
|
||||||
)
|
destination=remote_server, path=path, args=args, ignore_backoff=True
|
||||||
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
if e.code == 403:
|
||||||
|
raise SynapseError(
|
||||||
|
403,
|
||||||
|
"You are not allowed to view the public rooms list of %s"
|
||||||
|
% (remote_server,),
|
||||||
|
errcode=Codes.FORBIDDEN,
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user