Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
624 lines
21 KiB
Go
624 lines
21 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/hashicorp/go-multierror"
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
|
)
|
|
|
|
func (s *MmctlE2ETestSuite) TestRenameTeamCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
createTeam := func(displayName string) string {
|
|
teamName := model.NewRandomTeamName()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", displayName, "")
|
|
s.Require().Nil(createTeamCmdF(s.th.LocalClient, cmd, []string{}))
|
|
printer.Clean()
|
|
return teamName
|
|
}
|
|
|
|
s.RunForAllClients("Error renaming team which does not exist", func(c client.Client) {
|
|
printer.Clean()
|
|
nonExistentTeamName := "existingName"
|
|
cmd := &cobra.Command{}
|
|
args := []string{nonExistentTeamName}
|
|
cmd.Flags().String("name", "newname", "Team Name")
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(c, cmd, args)
|
|
s.Require().EqualError(err, "Unable to find team 'existingName', to see the all teams try 'team list' command")
|
|
})
|
|
|
|
s.RunForAllClients("Error renaming team without any flag", func(c client.Client) {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
args := []string{s.th.BasicTeam.Name}
|
|
cmd.Flags().String("name", "", "Team Name")
|
|
cmd.Flags().String("display-name", "", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(c, cmd, args)
|
|
s.Require().EqualError(err, "at least one of --name or --display-name is required")
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("Rename the name (slug) of an existing team", func(c client.Client) {
|
|
printer.Clean()
|
|
teamName := createTeam("Original Display Name")
|
|
newName := model.NewRandomTeamName()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", newName, "Team Name")
|
|
cmd.Flags().String("display-name", "", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(c, cmd, []string{teamName})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
s.Equal("'"+teamName+"' team renamed", printer.GetLines()[0])
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
renamedTeam, appErr := s.th.App.GetTeamByName(newName)
|
|
s.Require().Nil(appErr)
|
|
s.Equal(newName, renamedTeam.Name)
|
|
s.Equal("Original Display Name", renamedTeam.DisplayName, "display name should be unchanged")
|
|
|
|
_, appErr = s.th.App.GetTeamByName(teamName)
|
|
s.Require().NotNil(appErr, "old team name should no longer resolve")
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("Change the display name of an existing team", func(c client.Client) {
|
|
printer.Clean()
|
|
teamName := createTeam("Original Display Name")
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", "", "Team Name")
|
|
cmd.Flags().String("display-name", "Updated Display Name", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(c, cmd, []string{teamName})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
s.Equal("'"+teamName+"' team renamed", printer.GetLines()[0])
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
team, appErr := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(appErr)
|
|
s.Equal(teamName, team.Name, "team name (slug) should be unchanged")
|
|
s.Equal("Updated Display Name", team.DisplayName)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("Rename both the name and the display name of an existing team", func(c client.Client) {
|
|
printer.Clean()
|
|
teamName := createTeam("Original Display Name")
|
|
newName := model.NewRandomTeamName()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", newName, "Team Name")
|
|
cmd.Flags().String("display-name", "Updated Display Name", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(c, cmd, []string{teamName})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
s.Equal("'"+teamName+"' team renamed", printer.GetLines()[0])
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
renamedTeam, appErr := s.th.App.GetTeamByName(newName)
|
|
s.Require().Nil(appErr)
|
|
s.Equal(newName, renamedTeam.Name)
|
|
s.Equal("Updated Display Name", renamedTeam.DisplayName)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("Error renaming a team to a name that is already taken", func(c client.Client) {
|
|
printer.Clean()
|
|
existingName := createTeam("Existing Team")
|
|
teamName := createTeam("Team To Rename")
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", existingName, "Team Name")
|
|
cmd.Flags().String("display-name", "", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(c, cmd, []string{teamName})
|
|
s.Require().Error(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.ErrorContains(err, "Cannot rename team '"+teamName+"'")
|
|
|
|
// The team should keep its original name.
|
|
team, appErr := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(appErr)
|
|
s.Equal(teamName, team.Name)
|
|
})
|
|
|
|
s.Run("Permission error renaming an existing team", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
args := []string{s.th.BasicTeam.Name}
|
|
cmd.Flags().String("name", model.NewRandomTeamName(), "Team Name")
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
|
|
err := renameTeamCmdF(s.th.Client, cmd, args)
|
|
s.Require().Error(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.ErrorContains(err, "Cannot rename team '"+s.th.BasicTeam.Name+"', error : You do not have the appropriate permissions.")
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestDeleteTeamsCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.RunForAllClients("Error deleting team which does not exist", func(c client.Client) {
|
|
printer.Clean()
|
|
nonExistentName := "existingName"
|
|
cmd := &cobra.Command{}
|
|
args := []string{nonExistentName}
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
_ = deleteTeamsCmdF(c, cmd, args)
|
|
s.Len(printer.GetErrorLines(), 1)
|
|
s.Require().Equal("Unable to find team '"+nonExistentName+"'", printer.GetErrorLines()[0])
|
|
})
|
|
|
|
s.Run("Permission error while deleting a valid team", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
args := []string{s.th.BasicTeam.Name}
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
_ = deleteTeamsCmdF(s.th.Client, cmd, args)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.Len(printer.GetErrorLines(), 1)
|
|
s.Require().Equal("Unable to delete team '"+s.th.BasicTeam.Name+"' error: You do not have the appropriate permissions.", printer.GetErrorLines()[0])
|
|
team, _ := s.th.App.GetTeam(s.th.BasicTeam.Id)
|
|
s.Equal(team.Name, s.th.BasicTeam.Name)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("Delete a valid team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
teamName := "teamname" + model.NewRandomString(10)
|
|
teamDisplayname := "Mock Display Name"
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", teamDisplayname, "")
|
|
err := createTeamCmdF(s.th.LocalClient, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
|
|
cmd = &cobra.Command{}
|
|
args := []string{teamName}
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
// Set EnableAPITeamDeletion
|
|
enableConfig := true
|
|
config, _, _ := c.GetConfig(context.TODO())
|
|
config.ServiceSettings.EnableAPITeamDeletion = &enableConfig
|
|
_, _, _ = c.UpdateConfig(context.TODO(), config)
|
|
|
|
// Deletion should succeed for both local and SystemAdmin client now
|
|
err = deleteTeamsCmdF(c, cmd, args)
|
|
s.Require().Nil(err)
|
|
team := printer.GetLines()[0].(*model.Team)
|
|
s.Equal(teamName, team.Name)
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
// Reset config
|
|
enableConfig = false
|
|
config, _, _ = c.GetConfig(context.TODO())
|
|
config.ServiceSettings.EnableAPITeamDeletion = &enableConfig
|
|
_, _, _ = c.UpdateConfig(context.TODO(), config)
|
|
|
|
_, err = s.th.App.GetTeam(teamName)
|
|
s.Require().NotNil(err)
|
|
})
|
|
|
|
s.Run("Delete team with disabled config as local client", func() {
|
|
printer.Clean()
|
|
|
|
teamName := "teamname" + model.NewRandomString(10)
|
|
teamDisplayname := "Mock Display Name"
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", teamDisplayname, "")
|
|
err := createTeamCmdF(s.th.LocalClient, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
|
|
cmd = &cobra.Command{}
|
|
args := []string{teamName}
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
c := s.th.LocalClient
|
|
|
|
enableConfig := false
|
|
config, _, _ := c.GetConfig(context.TODO())
|
|
holdConfig := config.ServiceSettings.EnableAPITeamDeletion
|
|
// Set EnableAPITeamDeletion
|
|
config.ServiceSettings.EnableAPITeamDeletion = &enableConfig
|
|
_, _, _ = c.UpdateConfig(context.TODO(), config)
|
|
|
|
// Deletion should succeed for local client now
|
|
err = deleteTeamsCmdF(c, cmd, args)
|
|
s.Require().Nil(err)
|
|
team := printer.GetLines()[0].(*model.Team)
|
|
s.Equal(teamName, team.Name)
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
// Reset config
|
|
config, _, _ = c.GetConfig(context.TODO())
|
|
config.ServiceSettings.EnableAPITeamDeletion = holdConfig
|
|
_, _, _ = c.UpdateConfig(context.TODO(), config)
|
|
|
|
// expect team is deleted
|
|
_, err = s.th.App.GetTeam(teamName)
|
|
s.Require().NotNil(err)
|
|
})
|
|
|
|
s.Run("Permission denied error for system admin when deleting a valid team", func() {
|
|
printer.Clean()
|
|
|
|
args := []string{s.th.BasicTeam.Name}
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("display-name", "newDisplayName", "Team Display Name")
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
// Delete should fail for SystemAdmin client
|
|
err := deleteTeamsCmdF(s.th.SystemAdminClient, cmd, args)
|
|
s.Require().Error(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.Len(printer.GetErrorLines(), 1)
|
|
s.Equal("Unable to delete team '"+s.th.BasicTeam.Name+"' error: Permanent team deletion feature is not enabled. ServiceSettings.EnableAPITeamDeletion must be set to true to use this command. See https://mattermost.com/pl/environment-configuration-settings for more information.", printer.GetErrorLines()[0])
|
|
|
|
// verify team still exists
|
|
team, _ := s.th.App.GetTeam(s.th.BasicTeam.Id)
|
|
s.Equal(team.Name, s.th.BasicTeam.Name)
|
|
|
|
// Delete should succeed for local client
|
|
printer.Clean()
|
|
err = deleteTeamsCmdF(s.th.LocalClient, cmd, args)
|
|
s.Require().Nil(err)
|
|
team = printer.GetLines()[0].(*model.Team)
|
|
s.Equal(team.Name, s.th.BasicTeam.Name)
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestModifyTeamsCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.RunForSystemAdminAndLocal("system & local accounts can set a team to private", func(c client.Client) {
|
|
printer.Clean()
|
|
teamID := s.th.BasicTeam.Id
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("private", true, "")
|
|
err := modifyTeamsCmdF(c, cmd, []string{teamID})
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(model.TeamInvite, printer.GetLines()[0].(*model.Team).Type)
|
|
// teardown
|
|
appErr := s.th.App.UpdateTeamPrivacy(teamID, model.TeamOpen, true)
|
|
s.Require().Nil(appErr)
|
|
t, err := s.th.App.GetTeam(teamID)
|
|
s.Require().Nil(err)
|
|
s.Require().Equal(model.TeamOpen, t.Type)
|
|
})
|
|
|
|
s.Run("user that creates the team can't set team's privacy due to permissions", func() {
|
|
printer.Clean()
|
|
teamID := s.th.BasicTeam.Id
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("private", true, "")
|
|
err := modifyTeamsCmdF(s.th.Client, cmd, []string{teamID})
|
|
|
|
expectedError := fmt.Sprintf("Unable to modify team '%s' error: You do not have the appropriate permissions.", s.th.BasicTeam.Name)
|
|
s.Require().ErrorContains(err, expectedError)
|
|
s.Require().Contains(
|
|
printer.GetErrorLines()[0],
|
|
expectedError,
|
|
)
|
|
t, appErr := s.th.App.GetTeam(teamID)
|
|
s.Require().Nil(appErr)
|
|
s.Require().Equal(model.TeamOpen, t.Type)
|
|
})
|
|
|
|
s.Run("basic user with normal permissions that hasn't created the team can't set team's privacy", func() {
|
|
printer.Clean()
|
|
teamID := s.th.BasicTeam.Id
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("private", true, "")
|
|
s.th.LoginBasic2(s.T())
|
|
err := modifyTeamsCmdF(s.th.Client, cmd, []string{teamID})
|
|
|
|
expectedError := fmt.Sprintf("Unable to modify team '%s' error: You do not have the appropriate permissions.", s.th.BasicTeam.Name)
|
|
s.Require().ErrorContains(err, expectedError)
|
|
s.Require().Contains(
|
|
printer.GetErrorLines()[0],
|
|
expectedError,
|
|
)
|
|
t, appErr := s.th.App.GetTeam(teamID)
|
|
s.Require().Nil(appErr)
|
|
s.Require().Equal(model.TeamOpen, t.Type)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestTeamCreateCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.RunForAllClients("Should not create a team w/o name", func(c client.Client) {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("display-name", "somedisplayname", "")
|
|
|
|
err := createTeamCmdF(c, cmd, []string{})
|
|
s.EqualError(err, "name is required")
|
|
s.Require().Empty(printer.GetLines())
|
|
})
|
|
|
|
s.RunForAllClients("Should not create a team w/o display-name", func(c client.Client) {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().String("name", model.NewRandomTeamName(), "")
|
|
|
|
err := createTeamCmdF(c, cmd, []string{})
|
|
s.EqualError(err, "display-name is required")
|
|
s.Require().Empty(printer.GetLines())
|
|
})
|
|
|
|
s.Run("Should create a new team w/ email using LocalClient", func() {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
teamName := model.NewRandomTeamName()
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", "somedisplayname", "")
|
|
email := "someemail@example.com"
|
|
cmd.Flags().String("email", email, "")
|
|
|
|
err := createTeamCmdF(s.th.LocalClient, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
newTeam, err := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(err)
|
|
s.Equal(email, newTeam.Email)
|
|
})
|
|
|
|
s.Run("Should create a new team w/ assigned email using SystemAdminClient", func() {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
teamName := model.NewRandomTeamName()
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", "somedisplayname", "")
|
|
email := "someemail@example.com"
|
|
cmd.Flags().String("email", email, "")
|
|
|
|
err := createTeamCmdF(s.th.SystemAdminClient, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
newTeam, err := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(err)
|
|
s.NotEqual(email, newTeam.Email)
|
|
})
|
|
|
|
s.Run("Should create a new team w/ assigned email using Client", func() {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
teamName := model.NewRandomTeamName()
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", "somedisplayname", "")
|
|
email := "someemail@example.com"
|
|
cmd.Flags().String("email", email, "")
|
|
|
|
err := createTeamCmdF(s.th.Client, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
newTeam, err := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(err)
|
|
s.NotEqual(email, newTeam.Email)
|
|
})
|
|
|
|
s.RunForAllClients("Should create a new open team", func(c client.Client) {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
teamName := model.NewRandomTeamName()
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", "somedisplayname", "")
|
|
|
|
err := createTeamCmdF(c, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
newTeam, err := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(err)
|
|
s.Equal(newTeam.Type, model.TeamOpen)
|
|
s.Equal(newTeam.AllowOpenInvite, true)
|
|
})
|
|
|
|
s.RunForAllClients("Should create a new private team", func(c client.Client) {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
teamName := model.NewRandomTeamName()
|
|
cmd.Flags().String("name", teamName, "")
|
|
cmd.Flags().String("display-name", "somedisplayname", "")
|
|
cmd.Flags().Bool("private", true, "")
|
|
|
|
err := createTeamCmdF(c, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
newTeam, err := s.th.App.GetTeamByName(teamName)
|
|
s.Require().Nil(err)
|
|
s.Equal(newTeam.Type, model.TeamInvite)
|
|
s.Equal(newTeam.AllowOpenInvite, false)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestSearchTeamCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.RunForSystemAdminAndLocal("Search for existing team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := searchTeamCmdF(c, &cobra.Command{}, []string{s.th.BasicTeam.Name})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
team := printer.GetLines()[0].(*model.Team)
|
|
s.Equal(s.th.BasicTeam.Name, team.Name)
|
|
})
|
|
|
|
s.Run("Search for existing team with Client", func() {
|
|
printer.Clean()
|
|
|
|
err := searchTeamCmdF(s.th.Client, &cobra.Command{}, []string{s.th.BasicTeam.Name})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.Len(printer.GetErrorLines(), 1)
|
|
s.Equal("Unable to find team '"+s.th.BasicTeam.Name+"'", printer.GetErrorLines()[0])
|
|
})
|
|
|
|
s.RunForAllClients("Search of nonexistent team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
teamnameArg := "nonexistentteam"
|
|
err := searchTeamCmdF(c, &cobra.Command{}, []string{teamnameArg})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.Len(printer.GetErrorLines(), 1)
|
|
s.Equal("Unable to find team '"+teamnameArg+"'", printer.GetErrorLines()[0])
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestArchiveTeamsCmd() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("confirm", true, "Confirm you really want to archive the team and a DB backup has been performed.")
|
|
|
|
s.RunForAllClients("Archive nonexistent team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := archiveTeamsCmdF(c, cmd, []string{"unknown-team"})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
s.Require().Equal("Unable to find team 'unknown-team'", printer.GetErrorLines()[0])
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("Archive basic team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := archiveTeamsCmdF(c, cmd, []string{s.th.BasicTeam.Name})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
team := printer.GetLines()[0].(*model.Team)
|
|
s.Require().Equal(s.th.BasicTeam.Name, team.Name)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
|
|
basicTeam, err := s.th.App.GetTeam(s.th.BasicTeam.Id)
|
|
s.Require().Nil(err)
|
|
s.Require().NotZero(basicTeam.DeleteAt)
|
|
|
|
err = s.th.App.RestoreTeam(s.th.BasicTeam.Id)
|
|
s.Require().Nil(err)
|
|
})
|
|
|
|
s.Run("Archive team without permissions", func() {
|
|
printer.Clean()
|
|
|
|
err := archiveTeamsCmdF(s.th.Client, cmd, []string{s.th.BasicTeam.Name})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions.")
|
|
|
|
basicTeam, err := s.th.App.GetTeam(s.th.BasicTeam.Id)
|
|
s.Require().Nil(err)
|
|
s.Require().Zero(basicTeam.DeleteAt)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestListTeamsCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
mockTeamName := "mockteam" + model.NewId()
|
|
mockTeamDisplayname := "mockteam_display"
|
|
_, err := s.th.App.CreateTeam(s.th.Context, &model.Team{Name: mockTeamName, DisplayName: mockTeamDisplayname, Type: model.TeamOpen, DeleteAt: 1})
|
|
s.Require().Nil(err)
|
|
|
|
s.RunForSystemAdminAndLocal("Should print both active and archived teams for syasdmin and local clients", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := listTeamsCmdF(c, &cobra.Command{}, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 2)
|
|
team := printer.GetLines()[0].(*model.Team)
|
|
s.Equal(s.th.BasicTeam.Name, team.Name)
|
|
|
|
archivedTeam := printer.GetLines()[1].(*model.Team)
|
|
s.Equal(mockTeamName, archivedTeam.Name)
|
|
})
|
|
|
|
s.Run("Should not list teams for Client", func() {
|
|
printer.Clean()
|
|
|
|
err := listTeamsCmdF(s.th.Client, &cobra.Command{}, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestRestoreTeamsCmd() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.RunForAllClients("Restore team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
team := s.th.CreateTeam(s.T())
|
|
appErr := s.th.App.SoftDeleteTeam(team.Id)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := restoreTeamsCmdF(c, &cobra.Command{}, []string{team.Name})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Zero(printer.GetLines()[0].(*model.Team).DeleteAt)
|
|
})
|
|
|
|
s.RunForAllClients("Restore non-existent team", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
teamName := "non-existent-team"
|
|
|
|
err := restoreTeamsCmdF(c, &cobra.Command{}, []string{teamName})
|
|
var expected error
|
|
errMessage := "unable to find team '" + teamName + "'"
|
|
expected = multierror.Append(expected, errors.New(errMessage))
|
|
|
|
s.Require().EqualError(err, expected.Error())
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
})
|
|
|
|
s.Run("Restore team without permissions", func() {
|
|
printer.Clean()
|
|
|
|
team := s.th.CreateTeamWithClient(s.T(), s.th.SystemAdminClient)
|
|
appErr := s.th.App.SoftDeleteTeam(team.Id)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := restoreTeamsCmdF(s.th.Client, &cobra.Command{}, []string{team.Name})
|
|
var expected error
|
|
errMessage := "unable to find team '" + team.Name + "'"
|
|
expected = multierror.Append(expected, errors.New(errMessage))
|
|
|
|
s.Require().EqualError(err, expected.Error())
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
})
|
|
}
|