fix
This commit is contained in:
+40
-41
@@ -318,53 +318,52 @@ func (r *accessRepo) DataScopeDepartmentIDs(ctx context.Context, id uint) ([]uin
|
||||
return ids, err
|
||||
}
|
||||
func (r *accessRepo) ResolveDataScope(ctx context.Context, authorityID, userID uint) (biz.DataScope, error) {
|
||||
if authorityID == 888 {
|
||||
return biz.DataScope{All: true}, nil
|
||||
}
|
||||
identity := biz.DataScope{UserID: userID, AuthorityID: authorityID}
|
||||
var user userPO
|
||||
_ = r.data.gormDB.WithContext(ctx).Select("id", "dept_id").First(&user, userID).Error
|
||||
identity.PrimaryDeptID = user.DeptID
|
||||
var authority authorityPO
|
||||
if err := r.data.gormDB.WithContext(ctx).First(&authority, "authority_id = ?", authorityID).Error; err != nil {
|
||||
return biz.DataScope{}, err
|
||||
_ = r.data.gormDB.WithContext(ctx).Select("authority_id", "data_scope").First(&authority, "authority_id = ?", authorityID).Error
|
||||
identity.Scope = authority.DataScope
|
||||
if identity.Scope == 0 {
|
||||
identity.Scope = 1
|
||||
}
|
||||
if authority.DataScope == 1 {
|
||||
return biz.DataScope{All: true}, nil
|
||||
}
|
||||
if authority.DataScope == 4 {
|
||||
return biz.DataScope{OwnerUserID: userID}, nil
|
||||
identity.All = identity.Scope == 1
|
||||
if identity.Scope == 4 {
|
||||
identity.OwnerUserID = userID
|
||||
}
|
||||
var ids []uint
|
||||
if authority.DataScope == 5 {
|
||||
var err error
|
||||
ids, err = r.DataScopeDepartmentIDs(ctx, authorityID)
|
||||
if err != nil {
|
||||
return biz.DataScope{}, err
|
||||
}
|
||||
} else {
|
||||
if err := r.data.gormDB.WithContext(ctx).Model(&userDepartmentPO{}).Where("sys_user_id = ?", userID).Pluck("sys_department_id", &ids).Error; err != nil {
|
||||
return biz.DataScope{}, err
|
||||
}
|
||||
if authority.DataScope == 2 && len(ids) > 0 {
|
||||
var departments []departmentPO
|
||||
if err := r.data.gormDB.WithContext(ctx).Find(&departments).Error; err != nil {
|
||||
return biz.DataScope{}, err
|
||||
}
|
||||
selected := make(map[uint]bool, len(ids))
|
||||
for _, id := range ids {
|
||||
selected[id] = true
|
||||
}
|
||||
for _, department := range departments {
|
||||
for _, part := range strings.Split(department.Ancestors, ",") {
|
||||
value, _ := strconv.ParseUint(part, 10, 64)
|
||||
if selected[uint(value)] {
|
||||
selected[department.ID] = true
|
||||
break
|
||||
}
|
||||
_ = r.data.gormDB.WithContext(ctx).Model(&userDepartmentPO{}).Where("sys_user_id = ?", userID).Pluck("sys_department_id", &ids).Error
|
||||
selected := make(map[uint]bool, len(ids)+1)
|
||||
for _, id := range ids {
|
||||
selected[id] = true
|
||||
}
|
||||
if user.DeptID != 0 {
|
||||
selected[user.DeptID] = true
|
||||
}
|
||||
ids = ids[:0]
|
||||
for id := range selected {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if identity.Scope == 2 && len(ids) > 0 {
|
||||
var departments []departmentPO
|
||||
_ = r.data.gormDB.WithContext(ctx).Find(&departments).Error
|
||||
for _, department := range departments {
|
||||
for _, part := range strings.Split(department.Ancestors, ",") {
|
||||
value, _ := strconv.ParseUint(part, 10, 64)
|
||||
if selected[uint(value)] {
|
||||
selected[department.ID] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
ids = ids[:0]
|
||||
for id := range selected {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
ids = ids[:0]
|
||||
for id := range selected {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
} else if identity.Scope == 5 {
|
||||
ids, _ = r.DataScopeDepartmentIDs(ctx, authorityID)
|
||||
}
|
||||
return biz.DataScope{DepartmentIDs: ids}, nil
|
||||
identity.DepartmentIDs = ids
|
||||
return identity, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user