mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Merge pull request #143 from rgarmsen2295/mm-1416
MM-1416 Changed error message when adding a previously deleted channel to be better suited
This commit is contained in:
@@ -52,6 +52,8 @@ func TestCreateChannel(t *testing.T) {
|
||||
t.Fatal("Cannot create an existing")
|
||||
}
|
||||
|
||||
savedId := rchannel.Data.(*model.Channel).Id
|
||||
|
||||
rchannel.Data.(*model.Channel).Id = ""
|
||||
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err != nil {
|
||||
if err.Message != "A channel with that name already exists" {
|
||||
@@ -63,6 +65,13 @@ func TestCreateChannel(t *testing.T) {
|
||||
t.Fatal("should have been an error")
|
||||
}
|
||||
|
||||
Client.DeleteChannel(savedId)
|
||||
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err != nil {
|
||||
if err.Message != "A channel with that name was previously created" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
channel = model.Channel{DisplayName: "Channel on Different Team", Name: "aaaa" + model.NewId() + "abbb", Type: model.CHANNEL_OPEN, TeamId: team2.Id}
|
||||
|
||||
if _, err := Client.CreateChannel(&channel); err.StatusCode != http.StatusForbidden {
|
||||
|
||||
@@ -79,7 +79,13 @@ func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel {
|
||||
|
||||
if err := s.GetMaster().Insert(channel); err != nil {
|
||||
if strings.Contains(err.Error(), "Duplicate entry") && strings.Contains(err.Error(), "for key 'Name'") {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Save", "A channel with that name already exists", "id="+channel.Id+", "+err.Error())
|
||||
dupChannel := model.Channel{}
|
||||
s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId=? AND Name=? AND DeleteAt > 0", channel.TeamId, channel.Name)
|
||||
if (dupChannel.DeleteAt > 0) {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name was previously created", "id="+channel.Id+", "+err.Error())
|
||||
} else {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name already exists", "id="+channel.Id+", "+err.Error())
|
||||
}
|
||||
} else {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Save", "We couldn't save the channel", "id="+channel.Id+", "+err.Error())
|
||||
}
|
||||
@@ -111,7 +117,13 @@ func (s SqlChannelStore) Update(channel *model.Channel) StoreChannel {
|
||||
|
||||
if count, err := s.GetMaster().Update(channel); err != nil {
|
||||
if strings.Contains(err.Error(), "Duplicate entry") && strings.Contains(err.Error(), "for key 'Name'") {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name already exists", "id="+channel.Id+", "+err.Error())
|
||||
dupChannel := model.Channel{}
|
||||
s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId=? AND Name=? AND DeleteAt > 0", channel.TeamId, channel.Name)
|
||||
if (dupChannel.DeleteAt > 0) {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name was previously created", "id="+channel.Id+", "+err.Error())
|
||||
} else {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name already exists", "id="+channel.Id+", "+err.Error())
|
||||
}
|
||||
} else {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Update", "We encounted an error updating the channel", "id="+channel.Id+", "+err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user