Skip to content

Commit a223bc8

Browse files
authored
Prevent 500 when there is an error during new auth source post (#19041)
Fix #19036 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 886b1de commit a223bc8

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

routers/web/admin/auths.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func NewAuthSource(ctx *context.Context) {
9393
ctx.Data["PageIsAdmin"] = true
9494
ctx.Data["PageIsAdminAuthentications"] = true
9595

96-
ctx.Data["type"] = auth.LDAP
96+
ctx.Data["type"] = auth.LDAP.Int()
9797
ctx.Data["CurrentTypeName"] = auth.Names[auth.LDAP]
9898
ctx.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
9999
ctx.Data["smtp_auth"] = "PLAIN"
@@ -112,7 +112,7 @@ func NewAuthSource(ctx *context.Context) {
112112
ctx.Data["SSPIDefaultLanguage"] = ""
113113

114114
// only the first as default
115-
ctx.Data["oauth2_provider"] = oauth2providers[0]
115+
ctx.Data["oauth2_provider"] = oauth2providers[0].Name
116116

117117
ctx.HTML(http.StatusOK, tplAuthNew)
118118
}
@@ -253,9 +253,6 @@ func NewAuthSourcePost(ctx *context.Context) {
253253
ctx.Data["SSPISeparatorReplacement"] = "_"
254254
ctx.Data["SSPIDefaultLanguage"] = ""
255255

256-
// FIXME: most error path to render tplAuthNew will fail and result in 500
257-
// * template: admin/auth/new:17:68: executing "admin/auth/new" at <.type.Int>: can't evaluate field Int in type interface {}
258-
// * template: admin/auth/source/oauth:5:93: executing "admin/auth/source/oauth" at <.oauth2_provider.Name>: can't evaluate field Name in type interface {}
259256
hasTLS := false
260257
var config convert.Conversion
261258
switch auth.Type(form.Type) {

templates/admin/auth/new.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="inline required field {{if .Err_Type}}error{{end}}">
1515
<label>{{.i18n.Tr "admin.auths.auth_type"}}</label>
1616
<div class="ui selection type dropdown">
17-
<input type="hidden" id="auth_type" name="type" value="{{.type.Int}}">
17+
<input type="hidden" id="auth_type" name="type" value="{{.type}}">
1818
<div class="text">{{.CurrentTypeName}}</div>
1919
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
2020
<div class="menu">

templates/admin/auth/source/oauth.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div class="inline required field">
33
<label>{{.i18n.Tr "admin.auths.oauth2_provider"}}</label>
44
<div class="ui selection type dropdown">
5-
<input type="hidden" id="oauth2_provider" name="oauth2_provider" value="{{.oauth2_provider.Name}}">
6-
<div class="text">{{.oauth2_provider.Name}}</div>
5+
<input type="hidden" id="oauth2_provider" name="oauth2_provider" value="{{.oauth2_provider}}">
6+
<div class="text">{{.oauth2_provider}}</div>
77
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
88
<div class="menu">
99
{{range .OAuth2Providers}}

0 commit comments

Comments
 (0)