From a7f5512ff3435f7c07101caa50b44f1c2aa710cf Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Mon, 16 Aug 2021 09:10:31 -0700 Subject: [PATCH] [MM-18391] Removing convert channel endpoint (#18015) * removing convert endpoint * fixing translations Co-authored-by: Benjamin Cooke --- api4/channel.go | 55 ----------------------------------- api4/channel_test.go | 69 -------------------------------------------- i18n/en.json | 8 ----- model/client4.go | 16 ---------- 4 files changed, 148 deletions(-) diff --git a/api4/channel.go b/api4/channel.go index 09326dd896..286ee5ad9f 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -48,7 +48,6 @@ func (api *API) InitChannel() { api.BaseRoutes.Channel.Handle("", api.ApiSessionRequired(getChannel)).Methods("GET") api.BaseRoutes.Channel.Handle("", api.ApiSessionRequired(updateChannel)).Methods("PUT") api.BaseRoutes.Channel.Handle("/patch", api.ApiSessionRequired(patchChannel)).Methods("PUT") - api.BaseRoutes.Channel.Handle("/convert", api.ApiSessionRequired(convertChannelToPrivate)).Methods("POST") api.BaseRoutes.Channel.Handle("/privacy", api.ApiSessionRequired(updateChannelPrivacy)).Methods("PUT") api.BaseRoutes.Channel.Handle("/restore", api.ApiSessionRequired(restoreChannel)).Methods("POST") api.BaseRoutes.Channel.Handle("", api.ApiSessionRequired(deleteChannel)).Methods("DELETE") @@ -228,60 +227,6 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { } } -func convertChannelToPrivate(c *Context, w http.ResponseWriter, r *http.Request) { - c.RequireChannelId() - if c.Err != nil { - return - } - - oldPublicChannel, err := c.App.GetChannel(c.Params.ChannelId) - if err != nil { - c.Err = err - return - } - - auditRec := c.MakeAuditRecord("convertChannelToPrivate", audit.Fail) - defer c.LogAuditRec(auditRec) - auditRec.AddMeta("channel", oldPublicChannel) - - if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionConvertPublicChannelToPrivate) { - c.SetPermissionError(model.PermissionConvertPublicChannelToPrivate) - return - } - - if oldPublicChannel.Type == model.ChannelTypePrivate { - c.Err = model.NewAppError("convertChannelToPrivate", "api.channel.convert_channel_to_private.private_channel_error", nil, "", http.StatusBadRequest) - return - } - - if oldPublicChannel.Name == model.DefaultChannelName { - c.Err = model.NewAppError("convertChannelToPrivate", "api.channel.convert_channel_to_private.default_channel_error", nil, "", http.StatusBadRequest) - return - } - - user, err := c.App.GetUser(c.AppContext.Session().UserId) - if err != nil { - c.Err = err - return - } - auditRec.AddMeta("user", user) - - oldPublicChannel.Type = model.ChannelTypePrivate - - rchannel, err := c.App.UpdateChannelPrivacy(c.AppContext, oldPublicChannel, user) - if err != nil { - c.Err = err - return - } - - auditRec.Success() - c.LogAudit("name=" + rchannel.Name) - - if err := json.NewEncoder(w).Encode(rchannel); err != nil { - mlog.Warn("Error while writing response", mlog.Err(err)) - } -} - func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireChannelId() if c.Err != nil { diff --git a/api4/channel_test.go b/api4/channel_test.go index efd7544c34..e9de38336d 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -1855,75 +1855,6 @@ func TestPermanentDeleteChannel(t *testing.T) { }, "Permanent deletion with EnableAPIChannelDeletion set") } -func TestConvertChannelToPrivate(t *testing.T) { - th := Setup(t).InitBasic() - defer th.TearDown() - client := th.Client - - defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, th.BasicTeam.Id, false) - _, resp, err := client.ConvertChannelToPrivate(defaultChannel.Id) - require.Error(t, err) - CheckForbiddenStatus(t, resp) - - privateChannel := th.CreatePrivateChannel() - _, resp, err = client.ConvertChannelToPrivate(privateChannel.Id) - require.Error(t, err) - CheckForbiddenStatus(t, resp) - - publicChannel := th.CreatePublicChannel() - _, resp, err = client.ConvertChannelToPrivate(publicChannel.Id) - require.Error(t, err) - CheckForbiddenStatus(t, resp) - - th.LoginTeamAdmin() - th.RemovePermissionFromRole(model.PermissionConvertPublicChannelToPrivate.Id, model.TeamAdminRoleId) - - _, resp, err = client.ConvertChannelToPrivate(publicChannel.Id) - require.Error(t, err) - CheckForbiddenStatus(t, resp) - - th.AddPermissionToRole(model.PermissionConvertPublicChannelToPrivate.Id, model.TeamAdminRoleId) - - rchannel, resp, err := client.ConvertChannelToPrivate(publicChannel.Id) - require.NoError(t, err) - CheckOKStatus(t, resp) - require.Equal(t, model.ChannelTypePrivate, rchannel.Type, "channel should be converted from public to private") - - rchannel, resp, err = th.SystemAdminClient.ConvertChannelToPrivate(privateChannel.Id) - require.Error(t, err) - CheckBadRequestStatus(t, resp) - require.Nil(t, rchannel, "should not return a channel") - - rchannel, resp, err = th.SystemAdminClient.ConvertChannelToPrivate(defaultChannel.Id) - require.Error(t, err) - CheckBadRequestStatus(t, resp) - require.Nil(t, rchannel, "should not return a channel") - - WebSocketClient, err := th.CreateWebSocketClient() - require.NoError(t, err) - WebSocketClient.Listen() - - publicChannel2 := th.CreatePublicChannel() - rchannel, resp, err = th.SystemAdminClient.ConvertChannelToPrivate(publicChannel2.Id) - require.NoError(t, err) - CheckOKStatus(t, resp) - require.Equal(t, model.ChannelTypePrivate, rchannel.Type, "channel should be converted from public to private") - - timeout := time.After(10 * time.Second) - - for { - select { - case resp := <-WebSocketClient.EventChannel: - if resp.EventType() == model.WebsocketEventChannelConverted && resp.GetData()["channel_id"].(string) == publicChannel2.Id { - return - } - case <-timeout: - require.Fail(t, "timed out waiting for channel_converted event") - return - } - } -} - func TestUpdateChannelPrivacy(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/i18n/en.json b/i18n/en.json index db9b06b409..99434f5194 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -227,14 +227,6 @@ "id": "api.channel.channel_member_counts_by_group.license.error", "translation": "Your license does not support groups" }, - { - "id": "api.channel.convert_channel_to_private.default_channel_error", - "translation": "This default channel cannot be converted into a private channel." - }, - { - "id": "api.channel.convert_channel_to_private.private_channel_error", - "translation": "The channel requested to convert is already a private channel." - }, { "id": "api.channel.create_channel.direct_channel.app_error", "translation": "Must use createDirectChannel API service for direct message channel creation." diff --git a/model/client4.go b/model/client4.go index 58f634d3ad..cd88de794e 100644 --- a/model/client4.go +++ b/model/client4.go @@ -2499,22 +2499,6 @@ func (c *Client4) PatchChannel(channelId string, patch *ChannelPatch) (*Channel, return ch, BuildResponse(r), nil } -// ConvertChannelToPrivate converts public to private channel. -func (c *Client4) ConvertChannelToPrivate(channelId string) (*Channel, *Response, error) { - r, err := c.DoApiPost(c.channelRoute(channelId)+"/convert", "") - if err != nil { - return nil, BuildResponse(r), err - } - defer closeBody(r) - - var ch *Channel - err = json.NewDecoder(r.Body).Decode(&ch) - if err != nil { - return nil, BuildResponse(r), NewAppError("ConvertChannelToPrivate", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) - } - return ch, BuildResponse(r), nil -} - // UpdateChannelPrivacy updates channel privacy func (c *Client4) UpdateChannelPrivacy(channelId string, privacy ChannelType) (*Channel, *Response, error) { requestBody := map[string]string{"privacy": string(privacy)}