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

Commit

Permalink
Merge pull request #3316 from matrix-org/rav/enforce_report_api
Browse files Browse the repository at this point in the history
Enforce the specified API for report_event
  • Loading branch information
richvdh authored Jul 12, 2018
2 parents 0456e05 + c969754 commit 4c4dd62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/3316.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enforce the specified API for report_event
26 changes: 24 additions & 2 deletions synapse/rest/client/v2_alpha/report_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@

import logging

from six import string_types
from six.moves import http_client

from twisted.internet import defer

from synapse.http.servlet import RestServlet, parse_json_object_from_request
from synapse.api.errors import Codes, SynapseError
from synapse.http.servlet import (
RestServlet,
assert_params_in_request,
parse_json_object_from_request,
)

from ._base import client_v2_patterns

Expand All @@ -42,12 +50,26 @@ def on_POST(self, request, room_id, event_id):
user_id = requester.user.to_string()

body = parse_json_object_from_request(request)
assert_params_in_request(body, ("reason", "score"))

if not isinstance(body["reason"], string_types):
raise SynapseError(
http_client.BAD_REQUEST,
"Param 'reason' must be a string",
Codes.BAD_JSON,
)
if not isinstance(body["score"], int):
raise SynapseError(
http_client.BAD_REQUEST,
"Param 'score' must be an integer",
Codes.BAD_JSON,
)

yield self.store.add_event_report(
room_id=room_id,
event_id=event_id,
user_id=user_id,
reason=body.get("reason"),
reason=body["reason"],
content=body,
received_ts=self.clock.time_msec(),
)
Expand Down

0 comments on commit 4c4dd62

Please sign in to comment.