[MM-24602] Adds local patch channel endpoint (#15032)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e6e563360b
Коммит
b916bae0f7
@@ -16,6 +16,7 @@ func (api *API) InitChannelLocal() {
|
||||
api.BaseRoutes.Channel.Handle("", api.ApiLocal(getChannel)).Methods("GET")
|
||||
api.BaseRoutes.ChannelByName.Handle("", api.ApiLocal(getChannelByName)).Methods("GET")
|
||||
api.BaseRoutes.Channel.Handle("", api.ApiLocal(deleteChannel)).Methods("DELETE")
|
||||
api.BaseRoutes.Channel.Handle("/patch", api.ApiLocal(localPatchChannel)).Methods("PUT")
|
||||
|
||||
api.BaseRoutes.ChannelMember.Handle("", api.ApiLocal(localRemoveChannelMember)).Methods("DELETE")
|
||||
api.BaseRoutes.ChannelMember.Handle("", api.ApiLocal(getChannelMember)).Methods("GET")
|
||||
@@ -162,3 +163,46 @@ func localRemoveChannelMember(c *Context, w http.ResponseWriter, r *http.Request
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func localPatchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireChannelId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
patch := model.ChannelPatchFromJson(r.Body)
|
||||
if patch == nil {
|
||||
c.SetInvalidParam("channel")
|
||||
return
|
||||
}
|
||||
|
||||
originalOldChannel, err := c.App.GetChannel(c.Params.ChannelId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
channel := originalOldChannel.DeepCopy()
|
||||
|
||||
auditRec := c.MakeAuditRecord("localPatchChannel", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("channel", channel)
|
||||
|
||||
channel.Patch(patch)
|
||||
rchannel, err := c.App.UpdateChannel(channel)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.FillInChannelProps(rchannel)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
c.LogAudit("")
|
||||
auditRec.AddMeta("patch", rchannel)
|
||||
|
||||
w.Write([]byte(rchannel.ToJson()))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user