优化结构
This commit is contained in:
@@ -3,10 +3,9 @@ package data
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"kra/internal/biz/system"
|
||||
"testing"
|
||||
|
||||
"kra/internal/biz"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -53,12 +52,12 @@ func TestDataScopeCallbacksFailClosedAndAllowExplicitSystemBypass(t *testing.T)
|
||||
t.Fatalf("query without data scope error = %v", err)
|
||||
}
|
||||
|
||||
invalidCtx := biz.NewDataScopeContext(context.Background(), biz.DataScope{UserID: 7, AuthorityID: 1, Scope: 1, All: false})
|
||||
invalidCtx := system.NewDataScopeContext(context.Background(), system.DataScope{UserID: 7, AuthorityID: 1, Scope: 1, All: false})
|
||||
if err := db.WithContext(invalidCtx).Find(&rows).Error; !errors.Is(err, errInvalidDataScope) {
|
||||
t.Fatalf("query with invalid data scope error = %v", err)
|
||||
}
|
||||
|
||||
scopedCtx := biz.NewDataScopeContext(context.Background(), biz.DataScope{UserID: 7, AuthorityID: 1, Scope: 3, DepartmentIDs: []uint{10}})
|
||||
scopedCtx := system.NewDataScopeContext(context.Background(), system.DataScope{UserID: 7, AuthorityID: 1, Scope: 3, DepartmentIDs: []uint{10}})
|
||||
rows = nil
|
||||
if err := db.WithContext(scopedCtx).Order("id").Find(&rows).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -67,7 +66,7 @@ func TestDataScopeCallbacksFailClosedAndAllowExplicitSystemBypass(t *testing.T)
|
||||
t.Fatalf("scoped query rows = %+v", rows)
|
||||
}
|
||||
|
||||
emptyCtx := biz.NewDataScopeContext(context.Background(), biz.DataScope{UserID: 7, AuthorityID: 1, Scope: 5})
|
||||
emptyCtx := system.NewDataScopeContext(context.Background(), system.DataScope{UserID: 7, AuthorityID: 1, Scope: 5})
|
||||
rows = nil
|
||||
if err := db.WithContext(emptyCtx).Find(&rows).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -91,7 +90,7 @@ func TestDataScopeCreateRequiresIdentityAndStampsOwnership(t *testing.T) {
|
||||
t.Fatalf("create without data scope error = %v", err)
|
||||
}
|
||||
|
||||
ctx := biz.NewDataScopeContext(context.Background(), biz.DataScope{UserID: 7, AuthorityID: 1, Scope: 3, PrimaryDeptID: 10, DepartmentIDs: []uint{10}})
|
||||
ctx := system.NewDataScopeContext(context.Background(), system.DataScope{UserID: 7, AuthorityID: 1, Scope: 3, PrimaryDeptID: 10, DepartmentIDs: []uint{10}})
|
||||
created := dataScopeRecord{Name: "owned", DeptID: 999, CreatedBy: 999}
|
||||
if err := db.WithContext(ctx).Create(&created).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user