allow user to start migration in admin settings if no external user back-ends are enabled

This commit is contained in:
Bjoern Schiessle 2015-04-09 16:07:15 +02:00
parent 6bcf88ca96
commit d2ef73367c
6 changed files with 201 additions and 18 deletions

View File

@ -82,8 +82,12 @@ $excludedGroupsList = $appConfig->getValue('core', 'shareapi_exclude_groups_list
$excludedGroupsList = explode(',', $excludedGroupsList); // FIXME: this should be JSON!
$template->assign('shareExcludedGroupsList', implode('|', $excludedGroupsList));
$template->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
$backends = \OC::$server->getUserManager()->getBackends();
$externalBackends = (count($backends) > 1) ? true : false;
$template->assign('encryptionReady', \OC::$server->getEncryptionManager()->isReady());
$template->assign('externalBackendsEnabled', $externalBackends);
$encryptionModules = \OC::$server->getEncryptionManager()->getEncryptionModules();
try {
$defaultEncryptionModule = \OC::$server->getEncryptionManager()->getDefaultEncryptionModule();
$defaultEncryptionModuleId = $defaultEncryptionModule->getId();

View File

@ -23,8 +23,10 @@
namespace OC\Settings;
use OC\Files\View;
use OC\Settings\Controller\AppSettingsController;
use OC\Settings\Controller\CheckSetupController;
use OC\Settings\Controller\EncryptionController;
use OC\Settings\Controller\GroupsController;
use OC\Settings\Controller\LogSettingsController;
use OC\Settings\Controller\MailSettingsController;
@ -65,6 +67,17 @@ class Application extends App {
$c->query('DefaultMailAddress')
);
});
$container->registerService('EncryptionController', function(IContainer $c) {
return new EncryptionController(
$c->query('AppName'),
$c->query('Request'),
$c->query('L10N'),
$c->query('Config'),
$c->query('DatabaseConnection'),
$c->query('UserManager'),
new View()
);
});
$container->registerService('AppSettingsController', function(IContainer $c) {
return new AppSettingsController(
$c->query('AppName'),
@ -207,5 +220,8 @@ class Application extends App {
$container->registerService('Util', function(IContainer $c) {
return new \OC_Util();
});
$container->registerService('DatabaseConnection', function(IContainer $c) {
return $c->query('ServerContainer')->getDatabaseConnection();
});
}
}

View File

@ -0,0 +1,122 @@
<?php
/**
* @author Björn Schießle <schiessle@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Settings\Controller;
use OC\Files\View;
use OCA\Encryption\Migration;
use OCP\IL10N;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\IConfig;
use OC\DB\Connection;
use OCP\IUserManager;
/**
* @package OC\Settings\Controller
*/
class EncryptionController extends Controller {
/** @var \OCP\IL10N */
private $l10n;
/** @var Connection */
private $connection;
/** @var IConfig */
private $config;
/** @var IUserManager */
private $userManager;
/** @var View */
private $view;
/**
* @param string $appName
* @param IRequest $request
* @param \OCP\IL10N $l10n
* @param \OCP\IConfig $config
* @param \OC\DB\Connection $connection
* @param IUserManager $userManager
* @param View $view
*/
public function __construct($appName,
IRequest $request,
IL10N $l10n,
IConfig $config,
Connection $connection,
IUserManager $userManager,
View $view) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->config = $config;
$this->connection = $connection;
$this->view = $view;
$this->userManager = $userManager;
}
/**
* start migration
*
* @return array
*/
public function startMigration() {
// allow as long execution on the web server as possible
set_time_limit(0);
$migration = new Migration($this->config, $this->view, $this->connection);
$migration->reorganizeSystemFolderStructure();
$migration->updateDB();
try {
foreach ($this->userManager->getBackends() as $backend) {
$limit = 500;
$offset = 0;
do {
$users = $backend->getUsers('', $limit, $offset);
foreach ($users as $user) {
$migration->reorganizeFolderStructureForUser($user);
}
$offset += $limit;
} while (count($users) >= $limit);
}
} catch (\Exception $e) {
return array(
'data' => array(
'message' => (string)$this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()]),
),
'status' => 'error',
);
}
return array('data' =>
array('message' =>
(string) $this->l10n->t('Migration Completed')
),
'status' => 'success'
);
}
}

View File

