summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/rest/client/pusher.py16
-rw-r--r--synapse/rest/synapse/client/__init__.py5
-rw-r--r--synapse/rest/synapse/client/unsubscribe.py88
-rw-r--r--tests/push/test_email.py1
4 files changed, 1 insertions, 109 deletions
diff --git a/synapse/rest/client/pusher.py b/synapse/rest/client/pusher.py

index a455f95a26..2463b3b38c 100644 --- a/synapse/rest/client/pusher.py +++ b/synapse/rest/client/pusher.py
@@ -34,7 +34,6 @@ from synapse.http.site import SynapseRequest from synapse.push import PusherConfigException from synapse.rest.admin.experimental_features import ExperimentalFeature from synapse.rest.client._base import client_patterns -from synapse.rest.synapse.client.unsubscribe import UnsubscribeResource from synapse.types import JsonDict if TYPE_CHECKING: @@ -161,21 +160,6 @@ class PushersSetRestServlet(RestServlet): return 200, {} -class LegacyPushersRemoveRestServlet(UnsubscribeResource, RestServlet): - """ - A servlet to handle legacy "email unsubscribe" links, forwarding requests to the ``UnsubscribeResource`` - - This should be kept for some time, so unsubscribe links in past emails stay valid. - """ - - PATTERNS = client_patterns("/pushers/remove$", releases=[], v1=False, unstable=True) - - async def on_GET(self, request: SynapseRequest) -> None: - # Forward the request to the UnsubscribeResource - await self._async_render(request) - - def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: PushersRestServlet(hs).register(http_server) PushersSetRestServlet(hs).register(http_server) - LegacyPushersRemoveRestServlet(hs).register(http_server) diff --git a/synapse/rest/synapse/client/__init__.py b/synapse/rest/synapse/client/__init__.py
index 3afeb97be2..982b6c0e7e 100644 --- a/synapse/rest/synapse/client/__init__.py +++ b/synapse/rest/synapse/client/__init__.py
@@ -29,7 +29,6 @@ from synapse.rest.synapse.client.pick_idp import PickIdpResource from synapse.rest.synapse.client.pick_username import pick_username_resource from synapse.rest.synapse.client.rendezvous import MSC4108RendezvousSessionResource from synapse.rest.synapse.client.sso_register import SsoRegisterResource -from synapse.rest.synapse.client.unsubscribe import UnsubscribeResource if TYPE_CHECKING: from synapse.server import HomeServer @@ -50,9 +49,7 @@ def build_synapse_client_resource_tree(hs: "HomeServer") -> Mapping[str, Resourc "/_synapse/client/pick_idp": PickIdpResource(hs), "/_synapse/client/pick_username": pick_username_resource(hs), "/_synapse/client/new_user_consent": NewUserConsentResource(hs), - "/_synapse/client/sso_register": SsoRegisterResource(hs), - # Unsubscribe to notification emails link - "/_synapse/client/unsubscribe": UnsubscribeResource(hs), + "/_synapse/client/sso_register": SsoRegisterResource(hs) } # Expose the JWKS endpoint if OAuth2 delegation is enabled diff --git a/synapse/rest/synapse/client/unsubscribe.py b/synapse/rest/synapse/client/unsubscribe.py deleted file mode 100644
index 6d4bd9f2ed..0000000000 --- a/synapse/rest/synapse/client/unsubscribe.py +++ /dev/null
@@ -1,88 +0,0 @@ -# -# This file is licensed under the Affero General Public License (AGPL) version 3. -# -# Copyright 2022 The Matrix.org Foundation C.I.C. -# Copyright (C) 2023 New Vector, Ltd -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# See the GNU Affero General Public License for more details: -# <https://www.gnu.org/licenses/agpl-3.0.html>. -# -# Originally licensed under the Apache License, Version 2.0: -# <http://www.apache.org/licenses/LICENSE-2.0>. -# -# [This file includes modifications made by New Vector Limited] -# -# - -from typing import TYPE_CHECKING - -from synapse.api.errors import StoreError -from synapse.http.server import DirectServeHtmlResource, respond_with_html_bytes -from synapse.http.servlet import parse_string -from synapse.http.site import SynapseRequest - -if TYPE_CHECKING: - from synapse.server import HomeServer - - -class UnsubscribeResource(DirectServeHtmlResource): - """ - To allow pusher to be delete by clicking a link (ie. GET request) - """ - - SUCCESS_HTML = b"<html><body>You have been unsubscribed</body><html>" - - def __init__(self, hs: "HomeServer"): - super().__init__() - self.notifier = hs.get_notifier() - self.auth = hs.get_auth() - self.pusher_pool = hs.get_pusherpool() - self.macaroon_generator = hs.get_macaroon_generator() - - async def _async_render_GET(self, request: SynapseRequest) -> None: - """ - Handle a user opening an unsubscribe link in the browser, either via an - HTML/Text email or via the List-Unsubscribe header. - """ - token = parse_string(request, "access_token", required=True) - app_id = parse_string(request, "app_id", required=True) - pushkey = parse_string(request, "pushkey", required=True) - - user_id = self.macaroon_generator.verify_delete_pusher_token( - token, app_id, pushkey - ) - - try: - await self.pusher_pool.remove_pusher( - app_id=app_id, pushkey=pushkey, user_id=user_id - ) - except StoreError as se: - if se.code != 404: - # This is fine: they're already unsubscribed - raise - - self.notifier.on_new_replication_data() - - respond_with_html_bytes( - request, - 200, - UnsubscribeResource.SUCCESS_HTML, - ) - - async def _async_render_POST(self, request: SynapseRequest) -> None: - """ - Handle a mail user agent POSTing to the unsubscribe URL via the - List-Unsubscribe & List-Unsubscribe-Post headers. - """ - - # TODO Assert that the body has a single field - - # Assert the body has form encoded key/value pair of - # List-Unsubscribe=One-Click. - - await self._async_render_GET(request) diff --git a/tests/push/test_email.py b/tests/push/test_email.py
index 9c9c97901a..66ee6ca20f 100644 --- a/tests/push/test_email.py +++ b/tests/push/test_email.py
@@ -32,7 +32,6 @@ from twisted.test.proto_helpers import MemoryReactor import synapse.rest.admin from synapse.api.errors import Codes, SynapseError from synapse.rest.client import login, room -from synapse.rest.synapse.client.unsubscribe import UnsubscribeResource from synapse.server import HomeServer from synapse.util import Clock