diff --git a/app/channel.go b/app/channel.go index d4745bc1a9..edfb41f854 100644 --- a/app/channel.go +++ b/app/channel.go @@ -144,10 +144,6 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.direct_channel.app_error", nil, "", http.StatusBadRequest) } - if strings.Index(channel.Name, "__") > 0 { - return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.invalid_character.app_error", nil, "", http.StatusBadRequest) - } - if len(channel.TeamId) == 0 { return nil, model.NewAppError("CreateChannelWithUser", "app.channel.create_channel.no_team_id.app_error", nil, "", http.StatusBadRequest) } @@ -464,14 +460,6 @@ func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError // UpdateChannel updates a given channel by its Id. It also publishes the CHANNEL_UPDATED event. func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) { - userIds := strings.Split(channel.Name, "__") - if channel.Type != model.CHANNEL_DIRECT && - len(userIds) == 2 && - model.IsValidId(userIds[0]) && - model.IsValidId(userIds[1]) { - return nil, model.NewAppError("UpdateChannel", "api.channel.update_channel.invalid_character.app_error", nil, "", http.StatusBadRequest) - } - _, err := a.Srv().Store.Channel().Update(channel) if err != nil { return nil, err diff --git a/app/channel_test.go b/app/channel_test.go index 23025ed6c0..ef7ded9c89 100644 --- a/app/channel_test.go +++ b/app/channel_test.go @@ -744,6 +744,14 @@ func TestRenameChannel(t *testing.T) { "", "", }, + { + "Success on rename open channel with consecutive underscores in name", + th.createChannel(th.BasicTeam, model.CHANNEL_OPEN), + false, + "foo__bar", + "foo__bar", + "New Display Name", + }, { "Fail on rename direct message channel", th.CreateDmChannel(th.BasicUser2), diff --git a/i18n/en.json b/i18n/en.json index d3e7372448..3f78acebc1 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -259,10 +259,6 @@ "id": "api.channel.create_channel.direct_channel.app_error", "translation": "Must use createDirectChannel API service for direct message channel creation." }, - { - "id": "api.channel.create_channel.invalid_character.app_error", - "translation": "Invalid character '__' in channel name for non-direct channel." - }, { "id": "api.channel.create_channel.max_channel_limit.app_error", "translation": "Unable to create more than {{.MaxChannelsPerTeam}} channels for current team." @@ -427,10 +423,6 @@ "id": "api.channel.update_channel.deleted.app_error", "translation": "The channel has been archived or deleted." }, - { - "id": "api.channel.update_channel.invalid_character.app_error", - "translation": "Invalid channel name. User ids are not permitted in channel name for non-direct message channels." - }, { "id": "api.channel.update_channel.tried.app_error", "translation": "Tried to perform an invalid update of the default channel {{.Channel}}." @@ -4510,6 +4502,10 @@ "id": "model.channel.is_valid.id.app_error", "translation": "Invalid Id." }, + { + "id": "model.channel.is_valid.name.app_error", + "translation": "Invalid channel name. User ids are not permitted in channel name for non-direct message channels." + }, { "id": "model.channel.is_valid.purpose.app_error", "translation": "Invalid purpose." diff --git a/model/channel.go b/model/channel.go index c67e730ee8..ae95f2eb78 100644 --- a/model/channel.go +++ b/model/channel.go @@ -234,6 +234,11 @@ func (o *Channel) IsValid() *AppError { return NewAppError("Channel.IsValid", "model.channel.is_valid.creator_id.app_error", nil, "", http.StatusBadRequest) } + userIds := strings.Split(o.Name, "__") + if o.Type != CHANNEL_DIRECT && len(userIds) == 2 && IsValidId(userIds[0]) && IsValidId(userIds[1]) { + return NewAppError("Channel.IsValid", "model.channel.is_valid.name.app_error", nil, "", http.StatusBadRequest) + } + return nil }