Fix issue when removing and adding the first idp

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-07-06 20:55:24 +02:00 committed by Bjoern Schiessle
parent 224a2d6a6c
commit 174234a14e
No known key found for this signature in database
GPG key ID: 2378A753E2BF04F6
5 changed files with 24 additions and 11 deletions

View file

@ -18,7 +18,7 @@
this._getAppConfig('providerIds').done(function (data){
if (data.ocs.data.data !== '') {
OCA.User_SAML.Admin.providerIds = data.ocs.data.data;
OCA.User_SAML.Admin.currentConfig = OCA.User_SAML.Admin.providerIds.split(',')[0];
OCA.User_SAML.Admin.currentConfig = OCA.User_SAML.Admin.providerIds.split(',').sort()[0];
callback();
}
});
@ -113,6 +113,9 @@ $(function() {
OCA.User_SAML.Admin.init(function() {
$('.account-list li[data-id="' + OCA.User_SAML.Admin.currentConfig + '"]').addClass('active');
if (OCA.User_SAML.Admin.providerIds.split(',').length <= 1) {
$('[data-js="remove-idp"]').addClass('hidden');
}
// Hide depending on the setup state
if(type === '') {
$('#user-saml-choose-type').removeClass('hidden');
@ -155,7 +158,7 @@ $(function() {
var switchProvider = function(providerId) {
$('.account-list li').removeClass('active');
$('.account-list li[data-id="' + providerId + '"]').addClass('active');
OCA.User_SAML.Admin.currentConfig = providerId;
OCA.User_SAML.Admin.currentConfig = '' + providerId;
$.get(OC.generateUrl('/apps/user_saml/settings/providerSettings/' + providerId)).done(function(data) {
Object.keys(data).forEach(function(category, index){
var entries = data[category];
@ -186,15 +189,16 @@ $(function() {
});
};
$('.account-list').on('click', 'li:not(.add-provider)', function() {
$('.account-list').on('click', 'li:not(.add-provider):not(.remove-provider)', function() {
var providerId = '' + $(this).data('id');
switchProvider(providerId);
});
$('.account-list .add-provider').on('click', function() {
OCA.User_SAML.Admin.addProvider(function (nextId) {
$('<li data-id="' + nextId + '"><a>' + t('user_saml', 'Provider') + ' ' + nextId + '</a></li>').insertBefore('.account-list .add-provider');
$('<li data-id="' + nextId + '"><a>' + t('user_saml', 'Provider') + ' ' + nextId + '</a></li>').insertBefore('.account-list .remove-provider');
switchProvider(nextId);
$('[data-js="remove-idp"]').removeClass('hidden');
});
});
@ -202,6 +206,9 @@ $(function() {
OCA.User_SAML.Admin.removeProvider(function(currentConfig) {
$('.account-list li[data-id="' + currentConfig + '"]').remove();
switchProvider(OCA.User_SAML.Admin.providerIds.split(',')[0]);
if (OCA.User_SAML.Admin.providerIds.split(',').length <= 1) {
$('[data-js="remove-idp"]').addClass('hidden');
}
});
});

View file

@ -25,6 +25,7 @@ namespace OCA\User_SAML\Controller;
use OCA\User_SAML\Settings\Admin;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
@ -103,6 +104,7 @@ class SettingsController extends Controller {
$this->config->deleteAppValue('user_saml', $key);
}
}
return new Response();
}
}

View file

@ -55,11 +55,15 @@ class Admin implements ISettings {
*/
public function getForm() {
$providerIds = explode(',', $this->config->getAppValue('user_saml', 'providerIds', '1'));
natsort($providerIds);
$providers = [];
foreach ($providerIds as $id) {
$prefix = $id === '1' ? '' : $id .'-';
$name = $this->config->getAppValue('user_saml', $prefix . 'general-idp0_display_name', '');
$providers[$id] = $name === '' ? $this->l10n->t('Provider ') . $id : $name;
$providers[] = [
'id' => $id,
'name' => $name === '' ? $this->l10n->t('Provider ') . $id : $name
];
}
$serviceProviderFields = [
'x509cert' => $this->l10n->t('X.509 certificate of the Service Provider'),

View file

@ -51,12 +51,12 @@ style('user_saml', 'admin');
</div>
<ul class="account-list hidden">
<?php foreach ($_['providers'] as $id => $name) { ?>
<li data-id="<?php p($id); ?>">
<a href="#"><?php p($name); ?></a>
<?php foreach ($_['providers'] as $provider) { ?>
<li data-id="<?php p($provider['id']); ?>">
<a href="#"><?php p($provider['name']); ?></a>
</li>
<?php } ?>
<li><a data-js="remove-idp" class="icon-delete"><span class="hidden-visually"><?php p($l->t('Remove identity provider')); ?></span></a></li>
<li class="remove-provider"><a data-js="remove-idp" class="icon-delete"><span class="hidden-visually"><?php p($l->t('Remove identity provider')); ?></span></a></li>
<li class="add-provider"><a href="#" class="button"><span class="icon-add"></span> <?php p($l->t('Add identity provider')); ?></a></li>
</ul>

View file

@ -139,8 +139,8 @@ class AdminTest extends \Test\TestCase {
'general' => $generalSettings,
'attributeMappings' => $attributeMappingSettings,
'providers' => [
1 => 'Provider 1',
2 => 'Provider 2'
['id' => 1, 'name' => 'Provider 1'],
['id' => 2, 'name' => 'Provider 2']
],
];