From f5d29152c9529bee79a59be2d0ddecb0530e7d77 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:04:31 +0300 Subject: [PATCH] [v11.3.x] SSO: Fix client side validations for LDAP (#94596) SSO: Fix client side validations for LDAP (#94561) * fix client side validations for LDAP * add translations for new messages * simplify code in isInvalidField() (cherry picked from commit 0bd3ad1d5a15a879fff3fe4f83af5edb2521c807) Co-authored-by: Mihai Doarna --- .../features/admin/ldap/LdapSettingsPage.tsx | 29 ++++++++++++++----- public/locales/en-US/grafana.json | 9 ++++-- public/locales/pseudo-LOCALE/grafana.json | 9 ++++-- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/public/app/features/admin/ldap/LdapSettingsPage.tsx b/public/app/features/admin/ldap/LdapSettingsPage.tsx index 6c518cb973b..fd84d4f0dcd 100644 --- a/public/app/features/admin/ldap/LdapSettingsPage.tsx +++ b/public/app/features/admin/ldap/LdapSettingsPage.tsx @@ -108,7 +108,7 @@ export const LdapSettingsPage = () => { const methods = useForm({ defaultValues: emptySettings }); const { control, - formState: { isDirty }, + formState: { isDirty, errors }, getValues, setValue, handleSubmit, @@ -216,7 +216,7 @@ export const LdapSettingsPage = () => { /** * Button's Actions */ - const submitAndEnableLdapSettings = async (payload: LdapPayload) => { + const submitFormAndToggleSettings = async (payload: LdapPayload) => { payload.settings.enabled = !payload.settings.enabled; await putPayload(payload); reportInteraction('authentication_ldap_enabled'); @@ -254,6 +254,11 @@ export const LdapSettingsPage = () => { reportInteraction('authentication_ldap_abandoned'); }; + const isInvalidField = (field: string) => { + const err = errors?.settings?.config?.servers?.[0]; + return typeof err === 'object' && field in err; + }; + const subTitle = ( The LDAP integration in Grafana allows your Grafana users to log in with their LDAP credentials. Find out more in @@ -282,7 +287,7 @@ export const LdapSettingsPage = () => { {config.disableLoginForm && disabledFormAlert} -
+ {isLoading && } {!isLoading && ( @@ -291,7 +296,10 @@ export const LdapSettingsPage = () => { Basic Settings { /> { /> !!value?.length }} name={`${serverConfig}.search_base_dns`} control={control} render={({ field: { onChange, ref, ...field } }) => ( @@ -397,7 +412,7 @@ export const LdapSettingsPage = () => { Disable )} - diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 0823f93c9b3..af39e00eac0 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -1225,7 +1225,8 @@ "documentation": "documentation", "host": { "description": "Hostname or IP address of the LDAP server you wish to connect to.", - "label": "Server host *", + "error": "Server host is a required field", + "label": "Server host", "placeholder": "example: 127.0.0.1" }, "login-form-alert": { @@ -1234,12 +1235,14 @@ }, "search_filter": { "description": "LDAP search filter used to locate specific entries within the directory.", - "label": "Search filter *", + "error": "Search filter is a required field", + "label": "Search filter", "placeholder": "example: cn=%s" }, "search-base-dns": { "description": "An array of base dns to search through.", - "label": "Search base DNS *", + "error": "Search base DNS is a required field", + "label": "Search base DNS", "placeholder": "example: dc=grafana,dc=org" }, "subtitle": "The LDAP integration in Grafana allows your Grafana users to log in with their LDAP credentials. Find out more in our <2><0>documentation.", diff --git a/public/locales/pseudo-LOCALE/grafana.json b/public/locales/pseudo-LOCALE/grafana.json index a2a87a13fd4..1e58315b10e 100644 --- a/public/locales/pseudo-LOCALE/grafana.json +++ b/public/locales/pseudo-LOCALE/grafana.json @@ -1225,7 +1225,8 @@ "documentation": "đőčūmęʼnŧäŧįőʼn", "host": { "description": "Ħőşŧʼnämę őř ĨP äđđřęşş őƒ ŧĥę ĿĐÅP şęřvęř yőū ŵįşĥ ŧő čőʼnʼnęčŧ ŧő.", - "label": "Ŝęřvęř ĥőşŧ *", + "error": "Ŝęřvęř ĥőşŧ įş ä řęqūįřęđ ƒįęľđ", + "label": "Ŝęřvęř ĥőşŧ", "placeholder": "ęχämpľę: 127.0.0.1" }, "login-form-alert": { @@ -1234,12 +1235,14 @@ }, "search_filter": { "description": "ĿĐÅP şęäřčĥ ƒįľŧęř ūşęđ ŧő ľőčäŧę şpęčįƒįč ęʼnŧřįęş ŵįŧĥįʼn ŧĥę đįřęčŧőřy.", - "label": "Ŝęäřčĥ ƒįľŧęř *", + "error": "Ŝęäřčĥ ƒįľŧęř įş ä řęqūįřęđ ƒįęľđ", + "label": "Ŝęäřčĥ ƒįľŧęř", "placeholder": "ęχämpľę: čʼn=%ş" }, "search-base-dns": { "description": "Åʼn äřřäy őƒ þäşę đʼnş ŧő şęäřčĥ ŧĥřőūģĥ.", - "label": "Ŝęäřčĥ þäşę ĐŃŜ *", + "error": "Ŝęäřčĥ þäşę ĐŃŜ įş ä řęqūįřęđ ƒįęľđ", + "label": "Ŝęäřčĥ þäşę ĐŃŜ", "placeholder": "ęχämpľę: đč=ģřäƒäʼnä,đč=őřģ" }, "subtitle": "Ŧĥę ĿĐÅP įʼnŧęģřäŧįőʼn įʼn Ğřäƒäʼnä äľľőŵş yőūř Ğřäƒäʼnä ūşęřş ŧő ľőģ įʼn ŵįŧĥ ŧĥęįř ĿĐÅP čřęđęʼnŧįäľş. Fįʼnđ őūŧ mőřę įʼn őūř <2><0>đőčūmęʼnŧäŧįőʼn.",