Skip to content

Commit

Permalink
pydantic and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Jun 6, 2024
1 parent 7975a81 commit a2bb9e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@

import attr

from synapse._pydantic_compat import HAS_PYDANTIC_V2
from synapse.api.constants import Direction, UserTypes
from synapse.api.errors import Codes, NotFoundError, SynapseError
from synapse.http.servlet import (
RestServlet,
assert_params_in_dict,
parse_and_validate_json_object_from_request,
parse_boolean,
parse_enum,
parse_integer,
Expand All @@ -46,13 +48,20 @@
assert_user_is_admin,
)
from synapse.rest.client._base import client_patterns
from synapse.rest.models import RequestBodyModel
from synapse.storage.databases.main.registration import ExternalIDReuseException
from synapse.storage.databases.main.stats import UserSortOrder
from synapse.types import JsonDict, JsonMapping, UserID

if TYPE_CHECKING:
from synapse.server import HomeServer

if TYPE_CHECKING or HAS_PYDANTIC_V2:
from pydantic.v1 import StrictBool
else:
from pydantic import StrictBool


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -740,6 +749,9 @@ def __init__(self, hs: "HomeServer"):
self.is_mine = hs.is_mine
self.store = hs.get_datastores().main

class PutBody(RequestBodyModel):
suspend: StrictBool

async def on_PUT(
self, request: SynapseRequest, target_user_id: str
) -> Tuple[int, JsonDict]:
Expand All @@ -752,8 +764,8 @@ async def on_PUT(
if not await self.store.get_user_by_id(target_user_id):
raise NotFoundError("User not found")

body = parse_json_object_from_request(request, allow_empty_body=True)
suspend = body.get("suspend", False)
body = parse_and_validate_json_object_from_request(request, self.PutBody)
suspend = body.suspend
await self.store.set_user_suspended_status(target_user_id, suspend)

return HTTPStatus.OK, {f"user_{target_user_id}_suspended": suspend}
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ async def _do(
if event.sender != requester.user.to_string():
raise SynapseError(
403,
"Only events created by the requester may be redacted while account is suspended.",
"You can only redact your own events while account is suspended.",
Codes.USER_ACCOUNT_SUSPENDED,
)

Expand Down

0 comments on commit a2bb9e8

Please sign in to comment.