优化
This commit is contained in:
+12
-12
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (r *accessRepo) strictAuthorityIDs(ctx context.Context, actorID uint) (map[uint]bool, error) {
|
||||
func (r *authorityAccessRepo) strictAuthorityIDs(ctx context.Context, actorID uint) (map[uint]bool, error) {
|
||||
allowed := make(map[uint]bool)
|
||||
if actorID == 0 {
|
||||
return allowed, nil
|
||||
@@ -46,7 +46,7 @@ func (r *accessRepo) strictAuthorityIDs(ctx context.Context, actorID uint) (map[
|
||||
return allowed, nil
|
||||
}
|
||||
|
||||
func (r *accessRepo) checkAuthorityIDAuth(ctx context.Context, targetID uint) error {
|
||||
func (r *authorityAccessRepo) checkAuthorityIDAuth(ctx context.Context, targetID uint) error {
|
||||
config := r.data.runtime.Admin()
|
||||
if config == nil || config.System == nil || !config.System.UseStrictAuth {
|
||||
return nil
|
||||
@@ -65,7 +65,7 @@ func (r *accessRepo) checkAuthorityIDAuth(ctx context.Context, targetID uint) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *accessRepo) CreateAuthority(ctx context.Context, value *biz.Authority) error {
|
||||
func (r *authorityAccessRepo) CreateAuthority(ctx context.Context, value *biz.Authority) error {
|
||||
config := r.data.runtime.Admin()
|
||||
if config != nil && config.System != nil && config.System.UseStrictAuth && (value.ParentID == nil || *value.ParentID == 0) {
|
||||
if actor, ok := biz.ActorFromContext(ctx); ok {
|
||||
@@ -104,7 +104,7 @@ func (r *accessRepo) CreateAuthority(ctx context.Context, value *biz.Authority)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func (r *accessRepo) CopyAuthority(ctx context.Context, sourceID uint, value *biz.Authority) error {
|
||||
func (r *authorityAccessRepo) CopyAuthority(ctx context.Context, sourceID uint, value *biz.Authority) error {
|
||||
return r.data.gormDB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
config := r.data.runtime.Admin()
|
||||
actor, hasActor := biz.ActorFromContext(ctx)
|
||||
@@ -179,10 +179,10 @@ func (r *accessRepo) CopyAuthority(ctx context.Context, sourceID uint, value *bi
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func (r *accessRepo) UpdateAuthority(ctx context.Context, value *biz.Authority) error {
|
||||
func (r *authorityAccessRepo) UpdateAuthority(ctx context.Context, value *biz.Authority) error {
|
||||
return r.data.gormDB.WithContext(ctx).Model(&authorityPO{}).Where("authority_id = ?", value.AuthorityID).Updates(map[string]any{"authority_name": value.AuthorityName, "parent_id": value.ParentID, "data_scope": value.DataScope, "default_router": value.DefaultRouter}).Error
|
||||
}
|
||||
func (r *accessRepo) DeleteAuthority(ctx context.Context, id uint) error {
|
||||
func (r *authorityAccessRepo) DeleteAuthority(ctx context.Context, id uint) error {
|
||||
if id == 888 {
|
||||
return errors.New("不能删除超级管理员")
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func (r *accessRepo) DeleteAuthority(ctx context.Context, id uint) error {
|
||||
return tx.Delete(&authorityPO{}, "authority_id = ?", id).Error
|
||||
})
|
||||
}
|
||||
func (r *accessRepo) ListAuthorities(ctx context.Context) ([]*biz.Authority, error) {
|
||||
func (r *authorityAccessRepo) ListAuthorities(ctx context.Context) ([]*biz.Authority, error) {
|
||||
var pos []authorityPO
|
||||
if err := r.data.gormDB.WithContext(ctx).Order("authority_id").Find(&pos).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -245,7 +245,7 @@ func (r *accessRepo) ListAuthorities(ctx context.Context) ([]*biz.Authority, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (r *accessRepo) SetAuthorityUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
func (r *authorityAccessRepo) SetAuthorityUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
return r.data.gormDB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var oldIDs []uint
|
||||
if err := tx.Model(&userAuthorityPO{}).Where("sys_authority_authority_id = ?", id).Pluck("sys_user_id", &oldIDs).Error; err != nil {
|
||||
@@ -287,12 +287,12 @@ func (r *accessRepo) SetAuthorityUsers(ctx context.Context, id uint, ids []uint)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func (r *accessRepo) AuthorityUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
func (r *authorityAccessRepo) AuthorityUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
var ids []uint
|
||||
err := r.data.gormDB.WithContext(ctx).Model(&userAuthorityPO{}).Where("sys_authority_authority_id = ?", id).Pluck("sys_user_id", &ids).Error
|
||||
return ids, err
|
||||
}
|
||||
func (r *accessRepo) SetDataScope(ctx context.Context, id uint, scope int, deptIDs []uint) error {
|
||||
func (r *authorityAccessRepo) SetDataScope(ctx context.Context, id uint, scope int, deptIDs []uint) error {
|
||||
return r.data.gormDB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&authorityPO{}).Where("authority_id = ?", id).Update("data_scope", scope).Error; err != nil {
|
||||
return err
|
||||
@@ -312,12 +312,12 @@ func (r *accessRepo) SetDataScope(ctx context.Context, id uint, scope int, deptI
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func (r *accessRepo) DataScopeDepartmentIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
func (r *authorityAccessRepo) DataScopeDepartmentIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
var ids []uint
|
||||
err := r.data.gormDB.WithContext(ctx).Model(&authorityDepartmentPO{}).Where("authority_id = ?", id).Pluck("department_id", &ids).Error
|
||||
return ids, err
|
||||
}
|
||||
func (r *accessRepo) ResolveDataScope(ctx context.Context, authorityID, userID uint) (biz.DataScope, error) {
|
||||
func (r *authorityAccessRepo) ResolveDataScope(ctx context.Context, authorityID, userID uint) (biz.DataScope, error) {
|
||||
identity := biz.DataScope{UserID: userID, AuthorityID: authorityID}
|
||||
var user userPO
|
||||
_ = r.data.gormDB.WithContext(ctx).Select("id", "dept_id").First(&user, userID).Error
|
||||
|
||||
Reference in New Issue
Block a user