Check for not allowed errors on send_leave

This commit is contained in:
Kegan Dougal 2021-07-19 10:55:24 +01:00
parent 77d439dddf
commit 09eb86b9ec

View file

@ -22,6 +22,7 @@ import (
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/sirupsen/logrus"
) )
// MakeLeave implements the /make_leave API // MakeLeave implements the /make_leave API
@ -259,16 +260,27 @@ func SendLeave(
// Send the events to the room server. // Send the events to the room server.
// We are responsible for notifying other servers that the user has left // We are responsible for notifying other servers that the user has left
// the room, so set SendAsServer to cfg.Matrix.ServerName // the room, so set SendAsServer to cfg.Matrix.ServerName
if err = api.SendEvents( var response api.InputRoomEventsResponse
httpReq.Context(), rsAPI, rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
api.KindNew, InputRoomEvents: []api.InputRoomEvent{
[]*gomatrixserverlib.HeaderedEvent{ {
event.Headered(verRes.RoomVersion), Kind: api.KindNew,
Event: event.Headered(verRes.RoomVersion),
AuthEventIDs: event.AuthEventIDs(),
SendAsServer: string(cfg.Matrix.ServerName),
TransactionID: nil,
}, },
cfg.Matrix.ServerName, },
nil, }, &response)
); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed") if response.ErrMsg != "" {
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("producer.SendEvents failed")
if response.NotAllowed {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.Forbidden(response.ErrMsg),
}
}
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }