Add a delete brand image action on the APIv4 (#9552)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
160d278592
Коммит
43bdbb0c3a
@@ -14,6 +14,7 @@ import (
|
|||||||
func (api *API) InitBrand() {
|
func (api *API) InitBrand() {
|
||||||
api.BaseRoutes.Brand.Handle("/image", api.ApiHandlerTrustRequester(getBrandImage)).Methods("GET")
|
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(uploadBrandImage)).Methods("POST")
|
||||||
|
api.BaseRoutes.Brand.Handle("/image", api.ApiSessionRequired(deleteBrandImage)).Methods("DELETE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
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)
|
w.WriteHeader(http.StatusCreated)
|
||||||
ReturnStatusOK(w)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,3 +52,30 @@ func TestUploadBrandImage(t *testing.T) {
|
|||||||
_, resp = th.SystemAdminClient.UploadBrandImage(data)
|
_, resp = th.SystemAdminClient.UploadBrandImage(data)
|
||||||
CheckCreatedStatus(t, resp)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
16
app/brand.go
16
app/brand.go
@@ -77,3 +77,19 @@ func (a *App) GetBrandImage() ([]byte, *model.AppError) {
|
|||||||
|
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) DeleteBrandImage() *model.AppError {
|
||||||
|
filePath := BRAND_FILE_PATH + BRAND_FILE_NAME
|
||||||
|
|
||||||
|
fileExists, err := a.FileExists(filePath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fileExists {
|
||||||
|
return model.NewAppError("DeleteBrandImage", "api.admin.delete_brand_image.storage.not_found", nil, "", http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.RemoveFile(filePath)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2997,6 +2997,16 @@ func (c *Client4) GetBrandImage() ([]byte, *Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) DeleteBrandImage() *Response {
|
||||||
|
r, err := c.DoApiDelete(c.GetBrandRoute() + "/image")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return BuildErrorResponse(r, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return BuildResponse(r)
|
||||||
|
}
|
||||||
|
|
||||||
// UploadBrandImage sets the brand image for the system.
|
// UploadBrandImage sets the brand image for the system.
|
||||||
func (c *Client4) UploadBrandImage(data []byte) (bool, *Response) {
|
func (c *Client4) UploadBrandImage(data []byte) (bool, *Response) {
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user