summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWasim Thabraze <wasim@thabraze.me>2018-10-16 00:18:18 +0530
committerGeorge Goldberg <george@gberg.me>2018-10-15 19:48:18 +0100
commit457a34c5f4cba44299eb289694cb0174e4eba7be (patch)
tree7be9287aa3ca8317f02678953a6116e48b0931ec
parent0be0700aad6bd607270a97f037540da55a4ecf9f (diff)
downloadchat-457a34c5f4cba44299eb289694cb0174e4eba7be.tar.gz
chat-457a34c5f4cba44299eb289694cb0174e4eba7be.tar.bz2
chat-457a34c5f4cba44299eb289694cb0174e4eba7be.zip
[MM-12363] Added Team archive command to archive a team by name (#9565)
* Added Team archive command to archive a team by name * Team archive command now uses SoftDelete method Team search and list command now shows archived teams with the term '(archived)' appended to them
-rw-r--r--cmd/mattermost/commands/team.go43
-rw-r--r--cmd/mattermost/commands/team_test.go57
2 files changed, 98 insertions, 2 deletions
diff --git a/cmd/mattermost/commands/team.go b/cmd/mattermost/commands/team.go
index 587062534..151795f58 100644
--- a/cmd/mattermost/commands/team.go
+++ b/cmd/mattermost/commands/team.go
@@ -69,6 +69,15 @@ var SearchTeamCmd = &cobra.Command{
RunE: searchTeamCmdF,
}
+var ArchiveTeamCmd = &cobra.Command{
+ Use: "archive [teams]",
+ Short: "Archive teams",
+ Long: "Archive teams based on name",
+ Example: " team archive team1",
+ Args: cobra.MinimumNArgs(1),
+ RunE: archiveTeamCmdF,
+}
+
func init() {
TeamCreateCmd.Flags().String("name", "", "Team Name")
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
@@ -84,6 +93,7 @@ func init() {
DeleteTeamsCmd,
ListTeamsCmd,
SearchTeamCmd,
+ ArchiveTeamCmd,
)
RootCmd.AddCommand(TeamCmd)
}
@@ -253,7 +263,11 @@ func listTeamsCmdF(command *cobra.Command, args []string) error {
}
for _, team := range teams {
- CommandPrettyPrintln(team.Name)
+ if team.DeleteAt > 0 {
+ CommandPrettyPrintln(team.Name + " (archived)")
+ } else {
+ CommandPrettyPrintln(team.Name)
+ }
}
return nil
@@ -279,7 +293,11 @@ func searchTeamCmdF(command *cobra.Command, args []string) error {
sortedTeams := removeDuplicatesAndSortTeams(teams)
for _, team := range sortedTeams {
- CommandPrettyPrintln(team.Name + ": " + team.DisplayName + " (" + team.Id + ")")
+ if team.DeleteAt > 0 {
+ CommandPrettyPrintln(team.Name + ": " + team.DisplayName + " (" + team.Id + ")" + " (archived)")
+ } else {
+ CommandPrettyPrintln(team.Name + ": " + team.DisplayName + " (" + team.Id + ")")
+ }
}
return nil
@@ -300,3 +318,24 @@ func removeDuplicatesAndSortTeams(teams []*model.Team) []*model.Team {
})
return result
}
+
+func archiveTeamCmdF(command *cobra.Command, args []string) error {
+ a, err := InitDBCommandContextCobra(command)
+ if err != nil {
+ return err
+ }
+ defer a.Shutdown()
+
+ foundTeams := getTeamsFromTeamArgs(a, args)
+ for i, team := range foundTeams {
+ if team == nil {
+ CommandPrintErrorln("Unable to find team '" + args[i] + "'")
+ continue
+ }
+ if err := a.SoftDeleteTeam(team.Id); err != nil {
+ CommandPrintErrorln("Unable to archive team '"+team.Name+"' error: ", err)
+ }
+ }
+
+ return nil
+}
diff --git a/cmd/mattermost/commands/team_test.go b/cmd/mattermost/commands/team_test.go
index 559198256..16ebb5a09 100644
--- a/cmd/mattermost/commands/team_test.go
+++ b/cmd/mattermost/commands/team_test.go
@@ -96,6 +96,25 @@ func TestListTeams(t *testing.T) {
}
}
+func TestListArchivedTeams(t *testing.T) {
+ th := api4.Setup().InitBasic()
+ defer th.TearDown()
+
+ id := model.NewId()
+ name := "name" + id
+ displayName := "Name " + id
+
+ CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
+
+ CheckCommand(t, "team", "archive", name)
+
+ output := CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
+
+ if !strings.Contains(string(output), name+" (archived)") {
+ t.Fatal("should have archived team")
+ }
+}
+
func TestSearchTeamsByName(t *testing.T) {
th := api4.Setup().InitBasic()
defer th.TearDown()
@@ -129,3 +148,41 @@ func TestSearchTeamsByDisplayName(t *testing.T) {
t.Fatal("should have the created team")
}
}
+
+func TestSearchArchivedTeamsByName(t *testing.T) {
+ th := api4.Setup().InitBasic()
+ defer th.TearDown()
+
+ id := model.NewId()
+ name := "name" + id
+ displayName := "Name " + id
+
+ CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
+
+ CheckCommand(t, "team", "archive", name)
+
+ output := CheckCommand(t, "team", "search", name)
+
+ if !strings.Contains(string(output), "(archived)") {
+ t.Fatal("should have archived team")
+ }
+}
+
+func TestArchiveTeams(t *testing.T) {
+ th := api4.Setup().InitBasic()
+ defer th.TearDown()
+
+ id := model.NewId()
+ name := "name" + id
+ displayName := "Name " + id
+
+ CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
+
+ CheckCommand(t, "team", "archive", name)
+
+ output := CheckCommand(t, "team", "list")
+
+ if !strings.Contains(string(output), name+" (archived)") {
+ t.Fatal("should have archived team")
+ }
+}