支持通知凭据验证后查看并收紧账号权限
This commit is contained in:
1 parent
85feb38c5d
commit
a1dc20af85
9 files changed
+240
-29
No files matched your search
@@ -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(¤t)
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user