fix: complete nested portrait views and binding alert scope
This commit is contained in:
@@ -87,6 +87,16 @@ func (r *alertRecordRepo) List(ctx context.Context, scope business.AlertRecordSc
|
||||
if empty || !available {
|
||||
return page, nil
|
||||
}
|
||||
if filter.PlatformBusierID != nil {
|
||||
available, err := businessTableAvailable(db, "tab_promote")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !available {
|
||||
page.Available = false
|
||||
return page, nil
|
||||
}
|
||||
}
|
||||
base := func() *gorm.DB {
|
||||
q := alertScopedQuery(db, scope)
|
||||
if len(filter.PlatformCodes) > 0 {
|
||||
@@ -95,6 +105,9 @@ func (r *alertRecordRepo) List(ctx context.Context, scope business.AlertRecordSc
|
||||
if filter.TargetPromoteID != nil {
|
||||
q = q.Where("r.target_promote_id = ?", *filter.TargetPromoteID)
|
||||
}
|
||||
if filter.PlatformBusierID != nil {
|
||||
q = q.Where("EXISTS (?)", db.Table("tab_promote bp").Select("1").Where("bp.id=r.target_promote_id AND bp.source_db=r.platform_code AND bp.busier_id=?", *filter.PlatformBusierID))
|
||||
}
|
||||
return q
|
||||
}
|
||||
q := base()
|
||||
|
||||
@@ -111,6 +111,41 @@ func TestAlertRecordsMissingChannelsFailClosed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindingPortraitAlertsStayWithinSelectedSDKAccount(t *testing.T) {
|
||||
db, repo := prepareAlertRecords(t)
|
||||
if err := db.Exec("INSERT INTO sys_user_bind_platform(user_id,source_db,platform_busier_id,status) VALUES(9,'lx',16,'0')").Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Exec("INSERT INTO tab_promote VALUES(103,'lx',16,1,1)").Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&alertRecordPO{ID: 8, PlatformCode: "lx", TargetPromoteID: 103, BusinessID: 7, Status: 1, CreatedAt: time.Now()}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
for _, sample := range []struct {
|
||||
busier uint64
|
||||
want int64
|
||||
}{{14, 2}, {16, 1}, {999, 0}} {
|
||||
page, err := repo.List(ctx, alertTestScope(9), business.AlertRecordFilter{PlatformCodes: []string{"lx"}, PlatformBusierID: &sample.busier})
|
||||
if err != nil || page.Total != sample.want {
|
||||
t.Fatalf("binding %d: %+v %v", sample.busier, page, err)
|
||||
}
|
||||
var total int64
|
||||
for _, count := range page.StatusCount {
|
||||
total += count
|
||||
}
|
||||
if total != sample.want {
|
||||
t.Fatal("binding filter must also constrain status counts")
|
||||
}
|
||||
}
|
||||
busier := uint64(16)
|
||||
page, err := repo.List(ctx, alertTestScope(10), business.AlertRecordFilter{PlatformCodes: []string{"lx"}, PlatformBusierID: &busier})
|
||||
if err != nil || page.Total != 0 {
|
||||
t.Fatal("binding filter must not expand the viewer's permissions")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertRecordTransactionRollsBackWhenLogFails(t *testing.T) {
|
||||
db, repo := prepareAlertRecords(t)
|
||||
if err := db.Exec("CREATE TRIGGER reject_note BEFORE INSERT ON sys_alert_operation_log WHEN NEW.log_type = 2 BEGIN SELECT RAISE(ABORT, 'test failure'); END").Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user