From 43bdbb0c3a0d93a8bf34ae5e2abbad4586a2581b Mon Sep 17 00:00:00 2001 From: Julien Levesy Date: Mon, 15 Oct 2018 16:46:26 +0200 Subject: Add a delete brand image action on the APIv4 (#9552) --- api4/brand.go | 15 +++++++++++++++ api4/brand_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'api4') diff --git a/api4/brand.go b/api4/brand.go index b6d353a29..54764860c 100644 --- a/api4/brand.go +++ b/api4/brand.go @@ -14,6 +14,7 @@ import ( func (api *API) InitBrand() { api.BaseRoutes.Brand.Handle("/image", api.ApiHandlerTrustRequester(getBrandImage)).Methods("GET") api.BaseRoutes.Brand.Handle("/image", api.ApiSessionRequired(uploadBrandImage)).Methods("POST") + api.BaseRoutes.Brand.Handle("/image", api.ApiSessionRequired(deleteBrandImage)).Methods("DELETE") } func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { @@ -71,3 +72,17 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusCreated) ReturnStatusOK(w) } + +func deleteBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { + if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + if err := c.App.DeleteBrandImage(); err != nil { + c.Err = err + return + } + + ReturnStatusOK(w) +} diff --git a/api4/brand_test.go b/api4/brand_test.go index c1568c5cc..37169d99a 100644 --- a/api4/brand_test.go +++ b/api4/brand_test.go @@ -52,3 +52,30 @@ func TestUploadBrandImage(t *testing.T) { _, resp = th.SystemAdminClient.UploadBrandImage(data) CheckCreatedStatus(t, resp) } + +func TestDeleteBrandImage(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() + + data, err := readTestFile("test.png") + if err != nil { + t.Fatal(err) + } + + _, resp := th.SystemAdminClient.UploadBrandImage(data) + CheckCreatedStatus(t, resp) + + resp = th.Client.DeleteBrandImage() + CheckForbiddenStatus(t, resp) + + th.Client.Logout() + + resp = th.Client.DeleteBrandImage() + CheckUnauthorizedStatus(t, resp) + + resp = th.SystemAdminClient.DeleteBrandImage() + CheckOKStatus(t, resp) + + resp = th.SystemAdminClient.DeleteBrandImage() + CheckNotFoundStatus(t, resp) +} -- cgit v1.2.3-1-g7c22