|
33 | 33 | import twisted.web.http |
34 | 34 | from twisted.internet.defer import Deferred |
35 | 35 |
|
| 36 | +from synapse import event_auth |
36 | 37 | from synapse.api.constants import EventTypes, HistoryVisibility, Membership |
37 | 38 | from synapse.api.errors import ( |
38 | 39 | Codes, |
|
71 | 72 | from synapse.media.url_previewer import UrlPreviewer |
72 | 73 | from synapse.metrics.background_process_metrics import run_as_background_process |
73 | 74 | from synapse.replication.http.media import ReplicationCopyMediaServlet |
| 75 | +from synapse.state import CREATE_KEY, POWER_KEY |
74 | 76 | from synapse.storage.databases.main.media_repository import ( |
75 | 77 | LocalMedia, |
76 | 78 | MediaRestrictions, |
@@ -111,6 +113,7 @@ def __init__(self, hs: "HomeServer"): |
111 | 113 | self.clock = hs.get_clock() |
112 | 114 | self.server_name = hs.hostname |
113 | 115 | self.store = hs.get_datastores().main |
| 116 | + self._storage_controllers = hs.get_storage_controllers() |
114 | 117 | self._is_mine_server_name = hs.is_mine_server_name |
115 | 118 | self.msc3911_config = hs.config.experimental.msc3911 |
116 | 119 |
|
@@ -363,6 +366,32 @@ async def is_media_visible( |
363 | 366 | # from this restriction |
364 | 367 | raise NotFoundError() |
365 | 368 |
|
| 369 | + # Which means a bypass was requested |
| 370 | + if not redacted_media_bypass_config.is_admin: |
| 371 | + # Lifted this directly from RoomEventServlet for msc2815 |
| 372 | + auth_events = ( |
| 373 | + await self._storage_controllers.state.get_current_state( |
| 374 | + event_base.room_id, |
| 375 | + StateFilter.from_types( |
| 376 | + [ |
| 377 | + POWER_KEY, |
| 378 | + CREATE_KEY, |
| 379 | + ] |
| 380 | + ), |
| 381 | + ) |
| 382 | + ) |
| 383 | + |
| 384 | + redact_level = event_auth.get_named_level(auth_events, "redact", 50) |
| 385 | + user_level = event_auth.get_user_power_level( |
| 386 | + requesting_user.to_string(), auth_events |
| 387 | + ) |
| 388 | + if user_level < redact_level: |
| 389 | + raise SynapseError( |
| 390 | + 403, |
| 391 | + "You don't have permission to view redacted events in this room.", |
| 392 | + errcode=Codes.FORBIDDEN, |
| 393 | + ) |
| 394 | + |
366 | 395 | if event_base.is_state(): |
367 | 396 | # The standard event visibility utility, filter_events_for_client(), |
368 | 397 | # does not seem to meet the needs of a good UX when restricting and |
|
0 commit comments