Skip to content

Commit

Permalink
Fix UI on edit auth source page (go-gitea#14137)
Browse files Browse the repository at this point in the history
* do not override OAuth URLs with default values when editing an auth source (fixes go-gitea#12014)
* show custom url inputs by default for providers that don't provide an official hosted service
  • Loading branch information
noerw authored Dec 26, 2020
1 parent ad1164f commit 24ecdbd
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1832,37 +1832,41 @@ 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':
$('.open_id_connect_auto_discovery_url input').attr('required', 'required');
$('.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')) {
$('#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());
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':
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 24ecdbd

Please sign in to comment.