支持通知凭据验证后查看并收紧账号权限

This commit is contained in:
xuans committed 2026-09-26 22:16:47 +08:00
1 parent 85feb38c5d
commit a1dc20af85
9 files changed
+240 -29

No files matched your search

+22
View File
@@ -186,6 +186,28 @@ func ReplaceMembership(tx *xorm.Session, userID int, ids []int) error {
type WriteGuard func(*xorm.Session) error
// OwnGuard 只锁定并复核当前账号,不授予管理本人或其他账号的能力。
func OwnGuard(actorID int, role access.Role, sessionVersion, securityVersion int) WriteGuard {
return func(tx *xorm.Session) error {
if tx == nil || actorID <= 0 || !role.Valid() {
return ErrDenied
}
if _, err := tx.ID(actorID).SetExpr("session_version", "session_version").Update(&models.User{}); err != nil {
return err
}
var current models.User
found, err := tx.ID(actorID).Get(&current)
if err != nil {
return err
}
if !found || current.Disabled != 0 || current.MustChangePassword != 0 || current.EffectiveRole() != role ||
current.SessionVersion != sessionVersion || current.SecurityVersion != securityVersion {
return ErrDenied
}
return nil
}
}
func CheckWrite(tx *xorm.Session, guards ...WriteGuard) error {
for _, guard := range guards {
if guard == nil {