2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-29 21:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"strconv" 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"strings" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/api/dtos" 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/api/response" 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/accesscontrol" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/annotations" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									contextmodel  "github.com/grafana/grafana/pkg/services/contexthandler/model" 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-04 22:12:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/dashboards" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 06:09:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/featuremgmt" 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/guardian" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/org" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/services/user" 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-16 21:24:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/util" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									"github.com/grafana/grafana/pkg/web" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route GET /annotations annotations getAnnotations
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Find Annotations.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Starting in Grafana v6.4 regions annotations are now returned in one entity that now includes the timeEnd property.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: getAnnotationsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  GetAnnotations ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									query  :=  & annotations . ItemQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										From :          c . QueryInt64 ( "from" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										To :            c . QueryInt64 ( "to" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :         c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										UserID :        c . QueryInt64 ( "userId" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										AlertID :       c . QueryInt64 ( "alertId" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										DashboardID :   c . QueryInt64 ( "dashboardId" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										DashboardUID :  c . Query ( "dashboardUID" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										PanelID :       c . QueryInt64 ( "panelId" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Limit :         c . QueryInt64 ( "limit" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Tags :          c . QueryStrings ( "tags" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Type :          c . Query ( "type" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										MatchAny :      c . QueryBool ( "matchAny" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										SignedInUser :  c . SignedInUser , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 09:52:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// When dashboard UID present in the request, we ignore dashboard ID
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  query . DashboardUID  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										dq  :=  dashboards . GetDashboardQuery { UID :  query . DashboardUID ,  OrgID :  c . OrgID } 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-25 17:36:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										dqResult ,  err  :=  hs . DashboardService . GetDashboard ( c . Req . Context ( ) ,  & dq ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 09:52:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 06:09:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											if  hs . Features . IsEnabled ( featuremgmt . FlagDashboardsFromStorage )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												// OK... the storage UIDs do not (yet?) exist in the DashboardService
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												return  response . Error ( http . StatusBadRequest ,  "Invalid dashboard UID in annotation request" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											query . DashboardID  =  dqResult . ID 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 09:52:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									items ,  err  :=  hs . annotationsRepo . Find ( c . Req . Context ( ) ,  query ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 500 ,  "Failed to get annotations" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// since there are several annotations per dashboard, we can cache dashboard uid
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									dashboardCache  :=  make ( map [ int64 ] * string ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									for  _ ,  item  :=  range  items  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  item . Email  !=  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											item . AvatarURL  =  dtos . GetGravatarUrl ( item . Email ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  item . DashboardID  !=  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											if  val ,  ok  :=  dashboardCache [ item . DashboardID ] ;  ok  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												item . DashboardUID  =  val 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												query  :=  dashboards . GetDashboardQuery { ID :  item . DashboardID ,  OrgID :  c . OrgID } 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-25 17:36:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												queryResult ,  err  :=  hs . DashboardService . GetDashboard ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												if  err  ==  nil  &&  queryResult  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
													item . DashboardUID  =  & queryResult . UID 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
													dashboardCache [ item . DashboardID ]  =  & queryResult . UID 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . JSON ( http . StatusOK ,  items ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-10-14 15:33:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								type  AnnotationError  struct  {  
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									message  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( e  * AnnotationError )  Error ( )  string  {  
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  e . message 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route POST /annotations annotations postAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Create Annotation.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Creates an annotation in the Grafana database. The dashboardId and panelId fields are optional. If they are not specified then an organization annotation is created and can be queried in any dashboard that adds the Grafana annotations data source. When creating a region annotation include the timeEnd property.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// The format for `time` and `timeEnd` should be epoch numbers in millisecond resolution.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// The response for this HTTP request is slightly different in versions prior to v6.4. In prior versions you would also get an endId if you where creating a region. But in 6.4 regions are represented using a single event with time and timeEnd properties.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: postAnnotationResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  PostAnnotation ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									cmd  :=  dtos . PostAnnotationsCmd { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// overwrite dashboardId when dashboardUID is not empty
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . DashboardUID  !=  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-16 23:33:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										query  :=  dashboards . GetDashboardQuery { OrgID :  c . OrgID ,  UID :  cmd . DashboardUID } 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-25 17:36:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										queryResult ,  err  :=  hs . DashboardService . GetDashboard ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  err  ==  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-25 17:36:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											cmd . DashboardId  =  queryResult . ID 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  canSave ,  err  :=  hs . canCreateAnnotation ( c ,  cmd . DashboardId ) ;  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  dashboardGuardianResponse ( err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . Text  ==  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										err  :=  & AnnotationError { "text field should not be empty" } 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-29 21:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 400 ,  "Failed to save annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 01:22:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									item  :=  annotations . Item { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :        c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										UserID :       c . UserID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										DashboardID :  cmd . DashboardId , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										PanelID :      cmd . PanelId , 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-22 23:21:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Epoch :        cmd . Time , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-16 16:49:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										EpochEnd :     cmd . TimeEnd , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 01:22:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Text :         cmd . Text , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Data :         cmd . Data , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Tags :         cmd . Tags , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 01:22:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  hs . annotationsRepo . Save ( c . Req . Context ( ) ,  & item ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-29 21:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  errors . Is ( err ,  annotations . ErrTimerangeMissing )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											return  response . Error ( 400 ,  "Failed to save annotation" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 18:04:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . ErrOrFallback ( 500 ,  "Failed to save annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 01:22:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									startID  :=  item . ID 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-16 21:24:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . JSON ( http . StatusOK ,  util . DynMap { 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-16 21:24:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										"message" :  "Annotation added" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										"id" :       startID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 01:22:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  formatGraphiteAnnotation ( what  string ,  data  string )  string  {  
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									text  :=  what 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  data  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										text  =  text  +  "\n"  +  data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  text 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route POST /annotations/graphite annotations postGraphiteAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Create Annotation in Graphite format.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								// Creates an annotation by using Graphite-compatible event format. The `when` and `data` fields are optional. If `when` is not specified then the current time will be used as annotation’   
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: postAnnotationResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  PostGraphiteAnnotation ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									cmd  :=  dtos . PostGraphiteAnnotationsCmd { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . What  ==  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										err  :=  & AnnotationError { "what field should not be empty" } 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-29 21:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 400 ,  "Failed to save Graphite annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									text  :=  formatGraphiteAnnotation ( cmd . What ,  cmd . Data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Support tags in prior to Graphite 0.10.0 format (string of tags separated by space)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									var  tagsArray  [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									switch  tags  :=  cmd . Tags . ( type )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									case  string : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-18 16:13:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  tags  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											tagsArray  =  strings . Split ( tags ,  " " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											tagsArray  =  [ ] string { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									case  [ ] interface { } : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										for  _ ,  t  :=  range  tags  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											if  tagStr ,  ok  :=  t . ( string ) ;  ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												tagsArray  =  append ( tagsArray ,  tagStr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												err  :=  & AnnotationError { "tag should be a string" } 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-29 21:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												return  response . Error ( 400 ,  "Failed to save Graphite annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									default : 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										err  :=  & AnnotationError { "unsupported tags format" } 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-29 21:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 400 ,  "Failed to save Graphite annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									item  :=  annotations . Item { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :   c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										UserID :  c . UserID , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-09 19:58:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Epoch :   cmd . When  *  1000 , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Text :    text , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Tags :    tagsArray , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 20:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  hs . annotationsRepo . Save ( c . Req . Context ( ) ,  & item ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 18:04:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . ErrOrFallback ( 500 ,  "Failed to save Graphite annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . JSON ( http . StatusOK ,  util . DynMap { 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-16 21:24:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										"message" :  "Graphite annotation added" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										"id" :       item . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-16 21:24:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-12 16:12:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route PUT /annotations/{annotation_id} annotations updateAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Update Annotation.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Updates all properties of an annotation that matches the specified id. To only update certain property, consider using the Patch Annotation operation.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  UpdateAnnotation ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									cmd  :=  dtos . UpdateAnnotationsCmd { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									annotationID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":annotationId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "annotationId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotation ,  resp  :=  findAnnotationByID ( c . Req . Context ( ) ,  hs . annotationsRepo ,  annotationID ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  resp  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  resp 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  canSave ,  err  :=  hs . canSaveAnnotation ( c ,  annotation ) ;  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  dashboardGuardianResponse ( err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									item  :=  annotations . Item { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :     c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										UserID :    c . UserID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										ID :        annotationID , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-16 16:49:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Epoch :     cmd . Time , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										EpochEnd :  cmd . TimeEnd , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Text :      cmd . Text , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Tags :      cmd . Tags , 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 22:53:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Data :      annotation . Data , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . Data  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										item . Data  =  cmd . Data 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  hs . annotationsRepo . Update ( c . Req . Context ( ) ,  & item ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 18:04:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . ErrOrFallback ( 500 ,  "Failed to update annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . Success ( "Annotation updated" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route PATCH /annotations/{annotation_id} annotations patchAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
									
										
										
										
											2022-09-12 15:40:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// Patch Annotation.
  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Updates one or more properties of an annotation that matches the specified ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// This operation currently supports updating of the `text`, `tags`, `time` and `timeEnd` properties.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// This is available in Grafana 6.0.0-beta2 and above.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  PatchAnnotation ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									cmd  :=  dtos . PatchAnnotationsCmd { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotationID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":annotationId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "annotationId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotation ,  resp  :=  findAnnotationByID ( c . Req . Context ( ) ,  hs . annotationsRepo ,  annotationID ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  resp  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  resp 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  canSave ,  err  :=  hs . canSaveAnnotation ( c ,  annotation ) ;  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  dashboardGuardianResponse ( err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									existing  :=  annotations . Item { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :     c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										UserID :    c . UserID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										ID :        annotationID , 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Epoch :     annotation . Time , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										EpochEnd :  annotation . TimeEnd , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Text :      annotation . Text , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Tags :      annotation . Tags , 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 22:53:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Data :      annotation . Data , 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . Tags  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										existing . Tags  =  cmd . Tags 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . Text  !=  ""  &&  cmd . Text  !=  existing . Text  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										existing . Text  =  cmd . Text 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . Time  >  0  &&  cmd . Time  !=  existing . Epoch  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										existing . Epoch  =  cmd . Time 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-16 16:49:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . TimeEnd  >  0  &&  cmd . TimeEnd  !=  existing . EpochEnd  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										existing . EpochEnd  =  cmd . TimeEnd 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 22:53:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . Data  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										existing . Data  =  cmd . Data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  err  :=  hs . annotationsRepo . Update ( c . Req . Context ( ) ,  & existing ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 18:04:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . ErrOrFallback ( 500 ,  "Failed to update annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . Success ( "Annotation patched" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route POST /annotations/mass-delete annotations massDeleteAnnotations
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Delete multiple annotations.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  MassDeleteAnnotations ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									cmd  :=  dtos . MassDeleteAnnotationsCmd { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									err  :=  web . Bind ( c . Req ,  & cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  cmd . DashboardUID  !=  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-16 23:33:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										query  :=  dashboards . GetDashboardQuery { OrgID :  c . OrgID ,  UID :  cmd . DashboardUID } 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-25 17:36:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										queryResult ,  err  :=  hs . DashboardService . GetDashboard ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  err  ==  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-25 17:36:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											cmd . DashboardId  =  queryResult . ID 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 17:35:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ( cmd . DashboardId  !=  0  &&  cmd . PanelId  ==  0 )  ||  ( cmd . PanelId  !=  0  &&  cmd . DashboardId  ==  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										err  :=  & AnnotationError { message :  "DashboardId and PanelId are both required for mass delete" } 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									var  deleteParams  * annotations . DeleteParams 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 15:33:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-21 20:31:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// validations only for RBAC. A user can mass delete all annotations in a (dashboard + panel) or a specific annotation
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// if has access to that dashboard.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-25 16:42:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ! hs . AccessControl . IsDisabled ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										var  dashboardId  int64 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										if  cmd . AnnotationId  !=  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											annotation ,  respErr  :=  findAnnotationByID ( c . Req . Context ( ) ,  hs . annotationsRepo ,  cmd . AnnotationId ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											if  respErr  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												return  respErr 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											dashboardId  =  annotation . DashboardID 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											deleteParams  =  & annotations . DeleteParams { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												OrgID :  c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												ID :     cmd . AnnotationId , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											dashboardId  =  cmd . DashboardId 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											deleteParams  =  & annotations . DeleteParams { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
												OrgID :        c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												DashboardID :  cmd . DashboardId , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												PanelID :      cmd . PanelId , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										canSave ,  err  :=  hs . canMassDeleteAnnotations ( c ,  dashboardId ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										if  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											return  dashboardGuardianResponse ( err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									}  else  {  // legacy permissions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										deleteParams  =  & annotations . DeleteParams { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											OrgID :        c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											ID :           cmd . AnnotationId , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											DashboardID :  cmd . DashboardId , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											PanelID :      cmd . PanelId , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									err  =  hs . annotationsRepo . Delete ( c . Req . Context ( ) ,  deleteParams ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 15:33:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 500 ,  "Failed to delete annotations" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 15:33:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . Success ( "Annotations deleted" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 15:33:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route GET /annotations/{annotation_id} annotations getAnnotationByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
									
										
										
										
											2022-09-12 15:40:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// Get Annotation by ID.
  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: getAnnotationByIDResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  GetAnnotationByID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-05-16 23:16:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotationID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":annotationId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "annotationId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotation ,  resp  :=  findAnnotationByID ( c . Req . Context ( ) ,  hs . annotationsRepo ,  annotationID ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-16 23:16:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  resp  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  resp 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  annotation . Email  !=  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										annotation . AvatarURL  =  dtos . GetGravatarUrl ( annotation . Email ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-16 23:16:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  response . JSON ( 200 ,  annotation ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route DELETE /annotations/{annotation_id} annotations deleteAnnotationByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Delete Annotation By ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Deletes the annotation that matches the specified ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  DeleteAnnotationByID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotationID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":annotationId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "annotationId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									annotation ,  resp  :=  findAnnotationByID ( c . Req . Context ( ) ,  hs . annotationsRepo ,  annotationID ,  c . SignedInUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  resp  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  resp 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  canSave ,  err  :=  hs . canSaveAnnotation ( c ,  annotation ) ;  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  dashboardGuardianResponse ( err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									err  =  hs . annotationsRepo . Delete ( c . Req . Context ( ) ,  & annotations . DeleteParams { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :  c . OrgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										ID :     annotationID , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 500 ,  "Failed to delete annotation" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . Success ( "Annotation deleted" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-07 16:31:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  canSaveAnnotation ( c  * contextmodel . ReqContext ,  annotation  * annotations . ItemDTO )  ( bool ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  annotation . GetType ( )  ==  annotations . Dashboard  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  canEditDashboard ( c ,  annotation . DashboardID ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-25 16:42:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  hs . AccessControl . IsDisabled ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  c . SignedInUser . HasRole ( org . RoleEditor ) ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  true ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  canEditDashboard ( c  * contextmodel . ReqContext ,  dashboardID  int64 )  ( bool ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2022-12-15 22:34:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									guard ,  err  :=  guardian . New ( c . Req . Context ( ) ,  dashboardID ,  c . OrgID ,  c . SignedInUser ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  false ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  canEdit ,  err  :=  guard . CanEdit ( ) ;  err  !=  nil  ||  ! canEdit  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  false ,  err 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  true ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  findAnnotationByID ( ctx  context . Context ,  repo  annotations . Repository ,  annotationID  int64 ,  user  * user . SignedInUser )  ( * annotations . ItemDTO ,  response . Response )  {  
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									query  :=  & annotations . ItemQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-04 00:23:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										AnnotationID :  annotationID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :         user . OrgID , 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										SignedInUser :  user , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									items ,  err  :=  repo . Find ( ctx ,  query ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  nil ,  response . Error ( 500 ,  "Failed to find annotation" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  len ( items )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  nil ,  response . Error ( 404 ,  "Annotation not found" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-12 02:43:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  items [ 0 ] ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-06-30 19:42:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:route GET /annotations/tags annotations getAnnotationTags
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Find Annotations Tags.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Find all the event tags created in the annotations.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 200: getAnnotationTagsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  GetAnnotationTags ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-06-30 19:42:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									query  :=  & annotations . TagsQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										OrgID :  c . OrgID , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-30 19:42:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										Tag :    c . Query ( "tag" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Limit :  c . QueryInt64 ( "limit" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									result ,  err  :=  hs . annotationsRepo . FindTags ( c . Req . Context ( ) ,  query ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-30 19:42:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  response . Error ( 500 ,  "Failed to find annotation tags" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  response . JSON ( http . StatusOK ,  annotations . GetAnnotationTagsResponse { Result :  result } ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-30 19:42:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// AnnotationTypeScopeResolver provides an ScopeAttributeResolver able to
  
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								// resolve annotation types. Scope "annotations:id:<id>" will be translated to "annotations:type:<type>,
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// where <type> is the type of annotation with id <id>.
  
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  AnnotationTypeScopeResolver ( annotationsRepo  annotations . Repository )  ( string ,  accesscontrol . ScopeAttributeResolver )  {  
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									prefix  :=  accesscontrol . ScopeAnnotationsProvider . GetResourceScope ( "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  prefix ,  accesscontrol . ScopeAttributeResolverFunc ( func ( ctx  context . Context ,  orgID  int64 ,  initialScope  string )  ( [ ] string ,  error )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										scopeParts  :=  strings . Split ( initialScope ,  ":" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										if  scopeParts [ 0 ]  !=  accesscontrol . ScopeAnnotationsRoot  ||  len ( scopeParts )  !=  3  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  nil ,  accesscontrol . ErrInvalidScope 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										annotationIdStr  :=  scopeParts [ 2 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										annotationId ,  err  :=  strconv . Atoi ( annotationIdStr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  nil ,  accesscontrol . ErrInvalidScope 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										// tempUser is used to resolve annotation type.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										// The annotation doesn't get returned to the real user, so real user's permissions don't matter here.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										tempUser  :=  & user . SignedInUser { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											OrgID :  orgID , 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											Permissions :  map [ int64 ] map [ string ] [ ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												orgID :  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-04 22:12:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
													dashboards . ActionDashboardsRead :      { dashboards . ScopeDashboardsAll } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-11 20:18:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
													accesscontrol . ActionAnnotationsRead :  { accesscontrol . ScopeAnnotationsAll } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-19 15:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										annotation ,  resp  :=  findAnnotationByID ( ctx ,  annotationsRepo ,  int64 ( annotationId ) ,  tempUser ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  resp  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  nil ,  errors . New ( "could not resolve annotation type" ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-22 01:28:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  annotation . GetType ( )  ==  annotations . Organization  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  [ ] string { accesscontrol . ScopeAnnotationsTypeOrganization } ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  [ ] string { accesscontrol . ScopeAnnotationsTypeDashboard } ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 15:29:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-19 00:33:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-03-22 01:28:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  canCreateAnnotation ( c  * contextmodel . ReqContext ,  dashboardId  int64 )  ( bool ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  dashboardId  !=  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-25 16:42:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  ! hs . AccessControl . IsDisabled ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											evaluator  :=  accesscontrol . EvalPermission ( accesscontrol . ActionAnnotationsCreate ,  accesscontrol . ScopeAnnotationsTypeDashboard ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											if  canSave ,  err  :=  hs . AccessControl . Evaluate ( c . Req . Context ( ) ,  c . SignedInUser ,  evaluator ) ;  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												return  canSave ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-15 22:34:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  canEditDashboard ( c ,  dashboardId ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									}  else  {  // organization annotations
 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-25 16:42:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  ! hs . AccessControl . IsDisabled ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											evaluator  :=  accesscontrol . EvalPermission ( accesscontrol . ActionAnnotationsCreate ,  accesscontrol . ScopeAnnotationsTypeOrganization ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											return  hs . AccessControl . Evaluate ( c . Req . Context ( ) ,  c . SignedInUser ,  evaluator ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											return  c . SignedInUser . HasRole ( org . RoleEditor ) ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-22 01:28:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								func  ( hs  * HTTPServer )  canMassDeleteAnnotations ( c  * contextmodel . ReqContext ,  dashboardID  int64 )  ( bool ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  dashboardID  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										evaluator  :=  accesscontrol . EvalPermission ( accesscontrol . ActionAnnotationsDelete ,  accesscontrol . ScopeAnnotationsTypeOrganization ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  hs . AccessControl . Evaluate ( c . Req . Context ( ) ,  c . SignedInUser ,  evaluator ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										evaluator  :=  accesscontrol . EvalPermission ( accesscontrol . ActionAnnotationsDelete ,  accesscontrol . ScopeAnnotationsTypeDashboard ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										canSave ,  err  :=  hs . AccessControl . Evaluate ( c . Req . Context ( ) ,  c . SignedInUser ,  evaluator ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										if  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											return  false ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-20 15:43:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										canSave ,  err  =  canEditDashboard ( c ,  dashboardID ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 05:39:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										if  err  !=  nil  ||  ! canSave  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											return  false ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  true ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters getAnnotationByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  GetAnnotationByIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									AnnotationID  string  ` json:"annotation_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters deleteAnnotationByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  DeleteAnnotationByIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									AnnotationID  string  ` json:"annotation_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters getAnnotations
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  GetAnnotationsParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Find annotations created after specific epoch datetime in milliseconds.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									From  int64  ` json:"from" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Find annotations created before specific epoch datetime in milliseconds.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									To  int64  ` json:"to" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Limit response to annotations created by specific user.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									UserID  int64  ` json:"userId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Find annotations for a specified alert.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									AlertID  int64  ` json:"alertId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Find annotations that are scoped to a specific dashboard
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									DashboardID  int64  ` json:"dashboardId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Find annotations that are scoped to a specific dashboard
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									DashboardUID  string  ` json:"dashboardUID" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Find annotations that are scoped to a specific panel
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									PanelID  int64  ` json:"panelId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Max limit for results returned.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Limit  int64  ` json:"limit" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Use this to filter organization annotations. Organization annotations are annotations from an annotation data source that are not connected specifically to a dashboard or panel. You can filter by multiple tags.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// type: array
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// collectionFormat: multi
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Tags  [ ] string  ` json:"tags" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Return alerts or user created annotations
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Description:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// * `alert`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// * `annotation`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// enum: alert,annotation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Type  string  ` json:"type" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Match any or all tags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									MatchAny  bool  ` json:"matchAny" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters getAnnotationTags
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  GetAnnotationTagsParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Tag is a string that you can use to filter tags.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Tag  string  ` json:"tag" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Max limit for results returned.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// default: 100
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Limit  string  ` json:"limit" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters massDeleteAnnotations
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  MassDeleteAnnotationsParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  dtos . MassDeleteAnnotationsCmd  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters postAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  PostAnnotationParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  dtos . PostAnnotationsCmd  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters postGraphiteAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  PostGraphiteAnnotationParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  dtos . PostGraphiteAnnotationsCmd  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters updateAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  UpdateAnnotationParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									AnnotationID  string  ` json:"annotation_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  dtos . UpdateAnnotationsCmd  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:parameters patchAnnotation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  PatchAnnotationParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									AnnotationID  string  ` json:"annotation_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  dtos . PatchAnnotationsCmd  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:response getAnnotationsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  GetAnnotationsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  [ ] * annotations . ItemDTO  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:response getAnnotationByIDResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  GetAnnotationByIDResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  * annotations . ItemDTO  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:response postAnnotationResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  PostAnnotationResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										// ID Identifier of the created annotation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										// example: 65
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										ID  int64  ` json:"id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										// Message Message of the created annotation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										Message  string  ` json:"message" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									}  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								// swagger:response getAnnotationTagsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								type  GetAnnotationTagsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Body  annotations . GetAnnotationTagsResponse  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}