diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/channel.go | 15 | ||||
-rw-r--r-- | app/channel_test.go | 14 |
2 files changed, 29 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go index f9e77d737..ce183e6a9 100644 --- a/app/channel.go +++ b/app/channel.go @@ -159,6 +159,21 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod return rchannel, nil } +// RenameChannel is used to rename the channel Name and the DisplayName fields +func (a *App) RenameChannel(channel *model.Channel, newChannelName string, newDisplayName string) (*model.Channel, *model.AppError) { + channel.Name = newChannelName + if newDisplayName != "" { + channel.DisplayName = newDisplayName + } + + newChannel, err := a.UpdateChannel(channel) + if err != nil { + return nil, err + } + + return newChannel, nil +} + func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) { if result := <-a.Srv.Store.Channel().Save(channel, *a.Config().TeamSettings.MaxChannelsPerTeam); result.Err != nil { return nil, result.Err diff --git a/app/channel_test.go b/app/channel_test.go index 4e6aaaf52..82c9e07ad 100644 --- a/app/channel_test.go +++ b/app/channel_test.go @@ -605,3 +605,17 @@ func TestFillInChannelProps(t *testing.T) { } }) } + +func TestRenameChannel(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN) + + channel, err := th.App.RenameChannel(channel, "newchannelname", "New Display Name") + if err != nil { + t.Fatal("Failed to update channel name. Error: " + err.Error()) + } + assert.Equal(t, "newchannelname", channel.Name) + assert.Equal(t, "New Display Name", channel.DisplayName) +} |