feat: admin impersonates a user (#38614)

* fix #3631
* fix #21599

by the way, refactored the "profile avatar card" to simplify the code.
This commit is contained in:
wxiaoguang
2026-07-26 17:26:02 +00:00
committed by GitHub
parent 470d34b1de
commit a3caf21440
18 changed files with 278 additions and 238 deletions
+15
View File
@@ -26,6 +26,7 @@ import (
"gitea.dev/modules/web"
"gitea.dev/routers/web/explore"
user_setting "gitea.dev/routers/web/user/setting"
auth_service "gitea.dev/services/auth"
"gitea.dev/services/context"
"gitea.dev/services/forms"
"gitea.dev/services/mailer"
@@ -460,6 +461,20 @@ func EditUserPost(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
}
func ImpersonateUser(ctx *context.Context) {
u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64("userid"))
if err != nil {
ctx.JSONError("unable to get user")
return
}
err = auth_service.ImpersonateUser(ctx.Session, u)
if err != nil {
ctx.ServerError("unable to impersonate user", err)
return
}
ctx.JSONRedirect(setting.AppSubURL + "/user/settings")
}
// DeleteUser response for deleting a user
func DeleteUser(ctx *context.Context) {
u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64("userid"))