func createTeamCmdF(cmd *cobra.Command, args []string) error { initDBCommandContextCobra(cmd) name, errn := cmd.Flags().GetString("name") if errn != nil || name == "" { return errors.New("Name is required") } displayname, errdn := cmd.Flags().GetString("display_name") if errdn != nil || displayname == "" { return errors.New("Display Name is required") } email, _ := cmd.Flags().GetString("email") useprivate, _ := cmd.Flags().GetBool("private") teamType := model.TEAM_OPEN if useprivate { teamType = model.TEAM_INVITE } team := &model.Team{ Name: name, DisplayName: displayname, Email: email, Type: teamType, } if _, err := app.CreateTeam(team); err != nil { return errors.New("Team creation failed: " + err.Error()) } return nil }
func cmdCreateTeam() { if flagCmdCreateTeam { if len(flagTeamName) == 0 { fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name") os.Exit(1) } if len(flagEmail) == 0 { fmt.Fprintln(os.Stderr, "flag needs an argument: -email") os.Exit(1) } c := getMockContext() team := &model.Team{} team.DisplayName = flagTeamName team.Name = flagTeamName team.Email = flagEmail team.Type = model.TEAM_OPEN if _, err := app.CreateTeam(team); err != nil { if err.Id != "store.sql_team.save.domain_exists.app_error" { l4g.Error("%v", c.Err) flushLogAndExit(1) } } os.Exit(0) } }
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { team := model.TeamFromJson(r.Body) if team == nil { c.SetInvalidParam("createTeam", "team") return } var user *model.User if len(c.Session.UserId) > 0 { uchan := app.Srv.Store.User().Get(c.Session.UserId) if result := <-uchan; result.Err != nil { c.Err = result.Err return } else { user = result.Data.(*model.User) team.Email = user.Email } } if !isTeamCreationAllowed(c, team.Email) { return } rteam, err := app.CreateTeam(team) if err != nil { c.Err = err return } if user != nil { err := app.JoinUserToTeam(team, user) if err != nil { c.Err = err return } } w.Write([]byte(rteam.ToJson())) }