diff --git a/clientapi/routing/admin.go b/clientapi/routing/admin.go index d9ef5882..be865c39 100644 --- a/clientapi/routing/admin.go +++ b/clientapi/routing/admin.go @@ -753,6 +753,42 @@ func AdminUserDevicesDelete( } } +func AdminDeactivateAccount( + req *http.Request, + userAPI userapi.ClientUserAPI, + cfg *config.ClientAPI, +) util.JSONResponse { + logger := util.GetLogger(req.Context()) + vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) + if err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + userID, _ := vars["userID"] + local, domain, err := userutil.ParseUsernameParam(userID, cfg.Matrix) + if err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + + // TODO: "erase" field must also be processed here + // see https://github.com/element-hq/synapse/blob/develop/docs/admin_api/user_admin_api.md#deactivate-account + + var rs api.PerformAccountDeactivationResponse + if err := userAPI.PerformAccountDeactivation(req.Context(), &api.PerformAccountDeactivationRequest{ + Localpart: local, ServerName: domain, + }, &rs); err != nil { + logger.WithError(err).Error("userAPI.PerformDeviceDeletion failed") + return util.JSONResponse{ + Code: http.StatusInternalServerError, + JSON: spec.InternalServerError{}, + } + } + + return util.JSONResponse{ + Code: http.StatusOK, + JSON: struct{}{}, + } +} + func AdminAllowCrossSigningReplacementWithoutUIA( req *http.Request, userAPI userapi.ClientUserAPI, diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 651a863d..0e672f50 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -342,7 +342,10 @@ func Setup( httputil.MakeServiceAdminAPI("admin_username_available", m.AdminToken, func(r *http.Request) util.JSONResponse { return AdminCheckUsernameAvailable(r, userAPI, cfg) })).Methods(http.MethodGet) - + synapseAdminRouter.Handle("/admin/v1/deactivate/{userID}", + httputil.MakeServiceAdminAPI("admin_deactivate_user", m.AdminToken, func(r *http.Request) util.JSONResponse { + return AdminDeactivateAccount(r, userAPI, cfg) + })).Methods(http.MethodPost) synapseAdminRouter.Handle("/admin/v2/users/{userID}", httputil.MakeServiceAdminAPI("admin_manage_user", m.AdminToken, func(r *http.Request) util.JSONResponse { switch r.Method {