aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2024-03-22 22:54:29 +0100
committerGitHub <noreply@github.com>2024-03-22 21:54:29 +0000
commitad0a7d09e89fe18c9e2b08f23f5817a5231c6074 (patch)
tree01ae155c112ac01dce299724790a9db8d999994d /clientapi/routing
parent81f73c9f8df6dd3078a93b6ca978ecbb9c95df16 (diff)
Add getting/deleting single event report (#3344)
Based on https://github.com/matrix-org/dendrite/pull/3342 Adds `GET /_synapse/admin/v1/event_reports/{reportID}` and `DELETE /_synapse/admin/v1/event_reports/{reportID}`
Diffstat (limited to 'clientapi/routing')
-rw-r--r--clientapi/routing/admin.go48
-rw-r--r--clientapi/routing/routing.go22
2 files changed, 69 insertions, 1 deletions
diff --git a/clientapi/routing/admin.go b/clientapi/routing/admin.go
index e91e098a..68e62b08 100644
--- a/clientapi/routing/admin.go
+++ b/clientapi/routing/admin.go
@@ -530,6 +530,54 @@ func GetEventReports(
}
}
+func GetEventReport(req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI, reportID string) util.JSONResponse {
+ parsedReportID, err := strconv.ParseUint(reportID, 10, 64)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusBadRequest,
+ // Given this is an admin endpoint, let them know what didn't work.
+ JSON: spec.InvalidParam(err.Error()),
+ }
+ }
+
+ report, err := rsAPI.QueryAdminEventReport(req.Context(), parsedReportID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.Unknown(err.Error()),
+ }
+ }
+
+ return util.JSONResponse{
+ Code: http.StatusOK,
+ JSON: report,
+ }
+}
+
+func DeleteEventReport(req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI, reportID string) util.JSONResponse {
+ parsedReportID, err := strconv.ParseUint(reportID, 10, 64)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusBadRequest,
+ // Given this is an admin endpoint, let them know what didn't work.
+ JSON: spec.InvalidParam(err.Error()),
+ }
+ }
+
+ err = rsAPI.PerformAdminDeleteEventReport(req.Context(), parsedReportID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.Unknown(err.Error()),
+ }
+ }
+
+ return util.JSONResponse{
+ Code: http.StatusOK,
+ JSON: struct{}{},
+ }
+}
+
func parseUint64OrDefault(input string, defaultValue uint64) uint64 {
v, err := strconv.ParseUint(input, 10, 64)
if err != nil {
diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go
index dc63a2c2..c96c6538 100644
--- a/clientapi/routing/routing.go
+++ b/clientapi/routing/routing.go
@@ -1535,7 +1535,7 @@ func Setup(
).Methods(http.MethodPost, http.MethodOptions)
synapseAdminRouter.Handle("/admin/v1/event_reports",
- httputil.MakeAdminAPI("admin_report_event", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ httputil.MakeAdminAPI("admin_report_events", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
from := parseUint64OrDefault(req.URL.Query().Get("from"), 0)
limit := parseUint64OrDefault(req.URL.Query().Get("limit"), 100)
dir := req.URL.Query().Get("dir")
@@ -1547,4 +1547,24 @@ func Setup(
return GetEventReports(req, rsAPI, from, limit, backwards, userID, roomID)
}),
).Methods(http.MethodGet, http.MethodOptions)
+
+ synapseAdminRouter.Handle("/admin/v1/event_reports/{reportID}",
+ httputil.MakeAdminAPI("admin_report_event", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
+ if err != nil {
+ return util.ErrorResponse(err)
+ }
+ return GetEventReport(req, rsAPI, vars["reportID"])
+ }),
+ ).Methods(http.MethodGet, http.MethodOptions)
+
+ synapseAdminRouter.Handle("/admin/v1/event_reports/{reportID}",
+ httputil.MakeAdminAPI("admin_report_event_delete", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
+ if err != nil {
+ return util.ErrorResponse(err)
+ }
+ return DeleteEventReport(req, rsAPI, vars["reportID"])
+ }),
+ ).Methods(http.MethodDelete, http.MethodOptions)
}