mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix: annnotation api & sql issue
This commit is contained in:
parent
ed1fec8e0f
commit
132df4553c
@ -213,6 +213,7 @@ func DeleteAnnotations(c *m.ReqContext, cmd dtos.DeleteAnnotationsCmd) Response
|
|||||||
repo := annotations.GetRepository()
|
repo := annotations.GetRepository()
|
||||||
|
|
||||||
err := repo.Delete(&annotations.DeleteParams{
|
err := repo.Delete(&annotations.DeleteParams{
|
||||||
|
OrgId: c.OrgId,
|
||||||
Id: cmd.AnnotationId,
|
Id: cmd.AnnotationId,
|
||||||
RegionId: cmd.RegionId,
|
RegionId: cmd.RegionId,
|
||||||
DashboardId: cmd.DashboardId,
|
DashboardId: cmd.DashboardId,
|
||||||
@ -235,7 +236,8 @@ func DeleteAnnotationByID(c *m.ReqContext) Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := repo.Delete(&annotations.DeleteParams{
|
err := repo.Delete(&annotations.DeleteParams{
|
||||||
Id: annotationID,
|
OrgId: c.OrgId,
|
||||||
|
Id: annotationID,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -254,6 +256,7 @@ func DeleteAnnotationRegion(c *m.ReqContext) Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := repo.Delete(&annotations.DeleteParams{
|
err := repo.Delete(&annotations.DeleteParams{
|
||||||
|
OrgId: c.OrgId,
|
||||||
RegionId: regionID,
|
RegionId: regionID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -35,11 +35,12 @@ type PostParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeleteParams struct {
|
type DeleteParams struct {
|
||||||
Id int64 `json:"id"`
|
OrgId int64
|
||||||
AlertId int64 `json:"alertId"`
|
Id int64
|
||||||
DashboardId int64 `json:"dashboardId"`
|
AlertId int64
|
||||||
PanelId int64 `json:"panelId"`
|
DashboardId int64
|
||||||
RegionId int64 `json:"regionId"`
|
PanelId int64
|
||||||
|
RegionId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
var repositoryInstance Repository
|
var repositoryInstance Repository
|
||||||
|
@ -238,18 +238,19 @@ func (r *SqlAnnotationRepo) Delete(params *annotations.DeleteParams) error {
|
|||||||
queryParams []interface{}
|
queryParams []interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sqlog.Info("delete", "orgId", params.OrgId)
|
||||||
if params.RegionId != 0 {
|
if params.RegionId != 0 {
|
||||||
annoTagSql = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE region_id = ?)"
|
annoTagSql = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE region_id = ? AND org_id = ?)"
|
||||||
sql = "DELETE FROM annotation WHERE region_id = ?"
|
sql = "DELETE FROM annotation WHERE region_id = ? AND org_id = ?"
|
||||||
queryParams = []interface{}{params.RegionId}
|
queryParams = []interface{}{params.RegionId, params.OrgId}
|
||||||
} else if params.Id != 0 {
|
} else if params.Id != 0 {
|
||||||
annoTagSql = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE id = ?)"
|
annoTagSql = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE id = ? AND org_id = ?)"
|
||||||
sql = "DELETE FROM annotation WHERE id = ?"
|
sql = "DELETE FROM annotation WHERE id = ? AND org_id = ?"
|
||||||
queryParams = []interface{}{params.Id}
|
queryParams = []interface{}{params.Id, params.OrgId}
|
||||||
} else {
|
} else {
|
||||||
annoTagSql = "DELETE FROM annotation_tag WHERE annotation_id IN (SELECT id FROM annotation WHERE dashboard_id = ? AND panel_id = ?)"
|
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 = ?"
|
sql = "DELETE FROM annotation WHERE dashboard_id = ? AND panel_id = ? AND org_id = ?"
|
||||||
queryParams = []interface{}{params.DashboardId, params.PanelId}
|
queryParams = []interface{}{params.DashboardId, params.PanelId, params.OrgId}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Exec(annoTagSql, queryParams...); err != nil {
|
if _, err := sess.Exec(annoTagSql, queryParams...); err != nil {
|
||||||
|
@ -268,7 +268,7 @@ func TestAnnotations(t *testing.T) {
|
|||||||
|
|
||||||
annotationId := items[0].Id
|
annotationId := items[0].Id
|
||||||
|
|
||||||
err = repo.Delete(&annotations.DeleteParams{Id: annotationId})
|
err = repo.Delete(&annotations.DeleteParams{Id: annotationId, OrgId: 1})
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
items, err = repo.Find(query)
|
items, err = repo.Find(query)
|
||||||
|
Loading…
Reference in New Issue
Block a user