mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 04:03:51 +01:00
Run filter_events_for_client
so we don't accidentally mail out events people shouldn't see
This commit is contained in:
parent
4ed1e45869
commit
424a7f48f8
7 changed files with 24 additions and 20 deletions
|
@ -192,7 +192,7 @@ class BaseHandler(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _filter_events_for_client(self, user_id, events, is_peeking=False):
|
def filter_events_for_client(self, user_id, events, is_peeking=False):
|
||||||
"""
|
"""
|
||||||
Check which events a user is allowed to see
|
Check which events a user is allowed to see
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ class MessageHandler(BaseHandler):
|
||||||
"end": next_token.to_string(),
|
"end": next_token.to_string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
events = yield self._filter_events_for_client(
|
events = yield self.filter_events_for_client(
|
||||||
user_id,
|
user_id,
|
||||||
events,
|
events,
|
||||||
is_peeking=(member_event_id is None),
|
is_peeking=(member_event_id is None),
|
||||||
|
@ -483,7 +483,7 @@ class MessageHandler(BaseHandler):
|
||||||
]
|
]
|
||||||
).addErrback(unwrapFirstError)
|
).addErrback(unwrapFirstError)
|
||||||
|
|
||||||
messages = yield self._filter_events_for_client(
|
messages = yield self.filter_events_for_client(
|
||||||
user_id, messages
|
user_id, messages
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ class MessageHandler(BaseHandler):
|
||||||
end_token=stream_token
|
end_token=stream_token
|
||||||
)
|
)
|
||||||
|
|
||||||
messages = yield self._filter_events_for_client(
|
messages = yield self.filter_events_for_client(
|
||||||
user_id, messages, is_peeking=is_peeking
|
user_id, messages, is_peeking=is_peeking
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -700,7 +700,7 @@ class MessageHandler(BaseHandler):
|
||||||
consumeErrors=True,
|
consumeErrors=True,
|
||||||
).addErrback(unwrapFirstError)
|
).addErrback(unwrapFirstError)
|
||||||
|
|
||||||
messages = yield self._filter_events_for_client(
|
messages = yield self.filter_events_for_client(
|
||||||
user_id, messages, is_peeking=is_peeking,
|
user_id, messages, is_peeking=is_peeking,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -449,7 +449,7 @@ class RoomContextHandler(BaseHandler):
|
||||||
now_token = yield self.hs.get_event_sources().get_current_token()
|
now_token = yield self.hs.get_event_sources().get_current_token()
|
||||||
|
|
||||||
def filter_evts(events):
|
def filter_evts(events):
|
||||||
return self._filter_events_for_client(
|
return self.filter_events_for_client(
|
||||||
user.to_string(),
|
user.to_string(),
|
||||||
events,
|
events,
|
||||||
is_peeking=is_guest)
|
is_peeking=is_guest)
|
||||||
|
|
|
@ -172,7 +172,7 @@ class SearchHandler(BaseHandler):
|
||||||
|
|
||||||
filtered_events = search_filter.filter([r["event"] for r in results])
|
filtered_events = search_filter.filter([r["event"] for r in results])
|
||||||
|
|
||||||
events = yield self._filter_events_for_client(
|
events = yield self.filter_events_for_client(
|
||||||
user.to_string(), filtered_events
|
user.to_string(), filtered_events
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ class SearchHandler(BaseHandler):
|
||||||
r["event"] for r in results
|
r["event"] for r in results
|
||||||
])
|
])
|
||||||
|
|
||||||
events = yield self._filter_events_for_client(
|
events = yield self.filter_events_for_client(
|
||||||
user.to_string(), filtered_events
|
user.to_string(), filtered_events
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -281,11 +281,11 @@ class SearchHandler(BaseHandler):
|
||||||
event.room_id, event.event_id, before_limit, after_limit
|
event.room_id, event.event_id, before_limit, after_limit
|
||||||
)
|
)
|
||||||
|
|
||||||
res["events_before"] = yield self._filter_events_for_client(
|
res["events_before"] = yield self.filter_events_for_client(
|
||||||
user.to_string(), res["events_before"]
|
user.to_string(), res["events_before"]
|
||||||
)
|
)
|
||||||
|
|
||||||
res["events_after"] = yield self._filter_events_for_client(
|
res["events_after"] = yield self.filter_events_for_client(
|
||||||
user.to_string(), res["events_after"]
|
user.to_string(), res["events_after"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -681,7 +681,7 @@ class SyncHandler(BaseHandler):
|
||||||
|
|
||||||
if recents is not None:
|
if recents is not None:
|
||||||
recents = sync_config.filter_collection.filter_room_timeline(recents)
|
recents = sync_config.filter_collection.filter_room_timeline(recents)
|
||||||
recents = yield self._filter_events_for_client(
|
recents = yield self.filter_events_for_client(
|
||||||
sync_config.user.to_string(),
|
sync_config.user.to_string(),
|
||||||
recents,
|
recents,
|
||||||
)
|
)
|
||||||
|
@ -702,7 +702,7 @@ class SyncHandler(BaseHandler):
|
||||||
loaded_recents = sync_config.filter_collection.filter_room_timeline(
|
loaded_recents = sync_config.filter_collection.filter_room_timeline(
|
||||||
events
|
events
|
||||||
)
|
)
|
||||||
loaded_recents = yield self._filter_events_for_client(
|
loaded_recents = yield self.filter_events_for_client(
|
||||||
sync_config.user.to_string(),
|
sync_config.user.to_string(),
|
||||||
loaded_recents,
|
loaded_recents,
|
||||||
)
|
)
|
||||||
|
|
|
@ -399,7 +399,7 @@ class Notifier(object):
|
||||||
|
|
||||||
if name == "room":
|
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(),
|
||||||
new_events,
|
new_events,
|
||||||
is_peeking=is_peeking,
|
is_peeking=is_peeking,
|
||||||
|
|
|
@ -155,13 +155,15 @@ class Mailer(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
for n in notifs:
|
for n in notifs:
|
||||||
vars = yield self.get_notif_vars(n, notif_events[n['event_id']], room_state)
|
vars = yield self.get_notif_vars(
|
||||||
|
n, user_id, notif_events[n['event_id']], room_state
|
||||||
|
)
|
||||||
room_vars['notifs'].append(vars)
|
room_vars['notifs'].append(vars)
|
||||||
|
|
||||||
defer.returnValue(room_vars)
|
defer.returnValue(room_vars)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_notif_vars(self, notif, notif_event, room_state):
|
def get_notif_vars(self, notif, user_id, notif_event, room_state):
|
||||||
results = yield self.store.get_events_around(
|
results = yield self.store.get_events_around(
|
||||||
notif['room_id'], notif['event_id'],
|
notif['room_id'], notif['event_id'],
|
||||||
before_limit=CONTEXT_BEFORE, after_limit=0
|
before_limit=CONTEXT_BEFORE, after_limit=0
|
||||||
|
@ -173,15 +175,17 @@ class Mailer(object):
|
||||||
"messages": [],
|
"messages": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
for event in results['events_before']:
|
handler = self.hs.get_handlers().message_handler
|
||||||
|
the_events = yield handler.filter_events_for_client(
|
||||||
|
user_id, results["events_before"]
|
||||||
|
)
|
||||||
|
the_events.append(notif_event)
|
||||||
|
|
||||||
|
for event in the_events:
|
||||||
vars = self.get_message_vars(notif, event, room_state)
|
vars = self.get_message_vars(notif, event, room_state)
|
||||||
if vars is not None:
|
if vars is not None:
|
||||||
ret['messages'].append(vars)
|
ret['messages'].append(vars)
|
||||||
|
|
||||||
vars = self.get_message_vars(notif, notif_event, room_state)
|
|
||||||
if vars is not None:
|
|
||||||
ret['messages'].append(vars)
|
|
||||||
|
|
||||||
defer.returnValue(ret)
|
defer.returnValue(ret)
|
||||||
|
|
||||||
def get_message_vars(self, notif, event, room_state):
|
def get_message_vars(self, notif, event, room_state):
|
||||||
|
|
Loading…
Reference in a new issue