From 58d0d9afd286afd715e9f04825e1305045d404e2 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Fri, 4 Sep 2015 11:59:10 -0700 Subject: Adding cmd line options --- api/team.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'api/team.go') diff --git a/api/team.go b/api/team.go index 8cce384c3..8c0be9486 100644 --- a/api/team.go +++ b/api/team.go @@ -239,47 +239,55 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) { } func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { + team := model.TeamFromJson(r.Body) + rteam := CreateTeam(c, team) + if c.Err != nil { + return + } + + w.Write([]byte(rteam.ToJson())) +} + +func CreateTeam(c *Context, team *model.Team) *model.Team { if utils.Cfg.ServiceSettings.DisableEmailSignUp { c.Err = model.NewAppError("createTeam", "Team sign-up with email is disabled.", "") c.Err.StatusCode = http.StatusNotImplemented - return + return nil } - team := model.TeamFromJson(r.Body) - if team == nil { c.SetInvalidParam("createTeam", "team") - return + return nil } if !isTreamCreationAllowed(c, team.Email) { - return + return nil } if utils.Cfg.ServiceSettings.Mode != utils.MODE_DEV { - c.Err = model.NewAppError("createTeam", "The mode does not allow network creation without a valid invite", "") - return + c.Err = model.NewAppError("CreateTeam", "The mode does not allow network creation without a valid invite", "") + return nil } if result := <-Srv.Store.Team().Save(team); result.Err != nil { c.Err = result.Err - return + return nil } else { rteam := result.Data.(*model.Team) if _, err := CreateDefaultChannels(c, rteam.Id); err != nil { c.Err = err - return + return nil } if rteam.AllowValet { CreateValet(c, rteam) if c.Err != nil { - return + return nil } } - w.Write([]byte(rteam.ToJson())) + return rteam } } @@ -467,7 +475,7 @@ func InviteMembers(c *Context, team *model.Team, user *model.User, invites []str sender := user.GetDisplayName() senderRole := "" - if strings.Contains(user.Roles, model.ROLE_ADMIN) || strings.Contains(user.Roles, model.ROLE_SYSTEM_ADMIN) { + if model.IsInRole(user.Roles, model.ROLE_ADMIN) || model.IsInRole(user.Roles, model.ROLE_SYSTEM_ADMIN) { senderRole = "administrator" } else { senderRole = "member" @@ -526,7 +534,7 @@ func updateTeamDisplayName(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !strings.Contains(c.Session.Roles, model.ROLE_ADMIN) { + if !model.IsInRole(c.Session.Roles, model.ROLE_ADMIN) { c.Err = model.NewAppError("updateTeamDisplayName", "You do not have the appropriate permissions", "userId="+c.Session.UserId) c.Err.StatusCode = http.StatusForbidden return @@ -566,7 +574,7 @@ func updateValetFeature(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !strings.Contains(c.Session.Roles, model.ROLE_ADMIN) { + if !model.IsInRole(c.Session.Roles, model.ROLE_ADMIN) { c.Err = model.NewAppError("updateValetFeature", "You do not have the appropriate permissions", "userId="+c.Session.UserId) c.Err.StatusCode = http.StatusForbidden return -- cgit v1.2.3-1-g7c22