From 82ae7460bfaf668008de6613869285a55663bf46 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 17 Jun 2024 10:05:59 +0000 Subject: [PATCH] [BUG] admin authentication source JS errors (#4059) While trying to understand #1236, I was quite confused not to see the `Use Custom URLs` checkbox. This checkbox disappeared in b95a893b22a (because `getElementById` does not expect a `#` as first char), fixed in 4e816e1326086ff0929c028f837f62ba1c747759. After solving this, switching from `Nextcloud` to `OpenID Connect` triggered a JS error, which is addressed in 3efa4d836a300dc45b3ffece766b2b13539fc47c. Manual testing: - go to http://localhost:3000/admin/auths - click on `Add authentication source` - Choose `Authentication type`: `OAuth2` - Choose `OAuth2 provider`: `Nextcloud` - check that the `Use Custom URLs Instead of Default URLs` checkbox toggles the fields below - let the checkbox be checked - Switch the `OAuth2 provider` to `OpenID Connect` - ensure that no JS error is shown - Switch the `OAuth2 provider` to `Mastodon` - check that the fields below `Use Custom URLs Instead of Default URLs` have the right defaults (mastodon.social) ![2024-06-07-101638.png](/attachments/5bd6692e-3457-4dd8-b1c1-50e9a95a3100) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4059 Reviewed-by: twenty-panda Reviewed-by: Earl Warren Co-authored-by: oliverpool Co-committed-by: oliverpool --- release-notes/7.0.4/fix/4059.md | 1 + web_src/js/features/admin/common.js | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 release-notes/7.0.4/fix/4059.md diff --git a/release-notes/7.0.4/fix/4059.md b/release-notes/7.0.4/fix/4059.md new file mode 100644 index 0000000000..202ca4d33c --- /dev/null +++ b/release-notes/7.0.4/fix/4059.md @@ -0,0 +1 @@ +Wrongfully hidden "Use Custom URLs Instead of Default URLs" checkbox on Authentication Source Administration page. diff --git a/web_src/js/features/admin/common.js b/web_src/js/features/admin/common.js index b35502d52f..c2f3cde821 100644 --- a/web_src/js/features/admin/common.js +++ b/web_src/js/features/admin/common.js @@ -75,13 +75,16 @@ export function initAdminCommon() { } showElem('.open_id_connect_auto_discovery_url'); break; - default: - if (document.getElementById(`#${provider}_customURLSettings`)?.getAttribute('data-required')) { + default: { + const customURLSettings = document.getElementById(`${provider}_customURLSettings`); + if (!customURLSettings) break; + if (customURLSettings.getAttribute('data-required')) { document.getElementById('oauth2_use_custom_url')?.setAttribute('checked', 'checked'); } - if (document.getElementById(`#${provider}_customURLSettings`)?.getAttribute('data-available')) { + if (customURLSettings.getAttribute('data-available')) { showElem('.oauth2_use_custom_url'); } + } } onOAuth2UseCustomURLChange(applyDefaultValues); } @@ -95,11 +98,12 @@ export function initAdminCommon() { if (document.getElementById('oauth2_use_custom_url')?.checked) { for (const custom of ['token_url', 'auth_url', 'profile_url', 'email_url', 'tenant']) { - if (applyDefaultValues) { - document.getElementById(`oauth2_${custom}`).value = document.getElementById(`${provider}_${custom}`).value; - } const customInput = document.getElementById(`${provider}_${custom}`); - if (customInput && customInput.getAttribute('data-available')) { + if (!customInput) continue; + if (applyDefaultValues) { + document.getElementById(`oauth2_${custom}`).value = customInput.value; + } + if (customInput.getAttribute('data-available')) { for (const input of document.querySelectorAll(`.oauth2_${custom} input`)) { input.setAttribute('required', 'required'); }