mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Light improve of massive delete annotation api (#12390)
* fix delete annotations * fix self assignment * add right unit test using admin role
This commit is contained in:
parent
3bf12e4ff5
commit
eb4d860fcb
@ -37,7 +37,6 @@ func GetAnnotations(c *m.ReqContext) Response {
|
|||||||
if item.Email != "" {
|
if item.Email != "" {
|
||||||
item.AvatarUrl = dtos.GetGravatarUrl(item.Email)
|
item.AvatarUrl = dtos.GetGravatarUrl(item.Email)
|
||||||
}
|
}
|
||||||
item.Time = item.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON(200, items)
|
return JSON(200, items)
|
||||||
@ -214,7 +213,8 @@ func DeleteAnnotations(c *m.ReqContext, cmd dtos.DeleteAnnotationsCmd) Response
|
|||||||
repo := annotations.GetRepository()
|
repo := annotations.GetRepository()
|
||||||
|
|
||||||
err := repo.Delete(&annotations.DeleteParams{
|
err := repo.Delete(&annotations.DeleteParams{
|
||||||
AlertId: cmd.PanelId,
|
Id: cmd.AnnotationId,
|
||||||
|
RegionId: cmd.RegionId,
|
||||||
DashboardId: cmd.DashboardId,
|
DashboardId: cmd.DashboardId,
|
||||||
PanelId: cmd.PanelId,
|
PanelId: cmd.PanelId,
|
||||||
})
|
})
|
||||||
|
@ -100,6 +100,11 @@ func TestAnnotationsApiEndpoint(t *testing.T) {
|
|||||||
Id: 1,
|
Id: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteCmd := dtos.DeleteAnnotationsCmd{
|
||||||
|
DashboardId: 1,
|
||||||
|
PanelId: 1,
|
||||||
|
}
|
||||||
|
|
||||||
viewerRole := m.ROLE_VIEWER
|
viewerRole := m.ROLE_VIEWER
|
||||||
editorRole := m.ROLE_EDITOR
|
editorRole := m.ROLE_EDITOR
|
||||||
|
|
||||||
@ -171,6 +176,25 @@ func TestAnnotationsApiEndpoint(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("When user is an Admin", func() {
|
||||||
|
role := m.ROLE_ADMIN
|
||||||
|
Convey("Should be able to do anything", func() {
|
||||||
|
postAnnotationScenario("When calling POST on", "/api/annotations", "/api/annotations", role, cmd, func(sc *scenarioContext) {
|
||||||
|
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
|
||||||
|
So(sc.resp.Code, ShouldEqual, 200)
|
||||||
|
})
|
||||||
|
|
||||||
|
putAnnotationScenario("When calling PUT on", "/api/annotations/1", "/api/annotations/:annotationId", role, updateCmd, func(sc *scenarioContext) {
|
||||||
|
sc.fakeReqWithParams("PUT", sc.url, map[string]string{}).exec()
|
||||||
|
So(sc.resp.Code, ShouldEqual, 200)
|
||||||
|
})
|
||||||
|
deleteAnnotationsScenario("When calling POST on", "/api/annotations/mass-delete", "/api/annotations/mass-delete", role, deleteCmd, func(sc *scenarioContext) {
|
||||||
|
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
|
||||||
|
So(sc.resp.Code, ShouldEqual, 200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,3 +263,26 @@ func putAnnotationScenario(desc string, url string, routePattern string, role m.
|
|||||||
fn(sc)
|
fn(sc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteAnnotationsScenario(desc string, url string, routePattern string, role m.RoleType, cmd dtos.DeleteAnnotationsCmd, fn scenarioFunc) {
|
||||||
|
Convey(desc+" "+url, func() {
|
||||||
|
defer bus.ClearBusHandlers()
|
||||||
|
|
||||||
|
sc := setupScenarioContext(url)
|
||||||
|
sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
|
||||||
|
sc.context = c
|
||||||
|
sc.context.UserId = TestUserID
|
||||||
|
sc.context.OrgId = TestOrgID
|
||||||
|
sc.context.OrgRole = role
|
||||||
|
|
||||||
|
return DeleteAnnotations(c, cmd)
|
||||||
|
})
|
||||||
|
|
||||||
|
fakeAnnoRepo = &fakeAnnotationsRepo{}
|
||||||
|
annotations.SetRepository(fakeAnnoRepo)
|
||||||
|
|
||||||
|
sc.m.Post(routePattern, sc.defaultHandler)
|
||||||
|
|
||||||
|
fn(sc)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user