Rename Id to ID for annotation models (#62886)
* Rename Id to ID for annotation models * Add xorm tags * Rename Id to ID for API key models * Add xorm tags
This commit is contained in:
@@ -124,11 +124,11 @@ func TestOldAnnotationsAreDeletedFirst(t *testing.T) {
|
||||
|
||||
// create some test annotations
|
||||
a := annotations.Item{
|
||||
DashboardId: 1,
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
PanelId: 1,
|
||||
AlertId: 10,
|
||||
DashboardID: 1,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
PanelID: 1,
|
||||
AlertID: 10,
|
||||
Text: "",
|
||||
Created: time.Now().AddDate(-10, 0, -10).UnixNano() / int64(time.Millisecond),
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func TestOldAnnotationsAreDeletedFirst(t *testing.T) {
|
||||
_, err = sess.Insert(a)
|
||||
require.NoError(t, err, "cannot insert annotation")
|
||||
|
||||
a.AlertId = 20
|
||||
a.AlertID = 20
|
||||
_, err = sess.Insert(a)
|
||||
require.NoError(t, err, "cannot insert annotation")
|
||||
|
||||
@@ -195,23 +195,23 @@ func createTestAnnotations(t *testing.T, store db.DB, expectedCount int, oldAnno
|
||||
|
||||
for i := 0; i < expectedCount; i++ {
|
||||
a := &annotations.Item{
|
||||
DashboardId: 1,
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
PanelId: 1,
|
||||
DashboardID: 1,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
PanelID: 1,
|
||||
Text: "",
|
||||
}
|
||||
|
||||
// mark every third as an API annotation
|
||||
// that does not belong to a dashboard
|
||||
if i%3 == 1 {
|
||||
a.DashboardId = 0
|
||||
a.DashboardID = 0
|
||||
}
|
||||
|
||||
// mark every third annotation as an alert annotation
|
||||
if i%3 == 0 {
|
||||
a.AlertId = 10
|
||||
a.DashboardId = 2
|
||||
a.AlertID = 10
|
||||
a.DashboardID = 2
|
||||
}
|
||||
|
||||
// create epoch as int annotations.go line 40
|
||||
@@ -229,7 +229,7 @@ func createTestAnnotations(t *testing.T, store db.DB, expectedCount int, oldAnno
|
||||
// mimick the SQL annotation Save logic by writing records to the annotation_tag table
|
||||
// we need to ensure they get deleted when we clean up annotations
|
||||
for tagID := range []int{1, 2} {
|
||||
_, err = sess.Exec("INSERT INTO annotation_tag (annotation_id, tag_id) VALUES(?,?)", a.Id, tagID)
|
||||
_, err = sess.Exec("INSERT INTO annotation_tag (annotation_id, tag_id) VALUES(?,?)", a.ID, tagID)
|
||||
require.NoError(t, err, "should be able to save annotation tag ID", err)
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -131,7 +131,7 @@ func (r *xormRepositoryImpl) synchronizeTags(ctx context.Context, item *annotati
|
||||
return err
|
||||
}
|
||||
for _, tag := range tags {
|
||||
if _, err := sess.Exec("INSERT INTO annotation_tag (annotation_id, tag_id) VALUES(?,?)", item.Id, tag.Id); err != nil {
|
||||
if _, err := sess.Exec("INSERT INTO annotation_tag (annotation_id, tag_id) VALUES(?,?)", item.ID, tag.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (r *xormRepositoryImpl) Update(ctx context.Context, item *annotations.Item)
|
||||
)
|
||||
existing := new(annotations.Item)
|
||||
|
||||
isExist, err = sess.Table("annotation").Where("id=? AND org_id=?", item.Id, item.OrgId).Get(existing)
|
||||
isExist, err = sess.Table("annotation").Where("id=? AND org_id=?", item.ID, item.OrgID).Get(existing)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -176,11 +176,11 @@ func (r *xormRepositoryImpl) Update(ctx context.Context, item *annotations.Item)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := sess.Exec("DELETE FROM annotation_tag WHERE annotation_id = ?", existing.Id); err != nil {
|
||||
if _, err := sess.Exec("DELETE FROM annotation_tag WHERE annotation_id = ?", existing.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, tag := range tags {
|
||||
if _, err := sess.Exec("INSERT INTO annotation_tag (annotation_id, tag_id) VALUES(?,?)", existing.Id, tag.Id); err != nil {
|
||||
if _, err := sess.Exec("INSERT INTO annotation_tag (annotation_id, tag_id) VALUES(?,?)", existing.ID, tag.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (r *xormRepositoryImpl) Update(ctx context.Context, item *annotations.Item)
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = sess.Table("annotation").ID(existing.Id).Cols("epoch", "text", "epoch_end", "updated", "tags", "data").Update(existing)
|
||||
_, err = sess.Table("annotation").ID(existing.ID).Cols("epoch", "text", "epoch_end", "updated", "tags", "data").Update(existing)
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -228,32 +228,32 @@ func (r *xormRepositoryImpl) Get(ctx context.Context, query *annotations.ItemQue
|
||||
`)
|
||||
|
||||
sql.WriteString(`WHERE a.org_id = ?`)
|
||||
params = append(params, query.OrgId)
|
||||
params = append(params, query.OrgID)
|
||||
|
||||
if query.AnnotationId != 0 {
|
||||
if query.AnnotationID != 0 {
|
||||
// fmt.Print("annotation query")
|
||||
sql.WriteString(` AND a.id = ?`)
|
||||
params = append(params, query.AnnotationId)
|
||||
params = append(params, query.AnnotationID)
|
||||
}
|
||||
|
||||
if query.AlertId != 0 {
|
||||
if query.AlertID != 0 {
|
||||
sql.WriteString(` AND a.alert_id = ?`)
|
||||
params = append(params, query.AlertId)
|
||||
params = append(params, query.AlertID)
|
||||
}
|
||||
|
||||
if query.DashboardId != 0 {
|
||||
if query.DashboardID != 0 {
|
||||
sql.WriteString(` AND a.dashboard_id = ?`)
|
||||
params = append(params, query.DashboardId)
|
||||
params = append(params, query.DashboardID)
|
||||
}
|
||||
|
||||
if query.PanelId != 0 {
|
||||
if query.PanelID != 0 {
|
||||
sql.WriteString(` AND a.panel_id = ?`)
|
||||
params = append(params, query.PanelId)
|
||||
params = append(params, query.PanelID)
|
||||
}
|
||||
|
||||
if query.UserId != 0 {
|
||||
if query.UserID != 0 {
|
||||
sql.WriteString(` AND a.user_id = ?`)
|
||||
params = append(params, query.UserId)
|
||||
params = append(params, query.UserID)
|
||||
}
|
||||
|
||||
if query.From > 0 && query.To > 0 {
|
||||
@@ -363,27 +363,27 @@ func (r *xormRepositoryImpl) Delete(ctx context.Context, params *annotations.Del
|
||||
annoTagSQL string
|
||||
)
|
||||
|
||||
r.log.Info("delete", "orgId", params.OrgId)
|
||||
if params.Id != 0 {
|
||||
r.log.Info("delete", "orgId", params.OrgID)
|
||||
if params.ID != 0 {
|
||||
annoTagSQL = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE id = ? AND org_id = ?)"
|
||||
sql = "DELETE FROM annotation WHERE id = ? AND org_id = ?"
|
||||
|
||||
if _, err := sess.Exec(annoTagSQL, params.Id, params.OrgId); err != nil {
|
||||
if _, err := sess.Exec(annoTagSQL, params.ID, params.OrgID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := sess.Exec(sql, params.Id, params.OrgId); err != nil {
|
||||
if _, err := sess.Exec(sql, params.ID, params.OrgID); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
annoTagSQL = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE dashboard_id = ? AND panel_id = ? AND org_id = ?)"
|
||||
sql = "DELETE FROM annotation WHERE dashboard_id = ? AND panel_id = ? AND org_id = ?"
|
||||
|
||||
if _, err := sess.Exec(annoTagSQL, params.DashboardId, params.PanelId, params.OrgId); err != nil {
|
||||
if _, err := sess.Exec(annoTagSQL, params.DashboardID, params.PanelID, params.OrgID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := sess.Exec(sql, params.DashboardId, params.PanelId, params.OrgId); err != nil {
|
||||
if _, err := sess.Exec(sql, params.DashboardID, params.PanelID, params.OrgID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,9 +82,9 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
annotation := &annotations.Item{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
DashboardId: dashboard.ID,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
DashboardID: dashboard.ID,
|
||||
Text: "hello",
|
||||
Type: "alert",
|
||||
Epoch: 10,
|
||||
@@ -93,13 +93,13 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
}
|
||||
err = repo.Add(context.Background(), annotation)
|
||||
require.NoError(t, err)
|
||||
assert.Greater(t, annotation.Id, int64(0))
|
||||
assert.Greater(t, annotation.ID, int64(0))
|
||||
assert.Equal(t, annotation.Epoch, annotation.EpochEnd)
|
||||
|
||||
annotation2 := &annotations.Item{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
DashboardId: dashboard2.ID,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
DashboardID: dashboard2.ID,
|
||||
Text: "hello",
|
||||
Type: "alert",
|
||||
Epoch: 21, // Should swap epoch & epochEnd
|
||||
@@ -108,13 +108,13 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
}
|
||||
err = repo.Add(context.Background(), annotation2)
|
||||
require.NoError(t, err)
|
||||
assert.Greater(t, annotation2.Id, int64(0))
|
||||
assert.Greater(t, annotation2.ID, int64(0))
|
||||
assert.Equal(t, int64(20), annotation2.Epoch)
|
||||
assert.Equal(t, int64(21), annotation2.EpochEnd)
|
||||
|
||||
organizationAnnotation1 := &annotations.Item{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
Text: "deploy",
|
||||
Type: "",
|
||||
Epoch: 15,
|
||||
@@ -122,11 +122,11 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
}
|
||||
err = repo.Add(context.Background(), organizationAnnotation1)
|
||||
require.NoError(t, err)
|
||||
assert.Greater(t, organizationAnnotation1.Id, int64(0))
|
||||
assert.Greater(t, organizationAnnotation1.ID, int64(0))
|
||||
|
||||
globalAnnotation2 := &annotations.Item{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
Text: "rollback",
|
||||
Type: "",
|
||||
Epoch: 17,
|
||||
@@ -134,11 +134,11 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
}
|
||||
err = repo.Add(context.Background(), globalAnnotation2)
|
||||
require.NoError(t, err)
|
||||
assert.Greater(t, globalAnnotation2.Id, int64(0))
|
||||
assert.Greater(t, globalAnnotation2.ID, int64(0))
|
||||
t.Run("Can query for annotation by dashboard id", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: dashboard.ID,
|
||||
OrgID: 1,
|
||||
DashboardID: dashboard.ID,
|
||||
From: 0,
|
||||
To: 15,
|
||||
SignedInUser: testUser,
|
||||
@@ -155,8 +155,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
})
|
||||
|
||||
badAnnotation := &annotations.Item{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
Text: "rollback",
|
||||
Type: "",
|
||||
Epoch: 17,
|
||||
@@ -171,7 +171,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items := make([]annotations.Item, count)
|
||||
for i := 0; i < count; i++ {
|
||||
items[i] = annotations.Item{
|
||||
OrgId: 100,
|
||||
OrgID: 100,
|
||||
Type: "batch",
|
||||
Epoch: 12,
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
err := repo.AddMany(context.Background(), items)
|
||||
|
||||
require.NoError(t, err)
|
||||
query := &annotations.ItemQuery{OrgId: 100, SignedInUser: testUser}
|
||||
query := &annotations.ItemQuery{OrgID: 100, SignedInUser: testUser}
|
||||
inserted, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, inserted, count)
|
||||
@@ -196,7 +196,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items := make([]annotations.Item, count)
|
||||
for i := 0; i < count; i++ {
|
||||
items[i] = annotations.Item{
|
||||
OrgId: 101,
|
||||
OrgID: 101,
|
||||
Type: "batch",
|
||||
Epoch: 12,
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
err := repo.AddMany(context.Background(), items)
|
||||
|
||||
require.NoError(t, err)
|
||||
query := &annotations.ItemQuery{OrgId: 101, SignedInUser: testUser}
|
||||
query := &annotations.ItemQuery{OrgID: 101, SignedInUser: testUser}
|
||||
inserted, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, inserted, count)
|
||||
@@ -214,19 +214,19 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Can query for annotation by id", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
AnnotationId: annotation2.Id,
|
||||
OrgID: 1,
|
||||
AnnotationID: annotation2.ID,
|
||||
SignedInUser: testUser,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, items, 1)
|
||||
assert.Equal(t, annotation2.Id, items[0].Id)
|
||||
assert.Equal(t, annotation2.ID, items[0].ID)
|
||||
})
|
||||
|
||||
t.Run("Should not find any when item is outside time range", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 12,
|
||||
To: 15,
|
||||
SignedInUser: testUser,
|
||||
@@ -237,8 +237,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Should not find one when tag filter does not match", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 1,
|
||||
To: 15,
|
||||
Tags: []string{"asd"},
|
||||
@@ -250,8 +250,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Should not find one when type filter does not match", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 1,
|
||||
To: 15,
|
||||
Type: "alert",
|
||||
@@ -263,8 +263,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Should find one when all tag filters does match", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 1,
|
||||
To: 15, // this will exclude the second test annotation
|
||||
Tags: []string{"outage", "error"},
|
||||
@@ -276,7 +276,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Should find two annotations using partial match", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
OrgID: 1,
|
||||
From: 1,
|
||||
To: 25,
|
||||
MatchAny: true,
|
||||
@@ -289,8 +289,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Should find one when all key value tag filters does match", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 1,
|
||||
To: 15,
|
||||
Tags: []string{"type:outage", "server:server-1"},
|
||||
@@ -302,8 +302,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Can update annotation and remove all tags", func(t *testing.T) {
|
||||
query := &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 0,
|
||||
To: 15,
|
||||
SignedInUser: testUser,
|
||||
@@ -311,10 +311,10 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
annotationId := items[0].Id
|
||||
annotationId := items[0].ID
|
||||
err = repo.Update(context.Background(), &annotations.Item{
|
||||
Id: annotationId,
|
||||
OrgId: 1,
|
||||
ID: annotationId,
|
||||
OrgID: 1,
|
||||
Text: "something new",
|
||||
Tags: []string{},
|
||||
})
|
||||
@@ -323,7 +323,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err = repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, annotationId, items[0].Id)
|
||||
assert.Equal(t, annotationId, items[0].ID)
|
||||
assert.Empty(t, items[0].Tags)
|
||||
assert.Equal(t, "something new", items[0].Text)
|
||||
data, err := items[0].Data.Map()
|
||||
@@ -333,8 +333,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Can update annotation with new tags", func(t *testing.T) {
|
||||
query := &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 0,
|
||||
To: 15,
|
||||
SignedInUser: testUser,
|
||||
@@ -342,10 +342,10 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
annotationId := items[0].Id
|
||||
annotationId := items[0].ID
|
||||
err = repo.Update(context.Background(), &annotations.Item{
|
||||
Id: annotationId,
|
||||
OrgId: 1,
|
||||
ID: annotationId,
|
||||
OrgID: 1,
|
||||
Text: "something new",
|
||||
Tags: []string{"newtag1", "newtag2"},
|
||||
})
|
||||
@@ -354,7 +354,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err = repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, annotationId, items[0].Id)
|
||||
assert.Equal(t, annotationId, items[0].ID)
|
||||
assert.Equal(t, []string{"newtag1", "newtag2"}, items[0].Tags)
|
||||
assert.Equal(t, "something new", items[0].Text)
|
||||
assert.Greater(t, items[0].Updated, items[0].Created)
|
||||
@@ -362,8 +362,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Can update annotations with data", func(t *testing.T) {
|
||||
query := &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 0,
|
||||
To: 15,
|
||||
SignedInUser: testUser,
|
||||
@@ -371,11 +371,11 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
annotationId := items[0].Id
|
||||
annotationId := items[0].ID
|
||||
data := simplejson.NewFromAny(map[string]interface{}{"data": "I am a data", "data2": "I am also a data"})
|
||||
err = repo.Update(context.Background(), &annotations.Item{
|
||||
Id: annotationId,
|
||||
OrgId: 1,
|
||||
ID: annotationId,
|
||||
OrgID: 1,
|
||||
Text: "something new",
|
||||
Tags: []string{"newtag1", "newtag2"},
|
||||
Data: data,
|
||||
@@ -385,7 +385,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err = repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, annotationId, items[0].Id)
|
||||
assert.Equal(t, annotationId, items[0].ID)
|
||||
assert.Equal(t, []string{"newtag1", "newtag2"}, items[0].Tags)
|
||||
assert.Equal(t, "something new", items[0].Text)
|
||||
assert.Greater(t, items[0].Updated, items[0].Created)
|
||||
@@ -394,8 +394,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Can delete annotation", func(t *testing.T) {
|
||||
query := &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
From: 0,
|
||||
To: 15,
|
||||
SignedInUser: testUser,
|
||||
@@ -403,8 +403,8 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
annotationId := items[0].Id
|
||||
err = repo.Delete(context.Background(), &annotations.DeleteParams{Id: annotationId, OrgId: 1})
|
||||
annotationId := items[0].ID
|
||||
err = repo.Delete(context.Background(), &annotations.DeleteParams{ID: annotationId, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
items, err = repo.Get(context.Background(), query)
|
||||
@@ -414,29 +414,29 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
|
||||
t.Run("Can delete annotation using dashboard id and panel id", func(t *testing.T) {
|
||||
annotation3 := &annotations.Item{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
DashboardId: dashboard2.ID,
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
DashboardID: dashboard2.ID,
|
||||
Text: "toBeDeletedWithPanelId",
|
||||
Type: "alert",
|
||||
Epoch: 11,
|
||||
Tags: []string{"test"},
|
||||
PanelId: 20,
|
||||
PanelID: 20,
|
||||
}
|
||||
err = repo.Add(context.Background(), annotation3)
|
||||
require.NoError(t, err)
|
||||
|
||||
query := &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
AnnotationId: annotation3.Id,
|
||||
OrgID: 1,
|
||||
AnnotationID: annotation3.ID,
|
||||
SignedInUser: testUser,
|
||||
}
|
||||
items, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
|
||||
dashboardId := items[0].DashboardId
|
||||
panelId := items[0].PanelId
|
||||
err = repo.Delete(context.Background(), &annotations.DeleteParams{DashboardId: dashboardId, PanelId: panelId, OrgId: 1})
|
||||
dashboardId := items[0].DashboardID
|
||||
panelId := items[0].PanelID
|
||||
err = repo.Delete(context.Background(), &annotations.DeleteParams{DashboardID: dashboardId, PanelID: panelId, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
items, err = repo.Get(context.Background(), query)
|
||||
@@ -523,16 +523,16 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
dash1Annotation := &annotations.Item{
|
||||
OrgId: 1,
|
||||
DashboardId: 1,
|
||||
OrgID: 1,
|
||||
DashboardID: 1,
|
||||
Epoch: 10,
|
||||
}
|
||||
err = repo.Add(context.Background(), dash1Annotation)
|
||||
require.NoError(t, err)
|
||||
|
||||
dash2Annotation := &annotations.Item{
|
||||
OrgId: 1,
|
||||
DashboardId: 2,
|
||||
OrgID: 1,
|
||||
DashboardID: 2,
|
||||
Epoch: 10,
|
||||
Tags: []string{"foo:bar"},
|
||||
}
|
||||
@@ -540,7 +540,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
organizationAnnotation := &annotations.Item{
|
||||
OrgId: 1,
|
||||
OrgID: 1,
|
||||
Epoch: 10,
|
||||
}
|
||||
err = repo.Add(context.Background(), organizationAnnotation)
|
||||
@@ -566,7 +566,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
accesscontrol.ActionAnnotationsRead: {accesscontrol.ScopeAnnotationsAll},
|
||||
dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
expectedAnnotationIds: []int64{dash1Annotation.Id, dash2Annotation.Id, organizationAnnotation.Id},
|
||||
expectedAnnotationIds: []int64{dash1Annotation.ID, dash2Annotation.ID, organizationAnnotation.ID},
|
||||
},
|
||||
{
|
||||
description: "Should find all dashboard annotations",
|
||||
@@ -574,7 +574,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
accesscontrol.ActionAnnotationsRead: {accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
expectedAnnotationIds: []int64{dash1Annotation.Id, dash2Annotation.Id},
|
||||
expectedAnnotationIds: []int64{dash1Annotation.ID, dash2Annotation.ID},
|
||||
},
|
||||
{
|
||||
description: "Should find only annotations from dashboards that user can read",
|
||||
@@ -582,7 +582,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
accesscontrol.ActionAnnotationsRead: {accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
dashboards.ActionDashboardsRead: {fmt.Sprintf("dashboards:uid:%s", dash1UID)},
|
||||
},
|
||||
expectedAnnotationIds: []int64{dash1Annotation.Id},
|
||||
expectedAnnotationIds: []int64{dash1Annotation.ID},
|
||||
},
|
||||
{
|
||||
description: "Should find no annotations if user can't view dashboards or organization annotations",
|
||||
@@ -597,7 +597,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
accesscontrol.ActionAnnotationsRead: {accesscontrol.ScopeAnnotationsTypeOrganization},
|
||||
dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
expectedAnnotationIds: []int64{organizationAnnotation.Id},
|
||||
expectedAnnotationIds: []int64{organizationAnnotation.ID},
|
||||
},
|
||||
{
|
||||
description: "Should error if user doesn't have annotation read permissions",
|
||||
@@ -614,7 +614,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
setupRBACPermission(t, repo, role, user)
|
||||
|
||||
results, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
OrgID: 1,
|
||||
SignedInUser: user,
|
||||
})
|
||||
if tc.expectedError {
|
||||
@@ -624,7 +624,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, results, len(tc.expectedAnnotationIds))
|
||||
for _, r := range results {
|
||||
assert.Contains(t, tc.expectedAnnotationIds, r.Id)
|
||||
assert.Contains(t, tc.expectedAnnotationIds, r.ID)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user