@ -55,7 +55,7 @@ $(document).ready(function(){
});
$('#encryptionEnabled').change(function() {
$('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
$('#encryptionAPI div#EncryptionSettingsArea').toggleClass('hidden');
});
$('#encryptionAPI input').change(function() {
@ -70,6 +70,26 @@ $(document).ready(function(){
OC.AppConfig.setValue('core', $(this).attr('name'), value);
});
$('#startmigration').click(function(event){
$(window).on('beforeunload.encryption', function(e) {
return t('settings', 'Migration in progress. Please wait until the migration is finished');
});
event.preventDefault();
$('#startmigration').prop('disabled', true);
OC.msg.startAction('#startmigration_msg', t('settings', 'Migration started …'));
$.post(OC.generateUrl('/settings/admin/startmigration'), '', function(data){
OC.msg.finishedAction('#startmigration_msg', data);
if (data['status'] === 'success') {
$('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
$('#encryptionAPI div#migrationWarning').toggleClass('hidden');
} else {
$('#startmigration').prop('disabled', false);
}
$(window).off('beforeunload.encryption');
});
});
$('#shareAPI input:not(#excludedGroups)').change(function() {
var value = $(this).val();
if ($(this).attr('type') === 'checkbox') {

View File

@ -42,6 +42,7 @@ $application->registerRoutes($this, [
['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],

View File

@ -300,30 +300,50 @@ if ($_['cronErrors']) {
</div>
<div class="section" id='encryptionAPI'>
<h2><?php p($l->t('Server Side Encryption'));?></h2>
<p id="enable">
<input type="checkbox" name="encryption_enabled" id="encryptionEnabled"
value="1" <?php if ($_['encryptionEnabled']) print_unescaped('checked="checked"'); ?> />
<label for="encryptionEnabled"><?php p($l->t('Enable Server-Side-Encryption'));?></label><br/>
</p>
<div id='selectEncryptionModules' class="<?php if (!$_['encryptionEnabled']) { p('hidden'); }?>">
<?php if ($_['encryptionReady'] === false) {
p('Seems like you are in transit from the old encryption (ownCloud <= 8.0) to the new one. Please enable the "ownCloud Default Encryption Module" and run \'occ encryption:migrate\'');
} elseif (empty($_['encryptionModules'])) {
<h2><?php p($l->t('Server Side Encryption')); ?> </h2>
<p id="enable">
<input type="checkbox" name="encryption_enabled"
id="encryptionEnabled"
value="1" <?php if ($_['encryptionEnabled']) print_unescaped('checked="checked"'); ?> />
<label
for="encryptionEnabled"><?php p($l->t('Enable Server-Side-Encryption')); ?> <span id="startmigration_msg" class="msg"></span> </label><br/>
</p>
<div id="EncryptionSettingsArea" class="<?php if (!$_['encryptionEnabled']) p('hidden'); ?>">
<div id='selectEncryptionModules' class="<?php if (!$_['encryptionReady']) p('hidden'); ?>">
<?php
if (empty($_['encryptionModules'])) {
p('No encryption module loaded, please load a encryption module in the app menu');
} else { ?>
<h3>Select default encryption module:</h3>
<fieldset id='encryptionModules'>
<?php foreach ($_['encryptionModules'] as $id => $module): ?>
<input type="radio" id="<?php p($id) ?>"
name="default_encryption_module"
value="<?php p($id) ?>"
<?php if($module['default']) { p('checked'); } ?>>
<label for="<?php p($id) ?>"><?php p($module['displayName']) ?></label><br />
<?php endforeach;?>
<?php foreach ($_['encryptionModules'] as $id => $module): ?>
<input type="radio" id="<?php p($id) ?>"
name="default_encryption_module"
value="<?php p($id) ?>"
<?php if ($module['default']) {
p('checked');
} ?>>
<label
for="<?php p($id) ?>"><?php p($module['displayName']) ?></label>
<br/>
<?php endforeach; ?>
</fieldset>
<?php } ?>
</div>
<div id="migrationWarning" class="<?php if ($_['encryptionReady']) p('hidden'); ?>">
<?php
if ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === true) {
p('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. '
. 'Please enable the "ownCloud Default Encryption Module" and run \'occ encryption:migrate\'');
} elseif ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === false) {
p('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one.'); ?>
<input type="submit" name="startmigration" id="startmigration"
value="<?php p($l->t('Start migration')); ?>"/>
<?php } ?>
</div>
</div>
</div>
<div class="section" id="mail_general_settings">