Adds cli for team restore and team archive.
Этот коммит содержится в:
Ashutosh Kumar
2019-01-28 17:34:19 +05:30
коммит произвёл Hanzei
родитель 144686148b
Коммит 9b952dce27
4 изменённых файлов: 67 добавлений и 0 удалений

Просмотреть файл

@@ -81,6 +81,15 @@ var ArchiveTeamCmd = &cobra.Command{
RunE: archiveTeamCmdF,
}
var RestoreTeamsCmd = &cobra.Command{
Use: "restore [teams]",
Short: "Restore some teams",
Long: `Restore a previously deleted team`,
Example: " team restore myteam",
Args: cobra.MinimumNArgs(1),
RunE: restoreTeamsCmdF,
}
func init() {
TeamCreateCmd.Flags().String("name", "", "Team Name")
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
@@ -97,6 +106,7 @@ func init() {
ListTeamsCmd,
SearchTeamCmd,
ArchiveTeamCmd,
RestoreTeamsCmd,
)
RootCmd.AddCommand(TeamCmd)
}
@@ -294,6 +304,28 @@ func searchTeamCmdF(command *cobra.Command, args []string) error {
return nil
}
// Restores archived teams by name
func restoreTeamsCmdF(command *cobra.Command, args []string) error {
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
defer a.Shutdown()
teams := getTeamsFromTeamArgs(a, args)
for i, team := range teams {
if team == nil {
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
continue
}
err := a.RestoreTeam(team.Id)
if err != nil {
CommandPrintErrorln("Unable to restore team '" + team.Name + "' error: " + err.Error())
}
}
return nil
}
// Removes duplicates and sorts teams by name
func removeDuplicatesAndSortTeams(teams []*model.Team) []*model.Team {
keys := make(map[string]bool)

Просмотреть файл

@@ -8,6 +8,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/require"
)
func TestCreateTeam(t *testing.T) {
@@ -185,3 +186,22 @@ func TestArchiveTeams(t *testing.T) {
t.Fatal("should have archived team")
}
}
func TestRestoreTeams(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
id := model.NewId()
name := "name" + id
displayName := "Name " + id
th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
th.CheckCommand(t, "team", "archive", name)
th.CheckCommand(t, "team", "restore", name)
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
require.True(t, found)
}