mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 19:49:25 -05:00
Allow guest access if the user provides a list of rooms in the filter
This commit is contained in:
parent
489a4cd1cf
commit
45a9e0ae0c
@ -144,6 +144,9 @@ class FilterCollection(object):
|
|||||||
"include_leave", False
|
"include_leave", False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def list_rooms(self):
|
||||||
|
return self.room_filter.list_rooms()
|
||||||
|
|
||||||
def timeline_limit(self):
|
def timeline_limit(self):
|
||||||
return self.room_timeline_filter.limit()
|
return self.room_timeline_filter.limit()
|
||||||
|
|
||||||
@ -176,6 +179,15 @@ class Filter(object):
|
|||||||
def __init__(self, filter_json):
|
def __init__(self, filter_json):
|
||||||
self.filter_json = filter_json
|
self.filter_json = filter_json
|
||||||
|
|
||||||
|
def list_rooms(self):
|
||||||
|
"""The list of room_id strings this filter restricts the output to
|
||||||
|
or None if the this filter doesn't list the room ids.
|
||||||
|
"""
|
||||||
|
if "rooms" in self.filter_json:
|
||||||
|
return list(set(self.filter_json["rooms"]))
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def check(self, event):
|
def check(self, event):
|
||||||
"""Checks whether the filter matches the given event.
|
"""Checks whether the filter matches the given event.
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
SyncConfig = collections.namedtuple("SyncConfig", [
|
SyncConfig = collections.namedtuple("SyncConfig", [
|
||||||
"user",
|
"user",
|
||||||
|
"is_guest",
|
||||||
"filter",
|
"filter",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -85,7 +85,9 @@ class SyncRestServlet(RestServlet):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request):
|
def on_GET(self, request):
|
||||||
user, token_id, _ = yield self.auth.get_user_by_req(request)
|
user, token_id, is_guest = yield self.auth.get_user_by_req(
|
||||||
|
request, allow_guest=True
|
||||||
|
)
|
||||||
|
|
||||||
timeout = parse_integer(request, "timeout", default=0)
|
timeout = parse_integer(request, "timeout", default=0)
|
||||||
since = parse_string(request, "since")
|
since = parse_string(request, "since")
|
||||||
@ -118,8 +120,14 @@ class SyncRestServlet(RestServlet):
|
|||||||
except:
|
except:
|
||||||
filter = FilterCollection({})
|
filter = FilterCollection({})
|
||||||
|
|
||||||
|
if is_guest and filter.list_rooms() is None:
|
||||||
|
raise SynapseError(
|
||||||
|
400, "Guest users must provide a list of rooms in the filter"
|
||||||
|
)
|
||||||
|
|
||||||
sync_config = SyncConfig(
|
sync_config = SyncConfig(
|
||||||
user=user,
|
user=user,
|
||||||
|
is_guest=is_guest,
|
||||||
filter=filter,
|
filter=filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user