Create CLI command "team modify" to modify team's privacy setting. (#10898)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
dd30488a09
Коммит
c49f755a14
18
app/team.go
18
app/team.go
@@ -183,6 +183,24 @@ func (a *App) UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
|
|||||||
return oldTeam, nil
|
return oldTeam, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) UpdateTeamPrivacy(teamId string, teamType string, allowOpenInvite bool) *model.AppError {
|
||||||
|
oldTeam, err := a.GetTeam(teamId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
oldTeam.Type = teamType
|
||||||
|
oldTeam.AllowOpenInvite = allowOpenInvite
|
||||||
|
|
||||||
|
if oldTeam, err = a.Srv.Store.Team().Update(oldTeam); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.sendTeamEvent(oldTeam, model.WEBSOCKET_EVENT_UPDATE_TEAM)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) PatchTeam(teamId string, patch *model.TeamPatch) (*model.Team, *model.AppError) {
|
func (a *App) PatchTeam(teamId string, patch *model.TeamPatch) (*model.Team, *model.AppError) {
|
||||||
team, err := a.GetTeam(teamId)
|
team, err := a.GetTeam(teamId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -100,6 +100,15 @@ var TeamRenameCmd = &cobra.Command{
|
|||||||
RunE: renameTeamCmdF,
|
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() {
|
func init() {
|
||||||
TeamCreateCmd.Flags().String("name", "", "Team Name")
|
TeamCreateCmd.Flags().String("name", "", "Team Name")
|
||||||
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
|
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
|
||||||
@@ -110,6 +119,9 @@ func init() {
|
|||||||
|
|
||||||
TeamRenameCmd.Flags().String("display_name", "", "Team Display Name")
|
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(
|
TeamCmd.AddCommand(
|
||||||
TeamCreateCmd,
|
TeamCreateCmd,
|
||||||
RemoveUsersCmd,
|
RemoveUsersCmd,
|
||||||
@@ -120,6 +132,7 @@ func init() {
|
|||||||
ArchiveTeamCmd,
|
ArchiveTeamCmd,
|
||||||
RestoreTeamsCmd,
|
RestoreTeamsCmd,
|
||||||
TeamRenameCmd,
|
TeamRenameCmd,
|
||||||
|
ModifyTeamCmd,
|
||||||
)
|
)
|
||||||
RootCmd.AddCommand(TeamCmd)
|
RootCmd.AddCommand(TeamCmd)
|
||||||
}
|
}
|
||||||
@@ -410,3 +423,37 @@ func renameTeamCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
return nil
|
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