mirror of
https://github.com/matrix-org/dendrite
synced 2024-12-14 23:32:45 +00:00
506de4bb3d
* Specify interfaces used by appservice, do half of clientapi * convert more deps of clientapi to finer-grained interfaces * Convert mediaapi and rest of clientapi * Somehow this got missed
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package routing
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
|
"github.com/matrix-org/util"
|
|
)
|
|
|
|
func AdminEvacuateRoom(req *http.Request, device *userapi.Device, rsAPI roomserverAPI.ClientRoomserverAPI) util.JSONResponse {
|
|
if device.AccountType != userapi.AccountTypeAdmin {
|
|
return util.JSONResponse{
|
|
Code: http.StatusForbidden,
|
|
JSON: jsonerror.Forbidden("This API can only be used by admin users."),
|
|
}
|
|
}
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
if err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
roomID, ok := vars["roomID"]
|
|
if !ok {
|
|
return util.JSONResponse{
|
|
Code: http.StatusBadRequest,
|
|
JSON: jsonerror.MissingArgument("Expecting room ID."),
|
|
}
|
|
}
|
|
res := &roomserverAPI.PerformAdminEvacuateRoomResponse{}
|
|
rsAPI.PerformAdminEvacuateRoom(
|
|
req.Context(),
|
|
&roomserverAPI.PerformAdminEvacuateRoomRequest{
|
|
RoomID: roomID,
|
|
},
|
|
res,
|
|
)
|
|
if err := res.Error; err != nil {
|
|
return err.JSONResponse()
|
|
}
|
|
return util.JSONResponse{
|
|
Code: 200,
|
|
JSON: map[string]interface{}{
|
|
"affected": res.Affected,
|
|
},
|
|
}
|
|
}
|