mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-24602] Adds local patch channel endpoint (#15032)
This commit is contained in:
committed by
GitHub
parent
e6e563360b
commit
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()))
|
||||
}
|
||||
|
||||
@@ -282,11 +282,13 @@ func TestPatchChannel(t *testing.T) {
|
||||
_, resp = Client.PatchChannel(th.BasicChannel.Id, patch)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.PatchChannel(th.BasicChannel.Id, patch)
|
||||
CheckNoError(t, resp)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp = client.PatchChannel(th.BasicChannel.Id, patch)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.PatchChannel(th.BasicPrivateChannel.Id, patch)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = client.PatchChannel(th.BasicPrivateChannel.Id, patch)
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
|
||||
// Test updating the header of someone else's GM channel.
|
||||
user1 := th.CreateUser()
|
||||
|
||||
Reference in New Issue
Block a user