implement DELETE /emoji/{emoji_id} fro apiV4 (#6021)
implement GET /emoji/{emoji_id} for apiv4
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
62974f19cd
Коммит
80684ad69f
@@ -20,6 +20,8 @@ func InitEmoji() {
|
||||
|
||||
BaseRoutes.Emojis.Handle("", ApiSessionRequired(createEmoji)).Methods("POST")
|
||||
BaseRoutes.Emojis.Handle("", ApiSessionRequired(getEmojiList)).Methods("GET")
|
||||
BaseRoutes.Emoji.Handle("", ApiSessionRequired(deleteEmoji)).Methods("DELETE")
|
||||
BaseRoutes.Emoji.Handle("", ApiSessionRequired(getEmoji)).Methods("GET")
|
||||
}
|
||||
|
||||
func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -81,3 +83,49 @@ func getEmojiList(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.EmojiListToJson(listEmoji)))
|
||||
}
|
||||
}
|
||||
|
||||
func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireEmojiId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
emoji, err := app.GetEmoji(c.Params.EmojiId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if c.Session.UserId != emoji.CreatorId && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.Err = model.NewAppError("deleteImage", "api.emoji.delete.permissions.app_error", nil, "user_id="+c.Session.UserId, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
err = app.DeleteEmoji(emoji)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
}
|
||||
|
||||
func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireEmojiId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
|
||||
c.Err = model.NewAppError("getEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
emoji, err := app.GetEmoji(c.Params.EmojiId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(emoji.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user