From 44554d52ad4b07fd8bd6e6b5a34b9451d13705a5 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 24 Jul 2021 22:12:52 +0100 Subject: [PATCH 1/3] 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 --- models/login_source.go | 9 +++++++++ services/auth/source/ldap/security_protocol.go | 5 +++++ templates/admin/auth/edit.tmpl | 4 ++-- templates/admin/auth/new.tmpl | 4 ++-- templates/admin/auth/source/ldap.tmpl | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/models/login_source.go b/models/login_source.go index 5e1c6e222435e..5e8b0a0de5f18 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -36,6 +36,11 @@ func (typ LoginType) String() string { return LoginNames[typ] } +// String returns the string name of the LoginType +func (typ LoginType) Int() int { + return int(typ) +} + // LoginNames contains the name of LoginType values. var LoginNames = map[LoginType]string{ LoginLDAP: "LDAP (via BindDN)", @@ -218,6 +223,10 @@ func CreateLoginSource(source *LoginSource) error { return nil } + if settable, ok := source.Cfg.(LoginSourceSettable); ok { + settable.SetLoginSource(source) + } + registerableSource, ok := source.Cfg.(RegisterableSource) if !ok { return nil diff --git a/services/auth/source/ldap/security_protocol.go b/services/auth/source/ldap/security_protocol.go index 47c9d30e5cfe0..03e9ed88685fd 100644 --- a/services/auth/source/ldap/security_protocol.go +++ b/services/auth/source/ldap/security_protocol.go @@ -19,6 +19,11 @@ func (s SecurityProtocol) String() string { return SecurityProtocolNames[s] } +// String returns the name of the SecurityProtocol +func (s SecurityProtocol) Int() int { + return int(s) +} + // SecurityProtocolNames contains the name of SecurityProtocol values. var SecurityProtocolNames = map[SecurityProtocol]string{ SecurityProtocolUnencrypted: "Unencrypted", diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl index 3fbfedefe7012..22a2903b273f7 100644 --- a/templates/admin/auth/edit.tmpl +++ b/templates/admin/auth/edit.tmpl @@ -12,7 +12,7 @@
- + {{.Source.TypeName}}
@@ -31,7 +31,7 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/templates/admin/auth/new.tmpl b/templates/admin/auth/new.tmpl index 302132e06b2f1..6addc50d09c26 100644 --- a/templates/admin/auth/new.tmpl +++ b/templates/admin/auth/new.tmpl @@ -13,12 +13,12 @@
diff --git a/templates/admin/auth/source/ldap.tmpl b/templates/admin/auth/source/ldap.tmpl index 1cbcb2fd415ea..0b7ad7a4dae9b 100644 --- a/templates/admin/auth/source/ldap.tmpl +++ b/templates/admin/auth/source/ldap.tmpl @@ -7,7 +7,7 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
From 3a4adfd09ebe76e8c998810a82e97ecccb8c972b Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 24 Jul 2021 22:38:58 +0100 Subject: [PATCH 2/3] one more Signed-off-by: Andrew Thornton --- models/login_source.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/login_source.go b/models/login_source.go index 5e8b0a0de5f18..d9630ab22a098 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -329,6 +329,10 @@ func UpdateSource(source *LoginSource) error { return nil } + if settable, ok := source.Cfg.(LoginSourceSettable); ok { + settable.SetLoginSource(source) + } + registerableSource, ok := source.Cfg.(RegisterableSource) if !ok { return nil From cfac373dfe54011f8383c1a5487e71c163903395 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 24 Jul 2021 22:44:50 +0100 Subject: [PATCH 3/3] placate lint Signed-off-by: Andrew Thornton --- models/login_source.go | 2 +- services/auth/source/ldap/security_protocol.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/login_source.go b/models/login_source.go index d9630ab22a098..3a48074e9a7da 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -36,7 +36,7 @@ func (typ LoginType) String() string { return LoginNames[typ] } -// String returns the string name of the LoginType +// Int returns the int value of the LoginType func (typ LoginType) Int() int { return int(typ) } diff --git a/services/auth/source/ldap/security_protocol.go b/services/auth/source/ldap/security_protocol.go index 03e9ed88685fd..bb0c7770a1d35 100644 --- a/services/auth/source/ldap/security_protocol.go +++ b/services/auth/source/ldap/security_protocol.go @@ -19,7 +19,7 @@ func (s SecurityProtocol) String() string { return SecurityProtocolNames[s] } -// String returns the name of the SecurityProtocol +// Int returns the int value of the SecurityProtocol func (s SecurityProtocol) Int() int { return int(s) }