Unify repo settings & show better error (#19828)
* Unify context data * Actually show invalid url in error
This commit is contained in:
parent
3898fc5bda
commit
edf14202fe
7 changed files with 18 additions and 14 deletions
|
@ -128,7 +128,7 @@ func Validate(errs binding.Errors, data map[string]interface{}, f Form, l transl
|
||||||
case binding.ERR_EMAIL:
|
case binding.ERR_EMAIL:
|
||||||
data["ErrorMsg"] = trName + l.Tr("form.email_error")
|
data["ErrorMsg"] = trName + l.Tr("form.email_error")
|
||||||
case binding.ERR_URL:
|
case binding.ERR_URL:
|
||||||
data["ErrorMsg"] = trName + l.Tr("form.url_error")
|
data["ErrorMsg"] = trName + l.Tr("form.url_error", errs[0].Message)
|
||||||
case binding.ERR_INCLUDE:
|
case binding.ERR_INCLUDE:
|
||||||
data["ErrorMsg"] = trName + l.Tr("form.include_error", GetInclude(field))
|
data["ErrorMsg"] = trName + l.Tr("form.include_error", GetInclude(field))
|
||||||
case validation.ErrGlobPattern:
|
case validation.ErrGlobPattern:
|
||||||
|
|
|
@ -443,7 +443,7 @@ size_error = ` must be size %s.`
|
||||||
min_size_error = ` must contain at least %s characters.`
|
min_size_error = ` must contain at least %s characters.`
|
||||||
max_size_error = ` must contain at most %s characters.`
|
max_size_error = ` must contain at most %s characters.`
|
||||||
email_error = ` is not a valid email address.`
|
email_error = ` is not a valid email address.`
|
||||||
url_error = ` is not a valid URL.`
|
url_error = `'%s' is not a valid URL.`
|
||||||
include_error = ` must contain substring '%s'.`
|
include_error = ` must contain substring '%s'.`
|
||||||
glob_pattern_error = ` glob pattern is invalid: %s.`
|
glob_pattern_error = ` glob pattern is invalid: %s.`
|
||||||
regex_pattern_error = ` regex pattern is invalid: %s.`
|
regex_pattern_error = ` regex pattern is invalid: %s.`
|
||||||
|
|
|
@ -128,7 +128,7 @@ func handleMigrateRemoteAddrError(ctx *context.Context, err error, tpl base.TplN
|
||||||
case addrErr.IsProtocolInvalid:
|
case addrErr.IsProtocolInvalid:
|
||||||
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tpl, form)
|
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tpl, form)
|
||||||
case addrErr.IsURLError:
|
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:
|
case addrErr.IsPermissionDenied:
|
||||||
if addrErr.LocalPath {
|
if addrErr.LocalPath {
|
||||||
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tpl, form)
|
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)
|
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tpl, form)
|
||||||
default:
|
default:
|
||||||
log.Error("Error whilst updating url: %v", err)
|
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 {
|
} else {
|
||||||
log.Error("Error whilst updating url: %v", err)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,9 @@ const (
|
||||||
tplProtectedBranch base.TplName = "repo/settings/protected_branch"
|
tplProtectedBranch base.TplName = "repo/settings/protected_branch"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings show a repository's settings page
|
// SettingsCtxData is a middleware that sets all the general context data for the
|
||||||
func Settings(ctx *context.Context) {
|
// settings template.
|
||||||
|
func SettingsCtxData(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.settings")
|
ctx.Data["Title"] = ctx.Tr("repo.settings")
|
||||||
ctx.Data["PageIsSettingsOptions"] = true
|
ctx.Data["PageIsSettingsOptions"] = true
|
||||||
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
|
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
|
||||||
|
@ -94,15 +95,16 @@ func Settings(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["PushMirrors"] = pushMirrors
|
ctx.Data["PushMirrors"] = pushMirrors
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings show a repository's settings page
|
||||||
|
func Settings(ctx *context.Context) {
|
||||||
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SettingsPost response for changes of a repository
|
// SettingsPost response for changes of a repository
|
||||||
func SettingsPost(ctx *context.Context) {
|
func SettingsPost(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
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["ForcePrivate"] = setting.Repository.ForcePrivate
|
||||||
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
|
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
|
||||||
|
@ -827,7 +829,7 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
|
||||||
case addrErr.IsProtocolInvalid:
|
case addrErr.IsProtocolInvalid:
|
||||||
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tplSettingsOptions, form)
|
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tplSettingsOptions, form)
|
||||||
case addrErr.IsURLError:
|
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:
|
case addrErr.IsPermissionDenied:
|
||||||
if addrErr.LocalPath {
|
if addrErr.LocalPath {
|
||||||
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplSettingsOptions, form)
|
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplSettingsOptions, form)
|
||||||
|
|
|
@ -730,8 +730,10 @@ func RegisterRoutes(m *web.Route) {
|
||||||
|
|
||||||
m.Group("/{username}/{reponame}", func() {
|
m.Group("/{username}/{reponame}", func() {
|
||||||
m.Group("/settings", func() {
|
m.Group("/settings", func() {
|
||||||
|
m.Group("", func() {
|
||||||
m.Combo("").Get(repo.Settings).
|
m.Combo("").Get(repo.Settings).
|
||||||
Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
|
Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
|
||||||
|
}, repo.SettingsCtxData)
|
||||||
m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), repo.SettingsAvatar)
|
m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), repo.SettingsAvatar)
|
||||||
m.Post("/avatar/delete", repo.SettingsDeleteAvatar)
|
m.Post("/avatar/delete", repo.SettingsDeleteAvatar)
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err
|
||||||
strings.HasPrefix(remoteAddr, "git://") {
|
strings.HasPrefix(remoteAddr, "git://") {
|
||||||
u, err := url.Parse(remoteAddr)
|
u, err := url.Parse(remoteAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", &models.ErrInvalidCloneAddr{IsURLError: true}
|
return "", &models.ErrInvalidCloneAddr{IsURLError: true, Host: remoteAddr}
|
||||||
}
|
}
|
||||||
if len(authUsername)+len(authPassword) > 0 {
|
if len(authUsername)+len(authPassword) > 0 {
|
||||||
u.User = url.UserPassword(authUsername, authPassword)
|
u.User = url.UserPassword(authUsername, authPassword)
|
||||||
|
|
|
@ -44,7 +44,7 @@ func IsMigrateURLAllowed(remoteURL string, doer *user_model.User) error {
|
||||||
// Remote address can be HTTP/HTTPS/Git URL or local path.
|
// Remote address can be HTTP/HTTPS/Git URL or local path.
|
||||||
u, err := url.Parse(remoteURL)
|
u, err := url.Parse(remoteURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &models.ErrInvalidCloneAddr{IsURLError: true}
|
return &models.ErrInvalidCloneAddr{IsURLError: true, Host: remoteURL}
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.Scheme == "file" || u.Scheme == "" {
|
if u.Scheme == "file" || u.Scheme == "" {
|
||||||
|
|
Reference in a new issue