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

Commit

Permalink
add changelog and mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Jun 2, 2021
1 parent ce5150d commit 9dd518d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/10105.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing type hints to the admin API servlets.
6 changes: 4 additions & 2 deletions synapse/rest/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import logging
import platform
from typing import TYPE_CHECKING, Tuple
from typing import TYPE_CHECKING, Optional, Tuple

import synapse
from synapse.api.errors import Codes, NotFoundError, SynapseError
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, hs: "HomeServer") -> None:
self.auth = hs.get_auth()

async def on_POST(
self, request: SynapseRequest, room_id: str, event_id: str
self, request: SynapseRequest, room_id: str, event_id: Optional[str]
) -> Tuple[int, JsonDict]:
await assert_requester_is_admin(self.auth, request)

Expand All @@ -121,6 +121,8 @@ async def on_POST(
if event.room_id != room_id:
raise SynapseError(400, "Event is for wrong room.")

# RoomStreamToken expects [int] not Optional[int]
assert event.internal_metadata.stream_ordering is not None
room_token = RoomStreamToken(
event.depth, event.internal_metadata.stream_ordering
)
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/admin/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
# limitations under the License.

import re
from typing import Pattern
from typing import Iterable, Pattern

from synapse.api.auth import Auth
from synapse.api.errors import AuthError
from synapse.http.site import SynapseRequest
from synapse.types import UserID


def admin_patterns(path_regex: str, version: str = "v1") -> Pattern[str]:
def admin_patterns(path_regex: str, version: str = "v1") -> Iterable[Pattern]:
"""Returns the list of patterns for an admin endpoint
Args:
Expand Down
9 changes: 4 additions & 5 deletions synapse/rest/admin/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ class QuarantineMediaInRoom(RestServlet):
this server.
"""

PATTERNS = (
admin_patterns("/room/(?P<room_id>[^/]+)/media/quarantine")
+
PATTERNS = [
*admin_patterns("/room/(?P<room_id>[^/]+)/media/quarantine"),
# This path kept around for legacy reasons
admin_patterns("/quarantine_media/(?P<room_id>[^/]+)")
)
*admin_patterns("/quarantine_media/(?P<room_id>[^/]+)"),
]

def __init__(self, hs: "HomeServer") -> None:
self.store = hs.get_datastore()
Expand Down
9 changes: 4 additions & 5 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,12 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:

class WhoisRestServlet(RestServlet):
path_regex = "/whois/(?P<user_id>[^/]*)$"
PATTERNS = (
admin_patterns(path_regex)
+
PATTERNS = [
*admin_patterns(path_regex),
# URL for spec reason
# https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid
client_patterns("/admin" + path_regex, v1=True)
)
*client_patterns("/admin" + path_regex, v1=True),
]

def __init__(self, hs: "HomeServer"):
self.hs = hs
Expand Down

0 comments on commit 9dd518d

Please sign in to comment.