Fix UI on edit auth source page (#14137)

* do not override OAuth URLs with default values when editing an auth source (fixes #12014)
* show custom url inputs by default for providers that don't provide an official hosted service
This commit is contained in:
Norwin 2020-12-26 18:22:42 +00:00 committed by GitHub
parent ad1164f73b
commit 24ecdbdb0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1832,17 +1832,19 @@ function initAdmin() {
}
}
function onOAuth2Change() {
function onOAuth2Change(applyDefaultValues) {
$('.open_id_connect_auto_discovery_url, .oauth2_use_custom_url').hide();
$('.open_id_connect_auto_discovery_url input[required]').removeAttr('required');
const provider = $('#oauth2_provider').val();
switch (provider) {
case 'github':
case 'gitlab':
case 'gitea':
case 'nextcloud':
case 'mastodon':
$('#oauth2_use_custom_url').attr('checked', 'checked');
// fallthrough intentional
case 'github':
case 'gitlab':
$('.oauth2_use_custom_url').show();
break;
case 'openidConnect':
@ -1850,19 +1852,21 @@ function initAdmin() {
$('.open_id_connect_auto_discovery_url').show();
break;
}
onOAuth2UseCustomURLChange();
onOAuth2UseCustomURLChange(applyDefaultValues);
}
function onOAuth2UseCustomURLChange() {
function onOAuth2UseCustomURLChange(applyDefaultValues) {
const provider = $('#oauth2_provider').val();
$('.oauth2_use_custom_url_field').hide();
$('.oauth2_use_custom_url_field input[required]').removeAttr('required');
if ($('#oauth2_use_custom_url').is(':checked')) {
if (applyDefaultValues) {
$('#oauth2_token_url').val($(`#${provider}_token_url`).val());
$('#oauth2_auth_url').val($(`#${provider}_auth_url`).val());
$('#oauth2_profile_url').val($(`#${provider}_profile_url`).val());
$('#oauth2_email_url').val($(`#${provider}_email_url`).val());
}
switch (provider) {
case 'github':
@ -1923,7 +1927,7 @@ function initAdmin() {
case '6': // OAuth2
$('.oauth2').show();
$('.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input').attr('required', 'required');
onOAuth2Change();
onOAuth2Change(true);
break;
case '7': // SSPI
$('.sspi').show();
@ -1941,8 +1945,8 @@ function initAdmin() {
$('#auth_type').trigger('change');
$('#security_protocol').on('change', onSecurityProtocolChange);
$('#use_paged_search').on('change', onUsePagedSearchChange);
$('#oauth2_provider').on('change', onOAuth2Change);
$('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
$('#oauth2_provider').on('change', () => onOAuth2Change(true));
$('#oauth2_use_custom_url').on('change', () => onOAuth2UseCustomURLChange(true));
$('#groups_enabled').on('change', onVerifyGroupMembershipChange);
}
// Edit authentication
@ -1956,9 +1960,9 @@ function initAdmin() {
$('#use_paged_search').on('change', onUsePagedSearchChange);
}
} else if (authType === '6') {
$('#oauth2_provider').on('change', onOAuth2Change);
$('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
onOAuth2Change();
$('#oauth2_provider').on('change', () => onOAuth2Change(true));
$('#oauth2_use_custom_url').on('change', () => onOAuth2UseCustomURLChange(false));
onOAuth2Change(false);
}
}