summaryrefslogtreecommitdiffstats
path: root/routers/org
diff options
context:
space:
mode:
authorMorgan Bazalgette <git@howl.moe>2018-01-10 22:34:17 +0100
committerLauris BH <lauris@nix.lv>2018-01-10 23:34:17 +0200
commit65861900cda3bb6d9e2aa80b808b0000383c04b3 (patch)
tree8569d93b6ef092b30b35a4d4da906c6b6950e2ee /routers/org
parent45c264f681e3f7e1a22a191029836a690959aac3 (diff)
downloadgitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.tar.gz
gitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.zip
Handle refactor (#3339)
* Replace all ctx.Handle with ctx.ServerError or ctx.NotFound * Change Handle(403) to NotFound, avoid using macaron's NotFound
Diffstat (limited to 'routers/org')
-rw-r--r--routers/org/members.go2
-rw-r--r--routers/org/org.go12
-rw-r--r--routers/org/setting.go12
-rw-r--r--routers/org/teams.go16
4 files changed, 25 insertions, 17 deletions
diff --git a/routers/org/members.go b/routers/org/members.go
index aa3646d1e0..8a243c87be 100644
--- a/routers/org/members.go
+++ b/routers/org/members.go
@@ -26,7 +26,7 @@ func Members(ctx *context.Context) {
ctx.Data["PageIsOrgMembers"] = true
if err := org.GetMembers(); err != nil {
- ctx.Handle(500, "GetMembers", err)
+ ctx.ServerError("GetMembers", err)
return
}
ctx.Data["Members"] = org.Members
diff --git a/routers/org/org.go b/routers/org/org.go
index d0988bfcf5..665d1a71fc 100644
--- a/routers/org/org.go
+++ b/routers/org/org.go
@@ -22,9 +22,13 @@ const (
// Create render the page for create organization
func Create(ctx *context.Context) {
+ if !ctx.User.CanCreateOrganization() {
+ ctx.NotFound("CanCreateOrganization", nil)
+ }
+
ctx.Data["Title"] = ctx.Tr("new_org")
if !ctx.User.CanCreateOrganization() {
- ctx.Handle(500, "Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
+ ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
return
}
ctx.HTML(200, tplCreateOrg)
@@ -32,6 +36,10 @@ func Create(ctx *context.Context) {
// CreatePost response for create organization
func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
+ if !ctx.User.CanCreateOrganization() {
+ ctx.NotFound("CanCreateOrganization", nil)
+ }
+
ctx.Data["Title"] = ctx.Tr("new_org")
if ctx.HasError() {
@@ -57,7 +65,7 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
case models.IsErrUserNotAllowedCreateOrg(err):
ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
default:
- ctx.Handle(500, "CreateOrganization", err)
+ ctx.ServerError("CreateOrganization", err)
}
return
}
diff --git a/routers/org/setting.go b/routers/org/setting.go
index 4faed77d0d..937697d07e 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -48,7 +48,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
if org.LowerName != strings.ToLower(form.Name) {
isExist, err := models.IsUserExist(org.ID, form.Name)
if err != nil {
- ctx.Handle(500, "IsUserExist", err)
+ ctx.ServerError("IsUserExist", err)
return
} else if isExist {
ctx.Data["OrgName"] = true
@@ -59,7 +59,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
ctx.Data["OrgName"] = true
ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form)
} else {
- ctx.Handle(500, "ChangeUserName", err)
+ ctx.ServerError("ChangeUserName", err)
}
return
}
@@ -80,7 +80,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
org.Website = form.Website
org.Location = form.Location
if err := models.UpdateUser(org); err != nil {
- ctx.Handle(500, "UpdateUser", err)
+ ctx.ServerError("UpdateUser", err)
return
}
log.Trace("Organization setting updated: %s", org.Name)
@@ -120,7 +120,7 @@ func SettingsDelete(ctx *context.Context) {
if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil)
} else {
- ctx.Handle(500, "UserSignIn", err)
+ ctx.ServerError("UserSignIn", err)
}
return
}
@@ -130,7 +130,7 @@ func SettingsDelete(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("form.org_still_own_repo"))
ctx.Redirect(ctx.Org.OrgLink + "/settings/delete")
} else {
- ctx.Handle(500, "DeleteOrganization", err)
+ ctx.ServerError("DeleteOrganization", err)
}
} else {
log.Trace("Organization deleted: %s", org.Name)
@@ -151,7 +151,7 @@ func Webhooks(ctx *context.Context) {
ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID)
if err != nil {
- ctx.Handle(500, "GetWebhooksByOrgId", err)
+ ctx.ServerError("GetWebhooksByOrgId", err)
return
}
diff --git a/routers/org/teams.go b/routers/org/teams.go
index 7f8b828e82..d894c86614 100644
--- a/routers/org/teams.go
+++ b/routers/org/teams.go
@@ -37,7 +37,7 @@ func Teams(ctx *context.Context) {
for _, t := range org.Teams {
if err := t.GetMembers(); err != nil {
- ctx.Handle(500, "GetMembers", err)
+ ctx.ServerError("GetMembers", err)
return
}
}
@@ -85,7 +85,7 @@ func TeamsAction(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName)
} else {
- ctx.Handle(500, " GetUserByName", err)
+ ctx.ServerError(" GetUserByName", err)
}
return
}
@@ -142,7 +142,7 @@ func TeamsRepoAction(ctx *context.Context) {
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
return
}
- ctx.Handle(500, "GetRepositoryByName", err)
+ ctx.ServerError("GetRepositoryByName", err)
return
}
err = ctx.Org.Team.AddRepository(repo)
@@ -152,7 +152,7 @@ func TeamsRepoAction(ctx *context.Context) {
if err != nil {
log.Error(3, "Action(%s): '%s' %v", ctx.Params(":action"), ctx.Org.Team.Name, err)
- ctx.Handle(500, "TeamsRepoAction", err)
+ ctx.ServerError("TeamsRepoAction", err)
return
}
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
@@ -203,7 +203,7 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
case models.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
default:
- ctx.Handle(500, "NewTeam", err)
+ ctx.ServerError("NewTeam", err)
}
return
}
@@ -216,7 +216,7 @@ func TeamMembers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetMembers(); err != nil {
- ctx.Handle(500, "GetMembers", err)
+ ctx.ServerError("GetMembers", err)
return
}
ctx.HTML(200, tplTeamMembers)
@@ -227,7 +227,7 @@ func TeamRepositories(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetRepositories(); err != nil {
- ctx.Handle(500, "GetRepositories", err)
+ ctx.ServerError("GetRepositories", err)
return
}
ctx.HTML(200, tplTeamRepositories)
@@ -285,7 +285,7 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
case models.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
default:
- ctx.Handle(500, "UpdateTeam", err)
+ ctx.ServerError("UpdateTeam", err)
}
return
}