Fix duplicated channel's name error (#24080)
* Fix duplicated channel's name error * Test the SQL store layer instead of the API layer * Remove unused variable and query
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f1468a1958
Коммит
dbf63214ac
@@ -778,12 +778,7 @@ func (s SqlChannelStore) updateChannelT(transaction *sqlxTxWrapper, channel *mod
|
||||
WHERE Id=:Id`, channel)
|
||||
if err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"Name", "channels_name_teamid_key"}) {
|
||||
dupChannel := model.Channel{}
|
||||
s.GetReplicaX().Get(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name= :Name AND DeleteAt > 0", map[string]any{"TeamId": channel.TeamId, "Name": channel.Name})
|
||||
if dupChannel.DeleteAt > 0 {
|
||||
return nil, store.NewErrInvalidInput("Channel", "Id", channel.Id)
|
||||
}
|
||||
return nil, store.NewErrInvalidInput("Channel", "Id", channel.Id)
|
||||
return nil, store.NewErrInvalidInput("Channel", "Name", channel.Name)
|
||||
}
|
||||
return nil, errors.Wrapf(err, "failed to update channel with id=%s", channel.Id)
|
||||
}
|
||||
|
||||
@@ -351,6 +351,13 @@ func testChannelStoreUpdate(t *testing.T, ss store.Store) {
|
||||
o2.Name = o1.Name
|
||||
_, err = ss.Channel().Update(&o2)
|
||||
require.Error(t, err, "update should have failed because of existing name")
|
||||
|
||||
// Make sure that the error correctly reports the wrong field to be Name
|
||||
// See https://mattermost.atlassian.net/browse/MM-53756
|
||||
var invalidInputErr *store.ErrInvalidInput
|
||||
require.ErrorAs(t, err, &invalidInputErr)
|
||||
require.Equal(t, invalidInputErr.Entity, "Channel")
|
||||
require.Equal(t, invalidInputErr.Field, "Name")
|
||||
}
|
||||
|
||||
func testGetChannelUnread(t *testing.T, ss store.Store) {
|
||||
|
||||
Ссылка в новой задаче
Block a user