Annotations: Exclude internal dashboard id when saved via UID (#111535)
This commit is contained in:
@@ -70,7 +70,6 @@ Content-Type: application/json
|
||||
{
|
||||
"id": 1124,
|
||||
"alertId": 0,
|
||||
"dashboardId": 468,
|
||||
"dashboardUID": "uGlb_lG7z",
|
||||
"panelId": 2,
|
||||
"userId": 1,
|
||||
@@ -80,7 +79,6 @@ Content-Type: application/json
|
||||
"time": 1507266395000,
|
||||
"timeEnd": 1507266395000,
|
||||
"text": "test",
|
||||
"metric": "",
|
||||
"tags": [
|
||||
"tag1",
|
||||
"tag2"
|
||||
@@ -90,7 +88,6 @@ Content-Type: application/json
|
||||
{
|
||||
"id": 1123,
|
||||
"alertId": 0,
|
||||
"dashboardId": 468,
|
||||
"dashboardUID": "jcIIG-07z",
|
||||
"panelId": 2,
|
||||
"userId": 1,
|
||||
@@ -99,7 +96,6 @@ Content-Type: application/json
|
||||
"prevState": "",
|
||||
"time": 1507265111000,
|
||||
"text": "test",
|
||||
"metric": "",
|
||||
"tags": [
|
||||
"tag1",
|
||||
"tag2"
|
||||
@@ -145,7 +141,6 @@ Content-Type: application/json
|
||||
|
||||
{
|
||||
"dashboardUID":"jcIIG-07z",
|
||||
"panelId":1,
|
||||
"time":1507037197339,
|
||||
"timeEnd":1507180805056,
|
||||
"tags":["tag1","tag2"],
|
||||
|
||||
+1
-11
@@ -54,17 +54,7 @@ func (hs *HTTPServer) GetAnnotations(c *contextmodel.ReqContext) response.Respon
|
||||
query.Limit = defaultAnnotationsLimit
|
||||
}
|
||||
|
||||
// When dashboard UID present in the request, we ignore dashboard ID
|
||||
if query.DashboardUID != "" {
|
||||
dq := dashboards.GetDashboardQuery{UID: query.DashboardUID, OrgID: c.GetOrgID()}
|
||||
dqResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &dq)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard UID in annotation request", err)
|
||||
} else {
|
||||
query.DashboardID = dqResult.ID // nolint:staticcheck
|
||||
}
|
||||
}
|
||||
|
||||
// When dashboard ID exists without UID, find the UID from dashboards api
|
||||
if query.DashboardID != 0 && query.DashboardUID == "" { // nolint:staticcheck
|
||||
dq := dashboards.GetDashboardQuery{ID: query.DashboardID, OrgID: c.GetOrgID()} // nolint:staticcheck
|
||||
dqResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &dq)
|
||||
|
||||
@@ -299,16 +299,13 @@ func (r *xormRepositoryImpl) Get(ctx context.Context, query annotations.ItemQuer
|
||||
params = append(params, query.AlertUID, query.OrgID)
|
||||
}
|
||||
|
||||
// nolint: staticcheck
|
||||
if query.DashboardID != 0 {
|
||||
sql.WriteString(` AND a.dashboard_id = ?`)
|
||||
params = append(params, query.DashboardID)
|
||||
}
|
||||
|
||||
// note: orgID is already required above
|
||||
if query.DashboardUID != "" {
|
||||
sql.WriteString(` AND a.dashboard_uid = ?`)
|
||||
params = append(params, query.DashboardUID)
|
||||
} else if query.DashboardID != 0 { // nolint: staticcheck
|
||||
sql.WriteString(` AND a.dashboard_id = ?`)
|
||||
params = append(params, query.DashboardID) // nolint: staticcheck
|
||||
}
|
||||
|
||||
if query.PanelID != 0 {
|
||||
|
||||
@@ -111,26 +111,26 @@ func (i Item) TableName() string {
|
||||
|
||||
// swagger:model Annotation
|
||||
type ItemDTO struct {
|
||||
ID int64 `json:"id" xorm:"id"`
|
||||
AlertID int64 `json:"alertId" xorm:"alert_id"`
|
||||
AlertName string `json:"alertName"`
|
||||
ID int64 `json:"id,omitempty" xorm:"id"`
|
||||
AlertID int64 `json:"alertId,omitempty" xorm:"alert_id"`
|
||||
AlertName string `json:"alertName,omitempty"`
|
||||
// Deprecated: Use DashboardUID and OrgID instead
|
||||
DashboardID int64 `json:"dashboardId" xorm:"dashboard_id"`
|
||||
DashboardUID *string `json:"dashboardUID" xorm:"dashboard_uid"`
|
||||
PanelID int64 `json:"panelId" xorm:"panel_id"`
|
||||
UserID int64 `json:"userId" xorm:"user_id"`
|
||||
NewState string `json:"newState"`
|
||||
PrevState string `json:"prevState"`
|
||||
Created int64 `json:"created"`
|
||||
Updated int64 `json:"updated"`
|
||||
Time int64 `json:"time"`
|
||||
TimeEnd int64 `json:"timeEnd"`
|
||||
Text string `json:"text"`
|
||||
Tags []string `json:"tags"`
|
||||
Login string `json:"login"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatarUrl" xorm:"avatar_url"`
|
||||
Data *simplejson.Json `json:"data"`
|
||||
DashboardID int64 `json:"dashboardId,omitempty" xorm:"dashboard_id"`
|
||||
DashboardUID *string `json:"dashboardUID,omitempty" xorm:"dashboard_uid"`
|
||||
PanelID int64 `json:"panelId,omitempty" xorm:"panel_id"`
|
||||
UserID int64 `json:"userId,omitempty" xorm:"user_id"`
|
||||
NewState string `json:"newState,omitempty"`
|
||||
PrevState string `json:"prevState,omitempty"`
|
||||
Created int64 `json:"created,omitempty"`
|
||||
Updated int64 `json:"updated,omitempty"`
|
||||
Time int64 `json:"time,omitempty"`
|
||||
TimeEnd int64 `json:"timeEnd,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Login string `json:"login,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
AvatarURL string `json:"avatarUrl,omitempty" xorm:"avatar_url"`
|
||||
Data *simplejson.Json `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type SortedItems []*ItemDTO
|
||||
|
||||
Reference in New Issue
Block a user