mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-14 19:22:09 +09:00
feat: Add audit logging (#38189)
Co-authored-by: bircni <bircni@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -68,6 +68,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
audit_model "gitea.dev/models/audit"
|
||||
auth_model "gitea.dev/models/auth"
|
||||
"gitea.dev/models/organization"
|
||||
"gitea.dev/models/perm"
|
||||
@@ -95,6 +96,7 @@ import (
|
||||
"gitea.dev/routers/api/v1/user"
|
||||
"gitea.dev/routers/common"
|
||||
"gitea.dev/services/actions"
|
||||
"gitea.dev/services/audit"
|
||||
"gitea.dev/services/auth"
|
||||
"gitea.dev/services/context"
|
||||
"gitea.dev/services/forms"
|
||||
@@ -124,7 +126,13 @@ func sudo() func(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
log.Trace("Sudo from (%s) to: %s", ctx.Doer.Name, user.Name)
|
||||
|
||||
audit.Record(ctx, audit_model.UserImpersonation, user)
|
||||
|
||||
ctx.Doer = user
|
||||
// keep the audit actor in step with the effective doer, and keep the admin attached to it
|
||||
ctx.Data[middleware.ContextDataKeyImpersonator] = ctx.Data[middleware.ContextDataKeySignedUser]
|
||||
ctx.Data[middleware.ContextDataKeySignedUser] = user
|
||||
} else {
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "Only administrators allowed to sudo.",
|
||||
@@ -1021,6 +1029,7 @@ func Routes() *web.Router {
|
||||
}
|
||||
|
||||
m.AfterRouting(context.APIContexter())
|
||||
m.AfterRouting(common.AuditOrigin(audit_model.OriginAPI))
|
||||
m.AfterRouting(checkDeprecatedAuthMethods)
|
||||
|
||||
// Get user from session if logged in.
|
||||
|
||||
Reference in New Issue
Block a user