[MM-18391] Removing convert channel endpoint (#18015)

* removing convert endpoint

* fixing translations

Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Этот коммит содержится в:
Ben Cooke
2021-08-16 09:10:31 -07:00
коммит произвёл GitHub
родитель f43aa7d925
Коммит a7f5512ff3
4 изменённых файлов: 0 добавлений и 148 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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()

Просмотреть файл

@@ -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."

Просмотреть файл

@@ -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)}