Make disableapp.php accept arrays

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2017-04-25 21:06:24 +02:00
parent da67264a23
commit 732c92e93a
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
3 changed files with 135 additions and 53 deletions

View File

@ -370,9 +370,9 @@ class AppSettingsController extends Controller {
if($app['id'] === $identifier) { if($app['id'] === $identifier) {
if($newCategory) { if($newCategory) {
$app['newCategory'] = true; $app['newCategory'] = true;
$app['bundleId'] = $bundle->getIdentifier();
$app['categoryName'] = $bundle->getName(); $app['categoryName'] = $bundle->getName();
} }
$app['bundleId'] = $bundle->getIdentifier();
$newCategory = false; $newCategory = false;
$apps[] = $app; $apps[] = $app;
continue; continue;

View File

@ -36,8 +36,9 @@ if (!array_key_exists('appid', $_POST)) {
exit; exit;
} }
$appId = (string)$_POST['appid']; $appIds = (array)$_POST['appid'];
$appId = OC_App::cleanAppId($appId); foreach($appIds as $appId) {
$appId = OC_App::cleanAppId($appId);
OC_App::disable($appId); OC_App::disable($appId);
}
OC_JSON::success(); OC_JSON::success();

View File

@ -313,53 +313,94 @@ OC.Settings.Apps = OC.Settings.Apps || {
return; return;
} }
var bundles = OC.Settings.Apps.State.currentCategoryElements; var apps = OC.Settings.Apps.State.currentCategoryElements;
bundles.forEach(function(bundle) { var appsToEnable = [];
if(bundle['id'] === bundleId) { apps.forEach(function(app) {
OC.Settings.Apps.enableApp(bundle['apps'], active, element, groups); if(app['bundleId'] === bundleId) {
if(app['active'] === false) {
appsToEnable.push(app['id']);
}
} }
}); });
OC.Settings.Apps.enableApp(appsToEnable, false, groups);
}, },
enableApp:function(appId, active, element, groups) { /**
* @param {string[]} appId
* @param {boolean} active
* @param {array} groups
*/
enableApp:function(appId, active, groups) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, element, groups)); OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, groups));
return; return;
} }
var elements = [];
appId.forEach(function(appId) {
elements.push($('#app-'+appId+' .enable'));
});
var self = this; var self = this;
OC.Settings.Apps.hideErrorMessage(appId); appId.forEach(function(appId) {
OC.Settings.Apps.hideErrorMessage(appId);
});
groups = groups || []; groups = groups || [];
var appItem = $('div#app-'+appId+''); var appItems = [];
appId.forEach(function(appId) {
appItems.push($('div#app-'+appId+''));
});
if(active && !groups.length) { if(active && !groups.length) {
element.val(t('settings','Disabling app …')); elements.forEach(function(element) {
element.val(t('settings','Disabling app …'));
});
$.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appId},function(result) { $.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appId},function(result) {
if(!result || result.status !== 'success') { if(!result || result.status !== 'success') {
if (result.data && result.data.message) { if (result.data && result.data.message) {
OC.Settings.Apps.showErrorMessage(appId, result.data.message); OC.Settings.Apps.showErrorMessage(appId, result.data.message);
appItem.data('errormsg', result.data.message); appItems.forEach(function(appItem) {
appItem.data('errormsg', result.data.message);
})
} else { } else {
OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while disabling app')); OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while disabling app'));
appItem.data('errormsg', t('settings', 'Error while disabling app')); appItems.forEach(function(appItem) {
appItem.data('errormsg', t('settings', 'Error while disabling app'));
});
} }
element.val(t('settings','Disable')); elements.forEach(function(element) {
appItem.addClass('appwarning'); element.val(t('settings','Disable'));
});
appItems.forEach(function(appItem) {
appItem.addClass('appwarning');
});
} else { } else {
OC.Settings.Apps.rebuildNavigation(); OC.Settings.Apps.rebuildNavigation();
appItem.data('active',false); appItems.forEach(function(appItem) {
appItem.data('groups', ''); appItem.data('active', false);
element.data('active',false); appItem.data('groups', '');
appItem.removeClass('active'); });
element.val(t('settings','Enable')); elements.forEach(function(element) {
element.parent().find(".groups-enable").hide(); element.data('active', false);
element.parent().find('#group_select').hide().val(null); });
appItems.forEach(function(appItem) {
appItem.removeClass('active');
});
elements.forEach(function(element) {
element.val(t('settings', 'Enable'));
element.parent().find(".groups-enable").hide();
element.parent().find('#group_select').hide().val(null);
});
OC.Settings.Apps.State.apps[appId].active = false; OC.Settings.Apps.State.apps[appId].active = false;
} }
},'json'); },'json');
} else { } else {
// TODO: display message to admin to not refresh the page! // TODO: display message to admin to not refresh the page!
// TODO: lock UI to prevent further operations // TODO: lock UI to prevent further operations
element.val(t('settings','Enabling app …')); elements.forEach(function(element) {
element.val(t('settings', 'Enabling app …'));
});
var appIdArray = []; var appIdArray = [];
if( typeof appId === 'string' ) { if( typeof appId === 'string' ) {
@ -371,13 +412,21 @@ OC.Settings.Apps = OC.Settings.Apps || {
if(!result || result.status !== 'success') { if(!result || result.status !== 'success') {
if (result.data && result.data.message) { if (result.data && result.data.message) {
OC.Settings.Apps.showErrorMessage(appId, result.data.message); OC.Settings.Apps.showErrorMessage(appId, result.data.message);
appItem.data('errormsg', result.data.message); appItems.forEach(function(appItem) {
appItem.data('errormsg', result.data.message);
});
} else { } else {
OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app')); OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app'));
appItem.data('errormsg', t('settings', 'Error while disabling app')); appItems.forEach(function(appItem) {
appItem.data('errormsg', t('settings', 'Error while disabling app'));
});
} }
element.val(t('settings','Enable')); elements.forEach(function(element) {
appItem.addClass('appwarning'); element.val(t('settings', 'Enable'));
});
appItems.forEach(function(appItem) {
appItem.addClass('appwarning');
});
} else { } else {
self._checkServerHealth().done(function() { self._checkServerHealth().done(function() {
if (result.data.update_required) { if (result.data.update_required) {
@ -389,24 +438,40 @@ OC.Settings.Apps = OC.Settings.Apps || {
} }
OC.Settings.Apps.rebuildNavigation(); OC.Settings.Apps.rebuildNavigation();
appItem.data('active',true); appItems.forEach(function(appItem) {
element.data('active',true); appItem.data('active', true);
appItem.addClass('active'); });
element.val(t('settings','Disable')); elements.forEach(function(element) {
element.data('active', true);
});
appItems.forEach(function(appItem) {
appItem.addClass('active');
});
elements.forEach(function(element) {
element.val(t('settings', 'Disable'));
});
var app = OC.Settings.Apps.State.apps[appId]; var app = OC.Settings.Apps.State.apps[appId];
app.active = true; app.active = true;
if (OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') || if (OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') ||
OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) { OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) {
element.parent().find(".groups-enable").prop('checked', true); elements.forEach(function(element) {
element.parent().find(".groups-enable").hide(); element.parent().find(".groups-enable").prop('checked', true);
element.parent().find('#group_select').hide().val(null); element.parent().find(".groups-enable").hide();
element.parent().find('#group_select').hide().val(null);
});
} else { } else {
element.parent().find("#groups-enable").show(); elements.forEach(function(element) {
element.parent().find("#groups-enable").show();
});
if (groups) { if (groups) {
appItem.data('groups', JSON.stringify(groups)); appItems.forEach(function(appItem) {
appItem.data('groups', JSON.stringify(groups));
});
} else { } else {
appItem.data('groups', ''); appItems.forEach(function(appItem) {
appItem.data('groups', '');
});
} }
} }
}).fail(function() { }).fail(function() {
@ -416,26 +481,40 @@ OC.Settings.Apps = OC.Settings.Apps || {
appId, appId,
t('settings', 'Error: this app cannot be enabled because it makes the server unstable') t('settings', 'Error: this app cannot be enabled because it makes the server unstable')
); );
appItem.data('errormsg', t('settings', 'Error while enabling app')); appItems.forEach(function(appItem) {
element.val(t('settings','Enable')); appItem.data('errormsg', t('settings', 'Error while enabling app'));
appItem.addClass('appwarning'); });
elements.forEach(function(element) {
element.val(t('settings', 'Enable'));
});
appItems.forEach(function(appItem) {
appItem.addClass('appwarning');
});
}).fail(function() { }).fail(function() {
OC.Settings.Apps.showErrorMessage( OC.Settings.Apps.showErrorMessage(
appId, appId,
t('settings', 'Error: could not disable broken app') t('settings', 'Error: could not disable broken app')
); );
appItem.data('errormsg', t('settings', 'Error while disabling broken app')); appItems.forEach(function(appItem) {
element.val(t('settings','Enable')); appItem.data('errormsg', t('settings', 'Error while disabling broken app'));
});
elements.forEach(function(element) {
element.val(t('settings', 'Enable'));
});
}); });
}); });
} }
},'json') },'json')
.fail(function() { .fail(function() {
OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app')); OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app'));
appItem.data('errormsg', t('settings', 'Error while enabling app')); appItems.forEach(function(appItem) {
appItem.data('active',false); appItem.data('errormsg', t('settings', 'Error while enabling app'));
appItem.addClass('appwarning'); appItem.data('active', false);
element.val(t('settings','Enable')); appItem.addClass('appwarning');
});
elements.forEach(function(element) {
element.val(t('settings', 'Enable'));
});
}); });
} }
}, },
@ -799,14 +878,16 @@ OC.Settings.Apps = OC.Settings.Apps || {
$(document).on('click', '#apps-list input.enable', function () { $(document).on('click', '#apps-list input.enable', function () {
var appId = $(this).data('appid'); var appId = $(this).data('appid');
var bundleId = $(this).data('bundleid');
var element = $(this); var element = $(this);
var active = $(this).data('active'); var active = $(this).data('active');
var category = $('#app-navigation').attr('data-category'); var category = $('#app-navigation').attr('data-category');
if(category === 'app-bundles') { if(bundleId) {
OC.Settings.Apps.enableAppBundle(appId, active, element); OC.Settings.Apps.enableAppBundle(bundleId, active, element);
element.val(t('settings', 'Enable all'));
} else { } else {
OC.Settings.Apps.enableApp(appId, active, element); OC.Settings.Apps.enableApp([appId], active);
} }
}); });
@ -835,7 +916,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
var appId = element.data('appid'); var appId = element.data('appid');
if (appId) { if (appId) {
OC.Settings.Apps.enableApp(appId, false, element, groups); OC.Settings.Apps.enableApp([appId], false, groups);
OC.Settings.Apps.State.apps[appId].groups = groups; OC.Settings.Apps.State.apps[appId].groups = groups;
} }
}); });