From f3fc6d11fa11c9b8c73554c79ca55470073bb098 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Wed, 4 Oct 2017 19:08:59 +0100 Subject: PLT-7218: CLI to move slash commands between teams. (#7574) --- app/command.go | 10 ++++++++++ app/command_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 app/command_test.go (limited to 'app') diff --git a/app/command.go b/app/command.go index d3e36b0e0..6e439537e 100644 --- a/app/command.go +++ b/app/command.go @@ -336,6 +336,16 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, } } +func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError { + command.TeamId = team.Id + + if result := <-a.Srv.Store.Command().Update(command); result.Err != nil { + return result.Err + } + + return nil +} + func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppError) { if !*utils.Cfg.ServiceSettings.EnableCommands { return nil, model.NewAppError("RegenCommandToken", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented) diff --git a/app/command_test.go b/app/command_test.go new file mode 100644 index 000000000..be1da3ac7 --- /dev/null +++ b/app/command_test.go @@ -0,0 +1,46 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/mattermost/mattermost-server/model" +) + +func TestMoveCommand(t *testing.T) { + th := Setup().InitBasic() + + sourceTeam := th.CreateTeam() + targetTeam := th.CreateTeam() + + command := &model.Command{} + command.CreatorId = model.NewId() + command.Method = model.COMMAND_METHOD_POST + command.TeamId = sourceTeam.Id + command.URL = "http://nowhere.com/" + command.Trigger = "trigger1" + + command, err := th.App.CreateCommand(command) + assert.Nil(t, err) + + defer func() { + th.App.PermanentDeleteTeam(sourceTeam) + th.App.PermanentDeleteTeam(targetTeam) + }() + + // Move a command and check the team is updated. + assert.Nil(t, th.App.MoveCommand(targetTeam, command)) + retrievedCommand, err := th.App.GetCommand(command.Id) + assert.Nil(t, err) + assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId) + + // Move it to the team it's already in. Nothing should change. + assert.Nil(t, th.App.MoveCommand(targetTeam, command)) + retrievedCommand, err = th.App.GetCommand(command.Id) + assert.Nil(t, err) + assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId) +} -- cgit v1.2.3-1-g7c22