diff options
Diffstat (limited to 'api/team.go')
-rw-r--r-- | api/team.go | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/api/team.go b/api/team.go index d39d8ed60..7d746d922 100644 --- a/api/team.go +++ b/api/team.go @@ -30,7 +30,7 @@ func InitTeam(r *mux.Router) { sr.Handle("/find_teams", ApiAppHandler(findTeams)).Methods("POST") sr.Handle("/email_teams", ApiAppHandler(emailTeams)).Methods("POST") sr.Handle("/invite_members", ApiUserRequired(inviteMembers)).Methods("POST") - sr.Handle("/update_name", ApiUserRequired(updateTeamDisplayName)).Methods("POST") + sr.Handle("/update", ApiUserRequired(updateTeam)).Methods("POST") sr.Handle("/me", ApiUserRequired(getMyTeam)).Methods("GET") // These should be moved to the global admain console sr.Handle("/import_team", ApiUserRequired(importTeam)).Methods("POST") @@ -541,40 +541,47 @@ func InviteMembers(c *Context, team *model.Team, user *model.User, invites []str } } -func updateTeamDisplayName(c *Context, w http.ResponseWriter, r *http.Request) { +func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) { - props := model.MapFromJson(r.Body) + team := model.TeamFromJson(r.Body) - new_name := props["new_name"] - if len(new_name) == 0 { - c.SetInvalidParam("updateTeamDisplayName", "new_name") + if team == nil { + c.SetInvalidParam("updateTeam", "team") return } - teamId := props["team_id"] - if len(teamId) > 0 && len(teamId) != 26 { - c.SetInvalidParam("updateTeamDisplayName", "team_id") - return - } else if len(teamId) == 0 { - teamId = c.Session.TeamId - } + team.Id = c.Session.TeamId - if !c.HasPermissionsToTeam(teamId, "updateTeamDisplayName") { + if !c.IsTeamAdmin() { + c.Err = model.NewAppError("updateTeam", "You do not have the appropriate permissions", "userId="+c.Session.UserId) + c.Err.StatusCode = http.StatusForbidden return } - if !c.IsTeamAdmin() { - c.Err = model.NewAppError("updateTeamDisplayName", "You do not have the appropriate permissions", "userId="+c.Session.UserId) - c.Err.StatusCode = http.StatusForbidden + var oldTeam *model.Team + if result := <-Srv.Store.Team().Get(team.Id); result.Err != nil { + c.Err = result.Err return + } else { + oldTeam = result.Data.(*model.Team) } - if result := <-Srv.Store.Team().UpdateDisplayName(new_name, c.Session.TeamId); result.Err != nil { + oldTeam.DisplayName = team.DisplayName + oldTeam.InviteId = team.InviteId + oldTeam.AllowOpenInvite = team.AllowOpenInvite + oldTeam.AllowTeamListing = team.AllowTeamListing + oldTeam.CompanyName = team.CompanyName + oldTeam.AllowedDomains = team.AllowedDomains + //oldTeam.Type = team.Type + + if result := <-Srv.Store.Team().Update(oldTeam); result.Err != nil { c.Err = result.Err return } - w.Write([]byte(model.MapToJson(props))) + oldTeam.Sanitize() + + w.Write([]byte(oldTeam.ToJson())) } func getMyTeam(c *Context, w http.ResponseWriter, r *http.Request) { |