[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.Channel.Handle("", api.ApiLocal(getChannel)).Methods("GET")
|
||||||
api.BaseRoutes.ChannelByName.Handle("", api.ApiLocal(getChannelByName)).Methods("GET")
|
api.BaseRoutes.ChannelByName.Handle("", api.ApiLocal(getChannelByName)).Methods("GET")
|
||||||
api.BaseRoutes.Channel.Handle("", api.ApiLocal(deleteChannel)).Methods("DELETE")
|
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(localRemoveChannelMember)).Methods("DELETE")
|
||||||
api.BaseRoutes.ChannelMember.Handle("", api.ApiLocal(getChannelMember)).Methods("GET")
|
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)
|
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()))
|
||||||
|
}
|
||||||
|
|||||||
@@ -282,11 +282,13 @@ func TestPatchChannel(t *testing.T) {
|
|||||||
_, resp = Client.PatchChannel(th.BasicChannel.Id, patch)
|
_, resp = Client.PatchChannel(th.BasicChannel.Id, patch)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
_, resp = th.SystemAdminClient.PatchChannel(th.BasicChannel.Id, patch)
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
|
_, resp = client.PatchChannel(th.BasicChannel.Id, patch)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
_, resp = th.SystemAdminClient.PatchChannel(th.BasicPrivateChannel.Id, patch)
|
_, resp = client.PatchChannel(th.BasicPrivateChannel.Id, patch)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
})
|
||||||
|
|
||||||
// Test updating the header of someone else's GM channel.
|
// Test updating the header of someone else's GM channel.
|
||||||
user1 := th.CreateUser()
|
user1 := th.CreateUser()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user