Commit cc7944da authored by Tom Needham's avatar Tom Needham Committed by Thomas Müller
Browse files

Move settings registration to info.xml + merge 'personal' & 'admin' settings (#26449)

* WIP to loading settings panels from info.xml

* Handle legacy settings panels

* Move over existing built in panels. Still needs JS work

* Add language switcher

* Delete old personal settings controller

* Kill getName on IPanel

* Fix sync client urls

* Adding apps mgmt as admin section

* Fix JS loading for personal settings panels: profile

* Move shipped apps to new admin settings registration

* Fix section styling on settings panels

* - fix sort order sections
- adjust some styling
- remote filesexternal section - now provided by the app itself
- code cleanup

* Fix PHPDoc on public interface

* Fix sharing settings loading in admin panel

* Add some padding to help with UI

* Add active navigation styling

* Fix navigation to admin and add @deprecated label to old methods

* Fix documentation link styling on panels and personal sort order

* Fix logging and cron panels...
parent 33d92535
......@@ -30,5 +30,4 @@ $app = new Application([], $encryptionSystemReady);
if ($encryptionSystemReady) {
$app->registerEncryptionModule();
$app->registerHooks();
$app->registerSettings();
}
......@@ -31,4 +31,8 @@
<command>OCA\Encryption\Command\EnableMasterKey</command>
<command>OCA\Encryption\Command\MigrateKeys</command>
</commands>
<settings>
<admin>OCA\Encryption\Panels\Admin</admin>
<personal>OCA\Encryption\Panels\Personal</personal>
</settings>
</info>
......@@ -266,9 +266,4 @@ class Application extends \OCP\AppFramework\App {
}
public function registerSettings() {
// Register settings scripts
App::registerAdmin('encryption', 'settings/settings-admin');
App::registerPersonal('encryption', 'settings/settings-personal');
}
}
<?php
namespace OCA\Encryption\Panels;
use OCP\IL10N;
use OCP\Settings\ISettings;
use OCP\Template;
use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\Util;
use OC\Files\View;
use OCP\IConfig;
use OCA\Encryption\Session;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\ISession;
use OCP\IUserSession;
class Admin implements ISettings {
/** @var IConfig */
protected $config;
/** @var ILogger */
protected $logger;
/** @var IUserSession */
protected $userSession;
/** @var IUserManager */
protected $userManager;
/** @var ISession */
protected $session;
/** @var IL10N */
protected $l;
public function __construct(IConfig $config,
ILogger $logger,
IUserSession $userSession,
IUserManager $userManager,
ISession $session,
IL10N $l) {
$this->config = $config;
$this->logger = $logger;
$this->userSession = $userSession;
$this->userManager = $userManager;
$this->session = $session;
$this->l = $l;
}
public function getPriority() {
return 0;
}
public function getSectionID() {
return 'encryption';
}
public function getPanel() {
$tmpl = new Template('encryption', 'settings-admin');
$crypt = new Crypt(
$this->logger,
$this->userSession,
$this->config,
$this->l);
$util = new Util(
new View(),
$crypt,
$this->logger,
$this->userSession,
$this->config,
$this->userManager
);
// Check if an adminRecovery account is enabled for recovering files after lost pwd
$recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
$session = new Session($this->session);
$encryptHomeStorage = $util->shouldEncryptHomeStorage();
$tmpl->assign('recoveryEnabled', $recoveryAdminEnabled);
$tmpl->assign('initStatus', $session->getStatus());
$tmpl->assign('encryptHomeStorage', $encryptHomeStorage);
$tmpl->assign('masterKeyEnabled', $util->isMasterKeyEnabled());
return $tmpl;
}
}
\ No newline at end of file
<?php
namespace OCA\Encryption\Panels;
use OCP\Encryption\Keys\IStorage;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Settings\ISettings;
use OCP\Template;
class Personal implements ISettings {
/** @var ILogger */
protected $logger;
/** @var IUserSession */
protected $userSession;
/** @var IConfig */
protected $config;
/** @var IL10N */
protected $l;
/** @varIUserManager */
protected $userManager;
/** @var ISession */
protected $session;
/** @var IStorage */
protected $encKeyStorage;
public function __construct(
ILogger $logger,
IUserSession $userSession,
IConfig $config,
IL10N $l,
IUserManager $userManager,
ISession $session,
IStorage $encKeyStorage) {
$this->logger = $logger;
$this->userSession = $userSession;
$this->config = $config;
$this->l = $l;
$this->userManager = $userManager;
$this->session = $session;
$this->encKeyStorage = $encKeyStorage;
}
public function getPriority() {
return 0;
}
public function getSectionID() {
return 'encryption';
}
public function getPanel() {
$session = new \OCA\Encryption\Session($this->session);
$template = new Template('encryption', 'settings-personal');
$crypt = new \OCA\Encryption\Crypto\Crypt(
$this->logger,
$this->userSession,
$this->config,
$this->l);
$util = new \OCA\Encryption\Util(
new \OC\Files\View(),
$crypt,
$this->logger,
$this->userSession,
$this->config,
$this->userManager);
$user = $this->userSession->getUser()->getUID();
$privateKeySet = $session->isPrivateKeySet();
// did we tried to initialize the keys for this session?
$initialized = $session->getStatus();
$recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled');
$recoveryEnabledForUser = $util->isRecoveryEnabledForUser($user);
if ($recoveryAdminEnabled || !$privateKeySet) {
$template->assign('recoveryEnabled', $recoveryAdminEnabled);
$template->assign('recoveryEnabledForUser', $recoveryEnabledForUser);
$template->assign('privateKeySet', $privateKeySet);
$template->assign('initialized', $initialized);
return $template;
}
return null;
}
}
\ No newline at end of file
<?php
/**
* @author Björn Schießle <bjoern@schiessle.org>
* @author Clark Tomlinson <fallen013@gmail.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @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/>
*
*/
$session = new \OCA\Encryption\Session(\OC::$server->getSession());
$userSession = \OC::$server->getUserSession();
$template = new OCP\Template('encryption', 'settings-personal');
$crypt = new \OCA\Encryption\Crypto\Crypt(
\OC::$server->getLogger(),
$userSession,
\OC::$server->getConfig(),
\OC::$server->getL10N('encryption'));
$util = new \OCA\Encryption\Util(
new \OC\Files\View(),
$crypt,
\OC::$server->getLogger(),
$userSession,
\OC::$server->getConfig(),
\OC::$server->getUserManager());
$keyManager = new \OCA\Encryption\KeyManager(
\OC::$server->getEncryptionKeyStorage(),
$crypt,
\OC::$server->getConfig(),
$userSession,
$session,
\OC::$server->getLogger(), $util);
$user = $userSession->getUser()->getUID();
$view = new \OC\Files\View('/');
$privateKeySet = $session->isPrivateKeySet();
// did we tried to initialize the keys for this session?
$initialized = $session->getStatus();
$recoveryAdminEnabled = \OC::$server->getConfig()->getAppValue('encryption', 'recoveryAdminEnabled');
$recoveryEnabledForUser = $util->isRecoveryEnabledForUser($user);
$result = false;
if ($recoveryAdminEnabled || !$privateKeySet) {
$template->assign('recoveryEnabled', $recoveryAdminEnabled);
$template->assign('recoveryEnabledForUser', $recoveryEnabledForUser);
$template->assign('privateKeySet', $privateKeySet);
$template->assign('initialized', $initialized);
$result = $template->fetchPage();
}
return $result;
......@@ -2,10 +2,10 @@
/** @var array $_ */
/** @var \OCP\IL10N $l */
script('encryption', 'settings-admin');
script('core', 'multiselect');
style('encryption', 'settings-admin');
?>
<form id="ocDefaultEncryptionModule" class="sub-section">
<h2 class="app-name"><?php p($l->t('Encryption')); ?></h2>
<?php if(!$_["initStatus"]): ?>
<?php p($l->t("Encryption App is enabled but your keys are not initialized, please log-out and log-in again")); ?>
<?php else: ?>
......
......@@ -2,10 +2,9 @@
/** @var array $_ */
/** @var \OCP\IL10N $l */
script('encryption', 'settings-personal');
script('core', 'multiselect');
?>
<form id="ocDefaultEncryptionModule" class="section">
<h2><?php p($l->t('ownCloud basic encryption module')); ?></h2>
<h2 class="app-name"><?php p($l->t('ownCloud basic encryption module')); ?></h2>
<?php if ($_["initialized"] === \OCA\Encryption\Session::NOT_INITIALIZED ): ?>
......
<?php
/**
* @author Tom Needham
* @copyright 2016 Tom Needham tom@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Encryption\Tests\Panels;
use OCA\Encryption\Panels\Admin;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
/**
* @package OCA\Encryption\Tests\Panels
*/
class AdminTest extends \Test\TestCase {
/** @var Admin */
private $panel;
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/** @var IUserSession */
private $userSession;
/** @var IUserManager */
private $userManager;
/** @var ISession */
private $session;
/** @var IL10N */
private $l;
public function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)->getMock();
$this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
$this->session = $this->getMockBuilder(ISession::class)->getMock();
$this->l = $this->getMockBuilder(IL10N::class)->getMock();
$this->panel = new Admin(
$this->config,
$this->logger,
$this->userSession,
$this->userManager,
$this->session,
$this->l);
}
public function testGetSection() {
$this->assertEquals('encryption', $this->panel->getSectionID());
}
public function testGetPriority() {
$this->assertTrue(is_integer($this->panel->getPriority()));
}
public function testGetPanel() {
$templateHtml = $this->panel->getPanel()->fetchPage();
$this->assertContains('<form id="ocDefaultEncryptionModule" class="sub-section">', $templateHtml);
}
}
<?php
/**
* @author Tom Needham
* @copyright 2016 Tom Needham tom@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Encryption\Tests\Panels;
use OCA\Encryption\Panels\Personal;
use OCP\Encryption\Keys\IStorage;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
/**
* @package OCA\Encryption\Tests\Panels
*/
class PersonalTest extends \Test\TestCase {
/** @var Personal */
private $panel;
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/** @var IUserSession */
private $userSession;
/** @var IUserManager */
private $userManager;
/** @var ISession */
private $session;
/** @var IL10N */
private $l;
/** @var IStorage */
private $encKeyStorage;
public function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)->getMock();
$this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
$this->session = $this->getMockBuilder(ISession::class)->getMock();
$this->l = $this->getMockBuilder(IL10N::class)->getMock();
$this->encKeyStorage = $this->getMockBuilder(IStorage::class)->getMock();
$this->panel = new Personal(
$this->logger,
$this->userSession,
$this->config,
$this->l,
$this->userManager,
$this->session,
$this->encKeyStorage);
}
public function testGetSection() {
$this->assertEquals('encryption', $this->panel->getSectionID());
}
public function testGetPriority() {
$this->assertTrue(is_integer($this->panel->getPriority()));
}
public function testGetPanel() {
$mockUser = $this->getMockBuilder(IUser::class)->getMock();
$mockUser->expects($this->once())->method('getUID')->willReturn('testUser');
$this->userSession->expects($this->once())->method('getUser')->willReturn($mockUser);
$templateHtml = $this->panel->getPanel()->fetchPage();
$this->assertContains('<form id="ocDefaultEncryptionModule" class="section">', $templateHtml);
}
}
......@@ -26,8 +26,6 @@ use OCA\FederatedFileSharing\Notifier;
$l = \OC::$server->getL10N('files_sharing');
$app->registerSettings();
$manager = \OC::$server->getNotificationManager();
$manager->registerNotifier(function() {
return new Notifier(
......
......@@ -11,4 +11,8 @@
<dependencies>
<owncloud min-version="10.0" max-version="10.0" />
</dependencies>
<settings>
<admin>OCA\FederatedFileSharing\AdminPanel</admin>
<personal>OCA\FederatedFileSharing\PersonalPanel</personal>
</settings>
</info>
<?php
namespace OCA\FederatedFileSharing;
use OCP\Settings\ISettings;
use OCP\Template;
class AdminPanel implements ISettings {
/** @var FederatedShareProvider */
protected $shareProvider;
/**
* AdminPanel constructor.
*
* @param FederatedShareProvider $shareProvider
*/
public function __construct(FederatedShareProvider $shareProvider) {
$this->shareProvider = $shareProvider;
}
public function getPriority() {
return 95;
}
public function getSectionID() {
return 'sharing';
}
public function getPanel() {
$tmpl = new Template('federatedfilesharing', 'settings-admin');
$tmpl->assign('outgoingServer2serverShareEnabled', $this->shareProvider->isOutgoingServer2serverShareEnabled());
$tmpl->assign('incomingServer2serverShareEnabled', $this->shareProvider->isIncomingServer2serverShareEnabled());
return $tmpl;
}
}
......@@ -19,10 +19,8 @@
*
*/
namespace OCA\FederatedFileSharing\AppInfo;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\App;
......@@ -31,14 +29,6 @@ class Application extends App {
/** @var FederatedShareProvider */
protected $federatedShareProvider;
/**
* register personal and admin settings page
*/
public function registerSettings() {
\OCP\App::registerAdmin('federatedfilesharing', 'settings-admin');
\OCP\App::registerPersonal('federatedfilesharing', 'settings-personal');
}
/**
* get instance of federated share provider
*
......
<?php
namespace OCA\FederatedFileSharing;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Settings\ISettings;
use OCP\Template;
class PersonalPanel implements ISettings {
/** @var IL10N */
protected $l;
/** @var IUserSession */
protected $userSession;
/** @var IURLGenerator */
protected $urlGenerator;
/** @var FederatedShareProvider */
protected $shareProvider;
/** @var IRequest */
protected $request;
public function __construct(IL10N $l,
IUserSession $userSession,
IURLGenerator $urlGenerator,
FederatedShareProvider $shareProvider,
IRequest $request) {
$this->l = $l;
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
$this->shareProvider = $shareProvider;
$this->request = $request;
}
public function getPriority() {
return 0;
}
public function getSectionID() {
return 'general';
}
public function getPanel() {
$isIE8 = false;
preg_match('/MSIE (.*?);/', $this->request->getHeader('User-Agent'), $matches);
if (count($matches) > 0 && $matches[1] <= 9) {
$isIE8 = true;
}
$cloudID = $this->userSession->getUser()->getCloudId();
$url = 'https://owncloud.org/federation#' . $cloudID;
$ownCloudLogoPath = $this->urlGenerator->imagePath('core', 'logo-icon.svg');
$tmpl = new Template('federatedfilesharing', 'settings-personal');
$tmpl->assign('outgoingServer2serverShareEnabled', $this->shareProvider->isOutgoingServer2serverShareEnabled());
$tmpl->assign('message_with_URL', $this->l->t('Share with me through my #ownCloud Federated Cloud ID, see %s', [$url]));
$tmpl->assign('message_without_URL', $this->l->t('Share with me through my #ownCloud Federated Cloud ID', [$cloudID]));
$tmpl->assign('owncloud_logo_path', $ownCloudLogoPath);
$tmpl->assign('reference', $url);
$tmpl->assign('cloudId', $cloudID);
$tmpl->assign('showShareIT', !$isIE8);
$tmpl->assign('urlGenerator', $this->urlGenerator);
return $tmpl;
}