-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MSC4185: Event Visibility API #17973
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Implement MSC4185: Event Visibility API. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright 2024 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. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
from http import HTTPStatus | ||
from typing import TYPE_CHECKING, Tuple | ||
|
||
from synapse.api.errors import ( | ||
Codes, | ||
SynapseError, | ||
) | ||
from synapse.http.server import HttpServer | ||
from synapse.http.servlet import RestServlet | ||
from synapse.http.site import SynapseRequest | ||
from synapse.visibility import filter_events_for_client | ||
|
||
from ._base import client_patterns | ||
|
||
if TYPE_CHECKING: | ||
from synapse.server import HomeServer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AppserviceEventVisibilityrestServlet(RestServlet): | ||
PATTERNS = client_patterns( | ||
"/net.tadzik/appservice/(?P<appservice_id>[^/]*)/can_user_see_event/(?P<room_id>[^/]*)/(?P<user_id>[^/]*)/(?P<event_id>[^/]*)$", | ||
unstable=True, | ||
releases=(), | ||
) | ||
|
||
def __init__(self, hs: "HomeServer"): | ||
super().__init__() | ||
self.auth = hs.get_auth() | ||
self.store = hs.get_datastores().main | ||
self._storage_controllers = hs.get_storage_controllers() | ||
|
||
async def on_GET( | ||
self, request: SynapseRequest, appservice_id: str, room_id: str, user_id: str, event_id: str | ||
) -> Tuple[int, bool]: | ||
logger.info('on_GET') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftover debug log |
||
requester = await self.auth.get_user_by_req(request) | ||
|
||
if not requester.app_service: | ||
raise SynapseError( | ||
HTTPStatus.FORBIDDEN, | ||
"Only application services can use the /can_user_see_event endpoint", | ||
Codes.FORBIDDEN, | ||
) | ||
elif requester.app_service.id != appservice_id: | ||
raise SynapseError( | ||
HTTPStatus.FORBIDDEN, | ||
"Mismatching application service ID in path", | ||
Codes.FORBIDDEN, | ||
) | ||
|
||
event = await self.store.get_event(event_id, check_room_id=room_id) | ||
filtered = await filter_events_for_client(self._storage_controllers, user_id, [event]) | ||
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to have some sanity check test cases. We don't need to re-test every scenario that |
||
|
||
return HTTPStatus.OK, bool(filtered) | ||
|
||
def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: | ||
if hs.config.experimental.msc4185_enabled: | ||
AppserviceEventVisibilityrestServlet(hs).register(http_server) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,8 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: | |
"fi.mau.msc2815": self.config.experimental.msc2815_enabled, | ||
# Adds a ping endpoint for appservices to check HS->AS connection | ||
"fi.mau.msc2659.stable": True, # TODO: remove when "v1.7" is added above | ||
# Adds Event visibility API | ||
"net.tadzik.msc4185": self.config.experimental.msc4185_enabled, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the |
||
# TODO: this is no longer needed once unstable MSC3882 does not need to be supported: | ||
"org.matrix.msc3882": self.config.auth.login_via_existing_enabled, | ||
# Adds support for remotely enabling/disabling pushers, as per MSC3881 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the alternative mentioned in matrix-org/matrix-spec-proposals#4185 (comment) cover your use case? Feels like a new endpoint isn't necessary