summaryrefslogtreecommitdiffstats
path: root/routers/org
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-01-29 17:06:14 -0500
committerUnknwon <u@gogs.io>2016-01-29 17:06:14 -0500
commit112a7cab31df083983a664e252efcfca4ecb0d7a (patch)
treef5b450fbc40fb6a2073ba134851aef19c0f1e6aa /routers/org
parentee814bf8d6c70c91bac19059ba37af0d91b2a1e0 (diff)
downloadgitea-112a7cab31df083983a664e252efcfca4ecb0d7a.tar.gz
gitea-112a7cab31df083983a664e252efcfca4ecb0d7a.zip
#2497 incorrect error handle for team name
Diffstat (limited to 'routers/org')
-rw-r--r--routers/org/teams.go40
1 files changed, 18 insertions, 22 deletions
diff --git a/routers/org/teams.go b/routers/org/teams.go
index 2dd3c1981c..b2128baab6 100644
--- a/routers/org/teams.go
+++ b/routers/org/teams.go
@@ -157,12 +157,6 @@ func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
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)
- return
- }
// Validate permission level.
var auth models.AccessMode
@@ -178,28 +172,30 @@ func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
return
}
- org := ctx.Org.Organization
-
t := &models.Team{
- OrgID: org.Id,
+ OrgID: ctx.Org.Organization.Id,
Name: form.TeamName,
Description: form.Description,
Authorize: auth,
}
+ ctx.Data["Team"] = t
+
+ if ctx.HasError() {
+ ctx.HTML(200, TEAM_NEW)
+ return
+ }
+
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.Data["Err_TeamName"] = true
+ switch {
+ case models.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), TEAM_NEW, &form)
default:
ctx.Handle(500, "NewTeam", err)
}
return
}
- log.Trace("Team created: %s/%s", org.Name, t.Name)
+ log.Trace("Team created: %s/%s", ctx.Org.Organization.Name, t.Name)
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
}
@@ -235,8 +231,7 @@ func EditTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
t := ctx.Org.Team
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["team_name"] = t.Name
- ctx.Data["desc"] = t.Description
+ ctx.Data["Team"] = t
if ctx.HasError() {
ctx.HTML(200, TEAM_NEW)
@@ -267,10 +262,11 @@ func EditTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
}
t.Description = form.Description
if err := models.UpdateTeam(t, isAuthChanged); err != nil {
- if err == models.ErrTeamNameIllegal {
- ctx.Data["Err_TeamName"] = true
- ctx.RenderWithErr(ctx.Tr("form.illegal_team_name"), TEAM_NEW, &form)
- } else {
+ ctx.Data["Err_TeamName"] = true
+ switch {
+ case models.IsErrTeamAlreadyExist(err):
+ ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), TEAM_NEW, &form)
+ default:
ctx.Handle(500, "UpdateTeam", err)
}
return