mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-16 14:35:09 +00:00
enhance(admin): show impersonation banner and keep password change with the user (#38924)
Follow-up to https://github.com/go-gitea/gitea/pull/38614 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -228,6 +228,11 @@ func (ctx *Context) DoerNeedTwoFactorAuth() bool {
|
||||
return ctx.Session.Get(session.KeyUserHasTwoFactorAuth) == false
|
||||
}
|
||||
|
||||
// DoerIsImpersonated returns true if the current session is an admin impersonating the doer
|
||||
func (ctx *Context) DoerIsImpersonated() bool {
|
||||
return ctx.Session.Get(session.KeyImpersonatorData) != nil
|
||||
}
|
||||
|
||||
// HasError returns true if error occurs in form validation.
|
||||
// Attention: this function changes ctx.Data and ctx.Flash
|
||||
// If HasError is called, then before Redirect, the error message should be stored by ctx.Flash.Error(ctx.GetErrMsg()) again.
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/htmlutil"
|
||||
"gitea.dev/modules/httplib"
|
||||
"gitea.dev/modules/public"
|
||||
@@ -66,6 +67,14 @@ func (c TemplateContext) CurrentWebTheme() *webtheme.ThemeMetaInfo {
|
||||
return webtheme.GuaranteeGetThemeMetaInfo(themeName)
|
||||
}
|
||||
|
||||
func (c TemplateContext) ImpersonatedUser() *user_model.User {
|
||||
webCtx := GetWebContext(c)
|
||||
if webCtx == nil || webCtx.Doer == nil || !webCtx.DoerIsImpersonated() {
|
||||
return nil
|
||||
}
|
||||
return webCtx.Doer
|
||||
}
|
||||
|
||||
func (c TemplateContext) CurrentWebBanner() *setting.WebBannerType {
|
||||
// Using revision as a simple approach to determine if the banner has been changed after the user dismissed it.
|
||||
// There could be some false-positives because revision can be changed even if the banner isn't.
|
||||
|
||||
Reference in New Issue
Block a user