mirror of https://github.com/grafana/grafana.git
				
				
				
			AnnotationsApi: GET /api/annotations/:annotationId (#47739)
This commit is contained in:
		
							parent
							
								
									2d4065600c
								
							
						
					
					
						commit
						3d922a4e67
					
				|  | @ -351,6 +351,26 @@ func (hs *HTTPServer) MassDeleteAnnotations(c *models.ReqContext) response.Respo | ||||||
| 	return response.Success("Annotations deleted") | 	return response.Success("Annotations deleted") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (hs *HTTPServer) GetAnnotationByID(c *models.ReqContext) response.Response { | ||||||
|  | 	annotationID, err := strconv.ParseInt(web.Params(c.Req)[":annotationId"], 10, 64) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return response.Error(http.StatusBadRequest, "annotationId is invalid", err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	repo := annotations.GetRepository() | ||||||
|  | 
 | ||||||
|  | 	annotation, resp := findAnnotationByID(c.Req.Context(), repo, annotationID, c.SignedInUser) | ||||||
|  | 	if resp != nil { | ||||||
|  | 		return resp | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if annotation.Email != "" { | ||||||
|  | 		annotation.AvatarUrl = dtos.GetGravatarUrl(annotation.Email) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return response.JSON(200, annotation) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (hs *HTTPServer) DeleteAnnotationByID(c *models.ReqContext) response.Response { | func (hs *HTTPServer) DeleteAnnotationByID(c *models.ReqContext) response.Response { | ||||||
| 	annotationID, err := strconv.ParseInt(web.Params(c.Req)[":annotationId"], 10, 64) | 	annotationID, err := strconv.ParseInt(web.Params(c.Req)[":annotationId"], 10, 64) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  |  | ||||||
|  | @ -512,6 +512,24 @@ func TestAPI_Annotations_AccessControl(t *testing.T) { | ||||||
| 			}, | 			}, | ||||||
| 			want: http.StatusForbidden, | 			want: http.StatusForbidden, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "AccessControl getting annotation by ID with correct permissions is allowed", | ||||||
|  | 			args: args{ | ||||||
|  | 				permissions: []*accesscontrol.Permission{{Action: accesscontrol.ActionAnnotationsRead, Scope: accesscontrol.ScopeAnnotationsAll}}, | ||||||
|  | 				url:         "/api/annotations/1", | ||||||
|  | 				method:      http.MethodGet, | ||||||
|  | 			}, | ||||||
|  | 			want: http.StatusOK, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "AccessControl getting annotation by ID without permissions is forbidden", | ||||||
|  | 			args: args{ | ||||||
|  | 				permissions: []*accesscontrol.Permission{}, | ||||||
|  | 				url:         "/api/annotations", | ||||||
|  | 				method:      http.MethodGet, | ||||||
|  | 			}, | ||||||
|  | 			want: http.StatusForbidden, | ||||||
|  | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name: "AccessControl getting tags for annotations with correct permissions is allowed", | 			name: "AccessControl getting tags for annotations with correct permissions is allowed", | ||||||
| 			args: args{ | 			args: args{ | ||||||
|  |  | ||||||
|  | @ -475,6 +475,7 @@ func (hs *HTTPServer) registerRoutes() { | ||||||
| 
 | 
 | ||||||
| 		apiRoute.Group("/annotations", func(annotationsRoute routing.RouteRegister) { | 		apiRoute.Group("/annotations", func(annotationsRoute routing.RouteRegister) { | ||||||
| 			annotationsRoute.Post("/", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsCreate)), routing.Wrap(hs.PostAnnotation)) | 			annotationsRoute.Post("/", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsCreate)), routing.Wrap(hs.PostAnnotation)) | ||||||
|  | 			annotationsRoute.Get("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsRead, ac.ScopeAnnotationsID)), routing.Wrap(hs.GetAnnotationByID)) | ||||||
| 			annotationsRoute.Delete("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsDelete, ac.ScopeAnnotationsID)), routing.Wrap(hs.DeleteAnnotationByID)) | 			annotationsRoute.Delete("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsDelete, ac.ScopeAnnotationsID)), routing.Wrap(hs.DeleteAnnotationByID)) | ||||||
| 			annotationsRoute.Put("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsWrite, ac.ScopeAnnotationsID)), routing.Wrap(hs.UpdateAnnotation)) | 			annotationsRoute.Put("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsWrite, ac.ScopeAnnotationsID)), routing.Wrap(hs.UpdateAnnotation)) | ||||||
| 			annotationsRoute.Patch("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsWrite, ac.ScopeAnnotationsID)), routing.Wrap(hs.PatchAnnotation)) | 			annotationsRoute.Patch("/:annotationId", authorize(reqSignedIn, ac.EvalPermission(ac.ActionAnnotationsWrite, ac.ScopeAnnotationsID)), routing.Wrap(hs.PatchAnnotation)) | ||||||
|  |  | ||||||
|  | @ -16,6 +16,15 @@ import ( | ||||||
| // 401: unauthorisedError
 | // 401: unauthorisedError
 | ||||||
| // 500: internalServerError
 | // 500: internalServerError
 | ||||||
| 
 | 
 | ||||||
|  | // swagger:route GET /annotations/{annotation_id} annotations getAnnotation
 | ||||||
|  | //
 | ||||||
|  | // Get Annotation by Id.
 | ||||||
|  | //
 | ||||||
|  | // Responses:
 | ||||||
|  | // 200: getAnnotationResponse
 | ||||||
|  | // 401: unauthorisedError
 | ||||||
|  | // 500: internalServerError
 | ||||||
|  | 
 | ||||||
| // swagger:route POST /annotations/mass-delete annotations massDeleteAnnotations
 | // swagger:route POST /annotations/mass-delete annotations massDeleteAnnotations
 | ||||||
| //
 | //
 | ||||||
| // Delete multiple annotations.
 | // Delete multiple annotations.
 | ||||||
|  | @ -216,6 +225,13 @@ type GetAnnotationsResponse struct { | ||||||
| 	Body []*annotations.ItemDTO `json:"body"` | 	Body []*annotations.ItemDTO `json:"body"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // swagger:response getAnnotationResponse
 | ||||||
|  | type GetAnnotationResponse struct { | ||||||
|  | 	// The response message
 | ||||||
|  | 	// in: body
 | ||||||
|  | 	Body *annotations.ItemDTO `json:"body"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // swagger:response createAnnotationResponse
 | // swagger:response createAnnotationResponse
 | ||||||
| type CreateAnnotationResponse struct { | type CreateAnnotationResponse struct { | ||||||
| 	// The response message
 | 	// The response message
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue