2022-04-29 10:10:08 +02:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2022-05-05 14:17:38 +02:00
|
|
|
func AdminEvacuateRoom(req *http.Request, device *userapi.Device, rsAPI roomserverAPI.ClientRoomserverAPI) util.JSONResponse {
|
2022-04-29 10:10:08 +02:00
|
|
|
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{}
|
2022-08-11 16:29:33 +02:00
|
|
|
if err := rsAPI.PerformAdminEvacuateRoom(
|
2022-04-29 10:10:08 +02:00
|
|
|
req.Context(),
|
|
|
|
&roomserverAPI.PerformAdminEvacuateRoomRequest{
|
|
|
|
RoomID: roomID,
|
|
|
|
},
|
|
|
|
res,
|
2022-08-11 16:29:33 +02:00
|
|
|
); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-04-29 10:10:08 +02:00
|
|
|
if err := res.Error; err != nil {
|
|
|
|
return err.JSONResponse()
|
|
|
|
}
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 200,
|
|
|
|
JSON: map[string]interface{}{
|
|
|
|
"affected": res.Affected,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2022-06-29 16:29:39 +02:00
|
|
|
|
|
|
|
func AdminEvacuateUser(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)
|
|
|
|
}
|
|
|
|
userID, ok := vars["userID"]
|
|
|
|
if !ok {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.MissingArgument("Expecting user ID."),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res := &roomserverAPI.PerformAdminEvacuateUserResponse{}
|
2022-08-11 16:29:33 +02:00
|
|
|
if err := rsAPI.PerformAdminEvacuateUser(
|
2022-06-29 16:29:39 +02:00
|
|
|
req.Context(),
|
|
|
|
&roomserverAPI.PerformAdminEvacuateUserRequest{
|
|
|
|
UserID: userID,
|
|
|
|
},
|
|
|
|
res,
|
2022-08-11 16:29:33 +02:00
|
|
|
); err != nil {
|
|
|
|
return jsonerror.InternalAPIError(req.Context(), err)
|
|
|
|
}
|
2022-06-29 16:29:39 +02:00
|
|
|
if err := res.Error; err != nil {
|
|
|
|
return err.JSONResponse()
|
|
|
|
}
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 200,
|
|
|
|
JSON: map[string]interface{}{
|
|
|
|
"affected": res.Affected,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|