Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6329 from matrix-org/babolivier/context_filters
Browse files Browse the repository at this point in the history
* commit 'c530f9af4':
  Un-remove room purge test
  Incorporate review
  Format changelog
  Update changelog since this isn't going to be featured in 1.6.0
  Also filter state events
  Only filter if a filter was provided
  Update copyright
  Lint
  Update copyrights
  Changelog
  Add tests for /search
  Merge labels tests for /context and /messages
  Add test case
  Filter events_before and events_after in /context requests
  • Loading branch information
anoadragon453 committed Mar 19, 2020
2 parents 0d0b33b + c530f9a commit 00f1c3b
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 103 deletions.
1 change: 1 addition & 0 deletions changelog.d/6329.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly apply the event filter to the `state`, `events_before` and `events_after` fields in the response to `/context` requests.
3 changes: 2 additions & 1 deletion synapse/api/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018 New Vector Ltd
# Copyright 2018-2019 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018-2019 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
14 changes: 12 additions & 2 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2014 - 2016 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
# Copyright 2018-2019 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -927,6 +928,10 @@ def filter_evts(events):
room_id, event_id, before_limit, after_limit, event_filter
)

if event_filter:
results["events_before"] = event_filter.filter(results["events_before"])
results["events_after"] = event_filter.filter(results["events_after"])

results["events_before"] = yield filter_evts(results["events_before"])
results["events_after"] = yield filter_evts(results["events_after"])
results["event"] = event
Expand Down Expand Up @@ -955,7 +960,12 @@ def filter_evts(events):
state = yield self.state_store.get_state_for_events(
[last_event_id], state_filter=state_filter
)
results["state"] = list(state[last_event_id].values())

state_events = list(state[last_event_id].values())
if event_filter:
state_events = event_filter.filter(state_events)

results["state"] = state_events

# We use a dummy token here as we only care about the room portion of
# the token, which we replace.
Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/client/versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018-2019 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions synapse/storage/data_stores/main/stream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018-2019 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_filtering.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018-2019 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 00f1c3b

Please sign in to comment.