From 7274f4c6c2ad519d5a827a84cb3e28f64e266fbb Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Thu, 19 Dec 2019 18:50:20 +0100 Subject: [PATCH] [MM-21020] Return same error when creating a duplicate channel (#13429) * Return same error when trying to create a channel with the same name of an existing one * Remove unused arguments --- i18n/en.json | 4 ---- store/sqlstore/channel_store.go | 3 --- store/storetest/channel_store.go | 24 ++++++++++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 96398dee4c..4ef9706bfd 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5942,10 +5942,6 @@ "id": "store.sql_channel.save_channel.limit.app_error", "translation": "You've reached the limit of the number of allowed channels." }, - { - "id": "store.sql_channel.save_channel.previously.app_error", - "translation": "A channel with that URL was previously created" - }, { "id": "store.sql_channel.save_channel.save.app_error", "translation": "Unable to save the channel" diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 12bf86f161..2d1e7d611e 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -575,9 +575,6 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo if IsUniqueConstraintError(err, []string{"Name", "channels_name_teamid_key"}) { dupChannel := model.Channel{} s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name}) - if dupChannel.DeleteAt > 0 { - return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.previously.app_error", nil, "id="+channel.Id+", "+err.Error(), http.StatusBadRequest) - } return &dupChannel, model.NewAppError("SqlChannelStore.Save", store.CHANNEL_EXISTS_ERROR, nil, "id="+channel.Id+", "+err.Error(), http.StatusBadRequest) } return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.save.app_error", nil, "id="+channel.Id+", "+err.Error(), http.StatusInternalServerError) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index baaa67578d..218181f6ce 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -114,6 +114,30 @@ func testChannelStoreSave(t *testing.T, ss store.Store) { o1.Type = model.CHANNEL_DIRECT _, err = ss.Channel().Save(&o1, -1) require.NotNil(t, err, "should not be able to save direct channel") + + o1 = model.Channel{} + o1.TeamId = teamId + o1.DisplayName = "Name" + o1.Name = "zz" + model.NewId() + "b" + o1.Type = model.CHANNEL_OPEN + + _, err = ss.Channel().Save(&o1, -1) + require.Nil(t, err, "should have saved channel") + + o2 := o1 + o2.Id = "" + + _, err = ss.Channel().Save(&o2, -1) + require.NotNil(t, err, "should have failed to save a duplicate channel") + require.Equal(t, store.CHANNEL_EXISTS_ERROR, err.Id) + + err = ss.Channel().Delete(o1.Id, 100) + require.Nil(t, err, "should have deleted channel") + + o2.Id = "" + _, err = ss.Channel().Save(&o2, -1) + require.NotNil(t, err, "should have failed to save a duplicate of an archived channel") + require.Equal(t, store.CHANNEL_EXISTS_ERROR, err.Id) } func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSupplier) {