Skip to content

Commit 6a33b29

Browse files
authored
Fix add authentication page (#16543)
* Fix add authentication page There is a regression in #16199 whereby the add authentication page fails to react to the change in selected type. This is due to the String() method on the LoginSourceType which is ameliorated with an Int() function being added. Following on from this there are a few other related bugs. Fix #16541 Signed-off-by: Andrew Thornton <[email protected]>
1 parent fd15fd4 commit 6a33b29

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

models/login_source.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func (typ LoginType) String() string {
3636
return LoginNames[typ]
3737
}
3838

39+
// Int returns the int value of the LoginType
40+
func (typ LoginType) Int() int {
41+
return int(typ)
42+
}
43+
3944
// LoginNames contains the name of LoginType values.
4045
var LoginNames = map[LoginType]string{
4146
LoginLDAP: "LDAP (via BindDN)",
@@ -218,6 +223,10 @@ func CreateLoginSource(source *LoginSource) error {
218223
return nil
219224
}
220225

226+
if settable, ok := source.Cfg.(LoginSourceSettable); ok {
227+
settable.SetLoginSource(source)
228+
}
229+
221230
registerableSource, ok := source.Cfg.(RegisterableSource)
222231
if !ok {
223232
return nil
@@ -320,6 +329,10 @@ func UpdateSource(source *LoginSource) error {
320329
return nil
321330
}
322331

332+
if settable, ok := source.Cfg.(LoginSourceSettable); ok {
333+
settable.SetLoginSource(source)
334+
}
335+
323336
registerableSource, ok := source.Cfg.(RegisterableSource)
324337
if !ok {
325338
return nil

services/auth/source/ldap/security_protocol.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func (s SecurityProtocol) String() string {
1919
return SecurityProtocolNames[s]
2020
}
2121

22+
// Int returns the int value of the SecurityProtocol
23+
func (s SecurityProtocol) Int() int {
24+
return int(s)
25+
}
26+
2227
// SecurityProtocolNames contains the name of SecurityProtocol values.
2328
var SecurityProtocolNames = map[SecurityProtocol]string{
2429
SecurityProtocolUnencrypted: "Unencrypted",

templates/admin/auth/edit.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<input type="hidden" name="id" value="{{.Source.ID}}">
1313
<div class="inline field">
1414
<label>{{$.i18n.Tr "admin.auths.auth_type"}}</label>
15-
<input type="hidden" id="auth_type" name="type" value="{{.Source.Type}}">
15+
<input type="hidden" id="auth_type" name="type" value="{{.Source.Type.Int}}">
1616
<span>{{.Source.TypeName}}</span>
1717
</div>
1818
<div class="required inline field {{if .Err_Name}}error{{end}}">
@@ -31,7 +31,7 @@
3131
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
3232
<div class="menu">
3333
{{range .SecurityProtocols}}
34-
<div class="item" data-value="{{.Type}}">{{.Name}}</div>
34+
<div class="item" data-value="{{.Type.Int}}">{{.Name}}</div>
3535
{{end}}
3636
</div>
3737
</div>

templates/admin/auth/new.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<div class="inline required field {{if .Err_Type}}error{{end}}">
1414
<label>{{.i18n.Tr "admin.auths.auth_type"}}</label>
1515
<div class="ui selection type dropdown">
16-
<input type="hidden" id="auth_type" name="type" value="{{.type}}">
16+
<input type="hidden" id="auth_type" name="type" value="{{.type.Int}}">
1717
<div class="text">{{.CurrentTypeName}}</div>
1818
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
1919
<div class="menu">
2020
{{range .AuthSources}}
21-
<div class="item" data-value="{{.Type}}">{{.Name}}</div>
21+
<div class="item" data-value="{{.Type.Int}}">{{.Name}}</div>
2222
{{end}}
2323
</div>
2424
</div>

templates/admin/auth/source/ldap.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
88
<div class="menu">
99
{{range .SecurityProtocols}}
10-
<div class="item" data-value="{{.Type}}">{{.Name}}</div>
10+
<div class="item" data-value="{{.Type.Int}}">{{.Name}}</div>
1111
{{end}}
1212
</div>
1313
</div>

0 commit comments

Comments
 (0)