fix old settings present when switching providers

- wrongly used way to set value attribute

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2022-03-01 19:30:16 +01:00 committed by blizzz (Rebase PR Action)
parent 97c0594ab0
commit 77b14b6c6f
3 changed files with 18 additions and 4 deletions

View file

@ -210,6 +210,17 @@ $(function() {
$('.account-list li[data-id="' + providerId + '"]').addClass('active');
OCA.User_SAML.Admin.currentConfig = '' + providerId;
$.get(OC.generateUrl('/apps/user_saml/settings/providerSettings/' + providerId)).done(function(data) {
document.querySelectorAll('#user-saml-settings input[type="text"], #user-saml-settings textarea').forEach(function (inputNode) {
inputNode.value = '';
});
document.querySelectorAll('#user-saml-settings input[type="checkbox"]').forEach(function (inputNode) {
inputNode.checked = false;
inputNode.setAttribute('value', '0');
});
document.querySelectorAll('#user-saml-settings select option').forEach(function (inputNode) {
inputNode.selected = false;
});
Object.keys(data).forEach(function(category){
var entries = data[category];
Object.keys(entries).forEach(function (configKey) {
@ -226,9 +237,10 @@ $(function() {
|| htmlElement.tagName === 'TEXTAREA'
) {
htmlElement.nodeValue = entries[configKey];
htmlElement.value = entries[configKey];
} else if (htmlElement.tagName === 'INPUT' && htmlElement.getAttribute('type') === 'checkbox') {
htmlElement.checked = entries[configKey] === '1';
htmlElement.setAttribute('value', entries[configKey] === '1' ? '1' : '0');
htmlElement.value = entries[configKey] === '1' ? '1' : '0';
} else if (htmlElement.tagName === 'SELECT') {
htmlElement.querySelector('[value="' + entries[configKey] + '"]').selected = true;
} else {

View file

@ -177,8 +177,9 @@ class Admin implements ISettings {
'selected' => false,
],
];
if ($firstIdPConfig !== null && isset($nameIdFormats[$firstIdPConfig['sp-name-id-format']])) {
$nameIdFormats[$firstIdPConfig['sp-name-id-format']]['selected'] = true;
$chosenFormat = $firstIdPConfig['sp-name-id-format'] ?? '';
if ($firstIdPConfig !== null && isset($nameIdFormats[$chosenFormat])) {
$nameIdFormats[$chosenFormat]['selected'] = true;
} else {
$nameIdFormats[Constants::NAMEID_UNSPECIFIED]['selected'] = true;
}

View file

@ -176,7 +176,7 @@ class AdminTest extends \Test\TestCase {
],
Constants::NAMEID_UNSPECIFIED => [
'label' => 'Unspecified',
'selected' => false,
'selected' => true,
],
Constants::NAMEID_WINDOWS_DOMAIN_QUALIFIED_NAME => [
'label' => 'Windows domain qualified name',
@ -200,6 +200,7 @@ class AdminTest extends \Test\TestCase {
['id' => 2, 'name' => 'Provider 2']
],
'name-id-formats' => $nameIdFormats,
'config' => [],
];
return $params;