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($newCategory) {
$app['newCategory'] = true;
$app['bundleId'] = $bundle->getIdentifier();
$app['categoryName'] = $bundle->getName();
}
$app['bundleId'] = $bundle->getIdentifier();
$newCategory = false;
$apps[] = $app;
continue;

View File

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

View File

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