diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-08-16 16:21:17 +0800 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-08-16 16:21:17 +0800 |
commit | bba707de36d9bfbdb3001e3e89fac0c072aa14e9 (patch) | |
tree | 2b3ee7fc662baea04cecdf14b8a2758c108f83cc /routers/org/teams.go | |
parent | 78add502d71dca43bb59ab9ad91745c64d0bf74d (diff) | |
download | gitea-bba707de36d9bfbdb3001e3e89fac0c072aa14e9.tar.gz gitea-bba707de36d9bfbdb3001e3e89fac0c072aa14e9.zip |
Finish team list, create new team, join/leave team page
Diffstat (limited to 'routers/org/teams.go')
-rw-r--r-- | routers/org/teams.go | 100 |
1 files changed, 46 insertions, 54 deletions
diff --git a/routers/org/teams.go b/routers/org/teams.go index d494ddc04d..bc12a97160 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -13,31 +13,22 @@ import ( ) const ( - TEAMS base.TplName = "org/teams" - TEAM_NEW base.TplName = "org/team_new" + TEAMS base.TplName = "org/team/teams" + TEAM_NEW base.TplName = "org/team/new" ) func Teams(ctx *middleware.Context) { - ctx.Data["Title"] = "Organization " + ctx.Params(":org") + " Teams" + org := ctx.Org.Organization + ctx.Data["Title"] = org.FullName + ctx.Data["PageIsOrgTeams"] = true - org, err := models.GetUserByName(ctx.Params(":org")) - if err != nil { - if err == models.ErrUserNotExist { - ctx.Handle(404, "org.Teams(GetUserByName)", err) - } else { - ctx.Handle(500, "org.Teams(GetUserByName)", err) - } - return - } - ctx.Data["Org"] = org - - if err = org.GetTeams(); err != nil { - ctx.Handle(500, "org.Teams(GetTeams)", err) + if err := org.GetTeams(); err != nil { + ctx.Handle(500, "GetTeams", err) return } for _, t := range org.Teams { - if err = t.GetMembers(); err != nil { - ctx.Handle(500, "org.Home(GetMembers)", err) + if err := t.GetMembers(); err != nil { + ctx.Handle(500, "GetMembers", err) return } } @@ -46,44 +37,39 @@ func Teams(ctx *middleware.Context) { ctx.HTML(200, TEAMS) } -func NewTeam(ctx *middleware.Context) { - org, err := models.GetUserByName(ctx.Params(":org")) - if err != nil { - if err == models.ErrUserNotExist { - ctx.Handle(404, "org.NewTeam(GetUserByName)", err) - } else { - ctx.Handle(500, "org.NewTeam(GetUserByName)", err) - } - return +func TeamsAction(ctx *middleware.Context) { + var err error + switch ctx.Params(":action") { + case "join": + err = models.AddTeamMember(ctx.Org.Organization.Id, ctx.Org.Team.Id, ctx.User.Id) + case "leave": + err = models.RemoveMember(ctx.Org.Organization.Id, ctx.Org.Team.Id, ctx.User.Id) } - ctx.Data["Org"] = org - // Check ownership of organization. - if !org.IsOrgOwner(ctx.User.Id) { - ctx.Error(403) + if err != nil { + log.Error(4, "Action(%s): %v", ctx.Params(":action"), err) + ctx.JSON(200, map[string]interface{}{ + "ok": false, + "err": err.Error(), + }) return } + ctx.Redirect(ctx.Org.OrgLink + "/teams") +} +func NewTeam(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Org.Organization.FullName + ctx.Data["PageIsOrgTeams"] = true + ctx.Data["PageIsOrgTeamsNew"] = true + ctx.Data["Team"] = &models.Team{} ctx.HTML(200, TEAM_NEW) } func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) { - org, err := models.GetUserByName(ctx.Params(":org")) - if err != nil { - if err == models.ErrUserNotExist { - ctx.Handle(404, "org.NewTeamPost(GetUserByName)", err) - } else { - ctx.Handle(500, "org.NewTeamPost(GetUserByName)", err) - } - return - } - ctx.Data["Org"] = org - - // Check ownership of organization. - if !org.IsOrgOwner(ctx.User.Id) { - ctx.Error(403) - return - } + ctx.Data["Title"] = ctx.Org.Organization.FullName + ctx.Data["PageIsOrgTeams"] = true + ctx.Data["PageIsOrgTeamsNew"] = true + ctx.Data["Team"] = &models.Team{} if ctx.HasError() { ctx.HTML(200, TEAM_NEW) @@ -104,23 +90,29 @@ func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) { return } + org := ctx.Org.Organization + t := &models.Team{ OrgId: org.Id, Name: form.TeamName, Description: form.Description, Authorize: auth, } - if err = models.NewTeam(t); err != nil { - if err == models.ErrTeamAlreadyExist { + if err := models.NewTeam(t); err != nil { + switch err { + case models.ErrTeamNameIllegal: + ctx.Data["Err_TeamName"] = true + ctx.RenderWithErr(ctx.Tr("form.illegal_team_name"), TEAM_NEW, &form) + case models.ErrTeamAlreadyExist: ctx.Data["Err_TeamName"] = true - ctx.RenderWithErr("Team name has already been used", TEAM_NEW, &form) - } else { - ctx.Handle(500, "org.NewTeamPost(NewTeam)", err) + ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), TEAM_NEW, &form) + default: + ctx.Handle(500, "NewTeam", err) } return } - log.Trace("%s Team created: %s/%s", ctx.Req.RequestURI, org.Name, t.Name) - ctx.Redirect("/org/" + org.LowerName + "/teams/" + t.LowerName) + log.Trace("Team created: %s/%s", org.Name, t.Name) + ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName) } func EditTeam(ctx *middleware.Context) { |