完善掉线诊断并优化二维码加载
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"hfb_sys/backend/internal/auditlog"
|
||||
"hfb_sys/backend/internal/logging"
|
||||
"hfb_sys/backend/internal/model"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
@@ -125,7 +127,7 @@ func (r *Repository) Delete(ctx context.Context, id uint64) error {
|
||||
if err := tx.Delete(&model.Role{}, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return r.bumpAdminTokenVersions(tx, adminIDs)
|
||||
return r.bumpAdminTokenVersions(tx, ctx, adminIDs, "role_deleted")
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -161,7 +163,7 @@ func (r *Repository) AssignPermissions(ctx context.Context, roleID uint64, permI
|
||||
return err
|
||||
}
|
||||
}
|
||||
return r.bumpAdminTokenVersions(tx, adminIDs)
|
||||
return r.bumpAdminTokenVersions(tx, ctx, adminIDs, "role_permissions_changed")
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -218,13 +220,33 @@ func (r *Repository) adminIDsByRole(ctx context.Context, roleID uint64) ([]uint6
|
||||
return ids, err
|
||||
}
|
||||
|
||||
func (r *Repository) bumpAdminTokenVersions(tx *gorm.DB, adminIDs []uint64) error {
|
||||
func (r *Repository) bumpAdminTokenVersions(tx *gorm.DB, ctx context.Context, adminIDs []uint64, reason string) error {
|
||||
if len(adminIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
return tx.Model(&model.AdminUser{}).
|
||||
if err := tx.Model(&model.AdminUser{}).
|
||||
Where("id IN ?", adminIDs).
|
||||
UpdateColumn("token_version", gorm.Expr("token_version + 1")).Error
|
||||
UpdateColumn("token_version", gorm.Expr("token_version + 1")).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
for _, adminID := range adminIDs {
|
||||
bizID := adminID
|
||||
if err := auditlog.Append(tx, auditlog.Entry{
|
||||
ActorType: "admin",
|
||||
ActorID: logging.AdminIDFromContext(ctx),
|
||||
Action: "auth.token_version.bump",
|
||||
BizType: "admin_user",
|
||||
BizID: &bizID,
|
||||
Meta: auditlog.Meta{RequestID: logging.RequestIDFromContext(ctx)},
|
||||
Detail: map[string]any{
|
||||
"target_admin_id": adminID,
|
||||
"reason": reason,
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) invalidateAdminPermCaches(ctx context.Context, adminIDs []uint64) {
|
||||
|
||||
Reference in New Issue
Block a user