mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-20 01:34:18 -05:00
Return non-room events from guest /events calls
This commit is contained in:
parent
78f6010207
commit
468a2ed4ec
@ -14,6 +14,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
from synapse.api.constants import EventTypes
|
||||||
|
from synapse.api.errors import AuthError
|
||||||
|
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
from synapse.util.async import run_on_reactor, ObservableDeferred
|
from synapse.util.async import run_on_reactor, ObservableDeferred
|
||||||
@ -346,9 +348,9 @@ class Notifier(object):
|
|||||||
|
|
||||||
room_ids = []
|
room_ids = []
|
||||||
if is_guest:
|
if is_guest:
|
||||||
# TODO(daniel): Deal with non-room events too
|
|
||||||
only_room_events = True
|
|
||||||
if guest_room_id:
|
if guest_room_id:
|
||||||
|
if not self._is_world_readable(guest_room_id):
|
||||||
|
raise AuthError(403, "Guest access not allowed")
|
||||||
room_ids = [guest_room_id]
|
room_ids = [guest_room_id]
|
||||||
else:
|
else:
|
||||||
rooms = yield self.store.get_rooms_for_user(user.to_string())
|
rooms = yield self.store.get_rooms_for_user(user.to_string())
|
||||||
@ -361,6 +363,7 @@ class Notifier(object):
|
|||||||
|
|
||||||
events = []
|
events = []
|
||||||
end_token = from_token
|
end_token = from_token
|
||||||
|
|
||||||
for name, source in self.event_sources.sources.items():
|
for name, source in self.event_sources.sources.items():
|
||||||
keyname = "%s_key" % name
|
keyname = "%s_key" % name
|
||||||
before_id = getattr(before_token, keyname)
|
before_id = getattr(before_token, keyname)
|
||||||
@ -377,7 +380,7 @@ class Notifier(object):
|
|||||||
room_ids=room_ids,
|
room_ids=room_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_guest:
|
if name == "room":
|
||||||
room_member_handler = self.hs.get_handlers().room_member_handler
|
room_member_handler = self.hs.get_handlers().room_member_handler
|
||||||
new_events = yield room_member_handler._filter_events_for_client(
|
new_events = yield room_member_handler._filter_events_for_client(
|
||||||
user.to_string(),
|
user.to_string(),
|
||||||
@ -403,6 +406,17 @@ class Notifier(object):
|
|||||||
|
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def _is_world_readable(self, room_id):
|
||||||
|
state = yield self.hs.get_state_handler().get_current_state(
|
||||||
|
room_id,
|
||||||
|
EventTypes.RoomHistoryVisibility
|
||||||
|
)
|
||||||
|
if state and "history_visibility" in state.content:
|
||||||
|
defer.returnValue(state.content["history_visibility"] == "world_readable")
|
||||||
|
else:
|
||||||
|
defer.returnValue(False)
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def remove_expired_streams(self):
|
def remove_expired_streams(self):
|
||||||
time_now_ms = self.clock.time_msec()
|
time_now_ms = self.clock.time_msec()
|
||||||
|
@ -321,6 +321,9 @@ class PresenceEventStreamTestCase(unittest.TestCase):
|
|||||||
hs.handlers.room_member_handler.get_room_members = (
|
hs.handlers.room_member_handler.get_room_members = (
|
||||||
lambda r: self.room_members if r == "a-room" else []
|
lambda r: self.room_members if r == "a-room" else []
|
||||||
)
|
)
|
||||||
|
hs.handlers.room_member_handler._filter_events_for_client = (
|
||||||
|
lambda user_id, events, **kwargs: events
|
||||||
|
)
|
||||||
|
|
||||||
self.mock_datastore = hs.get_datastore()
|
self.mock_datastore = hs.get_datastore()
|
||||||
self.mock_datastore.get_app_service_by_token = Mock(return_value=None)
|
self.mock_datastore.get_app_service_by_token = Mock(return_value=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user