summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-06-12 07:43:27 +0200
committerGitHub <noreply@github.com>2022-06-12 13:43:27 +0800
commitedf14202fea349500d69ed2a360a53cc0d1f80e3 (patch)
tree2702b4bd827d1c7c5a8384115ec28e73128fa88a /routers
parent3898fc5bdafa33432d8ee9841e09b5c8b372df12 (diff)
downloadgitea-edf14202fea349500d69ed2a360a53cc0d1f80e3.tar.gz
gitea-edf14202fea349500d69ed2a360a53cc0d1f80e3.zip
Unify repo settings & show better error (#19828)
* Unify context data * Actually show invalid url in error
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/migrate.go6
-rw-r--r--routers/web/repo/setting.go12
-rw-r--r--routers/web/web.go6
3 files changed, 14 insertions, 10 deletions
diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go
index 38cdbd4973..393f8ed3d9 100644
--- a/routers/web/repo/migrate.go
+++ b/routers/web/repo/migrate.go
@@ -128,7 +128,7 @@ func handleMigrateRemoteAddrError(ctx *context.Context, err error, tpl base.TplN
case addrErr.IsProtocolInvalid:
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tpl, form)
case addrErr.IsURLError:
- ctx.RenderWithErr(ctx.Tr("form.url_error"), tpl, form)
+ ctx.RenderWithErr(ctx.Tr("form.url_error", addrErr.Host), tpl, form)
case addrErr.IsPermissionDenied:
if addrErr.LocalPath {
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tpl, form)
@@ -139,11 +139,11 @@ func handleMigrateRemoteAddrError(ctx *context.Context, err error, tpl base.TplN
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tpl, form)
default:
log.Error("Error whilst updating url: %v", err)
- ctx.RenderWithErr(ctx.Tr("form.url_error"), tpl, form)
+ ctx.RenderWithErr(ctx.Tr("form.url_error", "unknown"), tpl, form)
}
} else {
log.Error("Error whilst updating url: %v", err)
- ctx.RenderWithErr(ctx.Tr("form.url_error"), tpl, form)
+ ctx.RenderWithErr(ctx.Tr("form.url_error", "unknown"), tpl, form)
}
}
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index 6083d17fa5..fae62c1020 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -57,8 +57,9 @@ const (
tplProtectedBranch base.TplName = "repo/settings/protected_branch"
)
-// Settings show a repository's settings page
-func Settings(ctx *context.Context) {
+// SettingsCtxData is a middleware that sets all the general context data for the
+// settings template.
+func SettingsCtxData(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
@@ -94,15 +95,16 @@ func Settings(ctx *context.Context) {
return
}
ctx.Data["PushMirrors"] = pushMirrors
+}
+// Settings show a repository's settings page
+func Settings(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplSettingsOptions)
}
// SettingsPost response for changes of a repository
func SettingsPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
- ctx.Data["Title"] = ctx.Tr("repo.settings")
- ctx.Data["PageIsSettingsOptions"] = true
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
@@ -827,7 +829,7 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
case addrErr.IsProtocolInvalid:
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tplSettingsOptions, form)
case addrErr.IsURLError:
- ctx.RenderWithErr(ctx.Tr("form.url_error"), tplSettingsOptions, form)
+ ctx.RenderWithErr(ctx.Tr("form.url_error", addrErr.Host), tplSettingsOptions, form)
case addrErr.IsPermissionDenied:
if addrErr.LocalPath {
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplSettingsOptions, form)
diff --git a/routers/web/web.go b/routers/web/web.go
index dc596c6970..ad005f74df 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -730,8 +730,10 @@ func RegisterRoutes(m *web.Route) {
m.Group("/{username}/{reponame}", func() {
m.Group("/settings", func() {
- m.Combo("").Get(repo.Settings).
- Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
+ m.Group("", func() {
+ m.Combo("").Get(repo.Settings).
+ Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
+ }, repo.SettingsCtxData)
m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), repo.SettingsAvatar)
m.Post("/avatar/delete", repo.SettingsDeleteAvatar)