Create CLI command "team modify" to modify team's privacy setting. (#10898)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
dd30488a09
Коммит
c49f755a14
@@ -100,6 +100,15 @@ var TeamRenameCmd = &cobra.Command{
|
||||
RunE: renameTeamCmdF,
|
||||
}
|
||||
|
||||
var ModifyTeamCmd = &cobra.Command{
|
||||
Use: "modify [team] [flag]",
|
||||
Short: "Modify a team's privacy setting to public or private",
|
||||
Long: `Modify a team's privacy setting to public or private.`,
|
||||
Example: " team modify myteam --private",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: modifyTeamCmdF,
|
||||
}
|
||||
|
||||
func init() {
|
||||
TeamCreateCmd.Flags().String("name", "", "Team Name")
|
||||
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
|
||||
@@ -110,6 +119,9 @@ func init() {
|
||||
|
||||
TeamRenameCmd.Flags().String("display_name", "", "Team Display Name")
|
||||
|
||||
ModifyTeamCmd.Flags().Bool("private", false, "Convert the team to a private team")
|
||||
ModifyTeamCmd.Flags().Bool("public", false, "Convert the team to a public team")
|
||||
|
||||
TeamCmd.AddCommand(
|
||||
TeamCreateCmd,
|
||||
RemoveUsersCmd,
|
||||
@@ -120,6 +132,7 @@ func init() {
|
||||
ArchiveTeamCmd,
|
||||
RestoreTeamsCmd,
|
||||
TeamRenameCmd,
|
||||
ModifyTeamCmd,
|
||||
)
|
||||
RootCmd.AddCommand(TeamCmd)
|
||||
}
|
||||
@@ -410,3 +423,37 @@ func renameTeamCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func modifyTeamCmdF(command *cobra.Command, args []string) error {
|
||||
a, err := InitDBCommandContextCobra(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer a.Shutdown()
|
||||
|
||||
team := getTeamFromTeamArg(a, args[0])
|
||||
if team == nil {
|
||||
return errors.New("Unable to find team '" + args[0] + "'")
|
||||
}
|
||||
|
||||
public, _ := command.Flags().GetBool("public")
|
||||
private, _ := command.Flags().GetBool("private")
|
||||
|
||||
if public == private {
|
||||
return errors.New("You must specify only one of --public or --private")
|
||||
}
|
||||
|
||||
if public {
|
||||
team.Type = model.TEAM_OPEN
|
||||
team.AllowOpenInvite = true
|
||||
} else if private {
|
||||
team.Type = model.TEAM_INVITE
|
||||
team.AllowOpenInvite = false
|
||||
}
|
||||
|
||||
if err := a.UpdateTeamPrivacy(team.Id, team.Type, team.AllowOpenInvite); err != nil {
|
||||
return errors.New("Failed to update privacy for team" + args[0])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -271,3 +271,25 @@ func TestRenameTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestModifyTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
team := th.CreateTeam()
|
||||
|
||||
th.CheckCommand(t, "team", "modify", team.Name, "--private")
|
||||
|
||||
updatedTeam, _ := th.App.GetTeam(team.Id)
|
||||
|
||||
if !updatedTeam.AllowOpenInvite && team.Type == model.TEAM_INVITE {
|
||||
t.Fatal("Failed modifying team's privacy to private")
|
||||
}
|
||||
|
||||
th.CheckCommand(t, "team", "modify", team.Name, "--public")
|
||||
|
||||
if updatedTeam.AllowOpenInvite && team.Type == model.TEAM_OPEN {
|
||||
t.Fatal("Failed modifying team's privacy to private")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user