diff --git a/apps/encryption/appinfo/info.xml b/apps/encryption/appinfo/info.xml
index 83f4107384..539f9f116d 100644
--- a/apps/encryption/appinfo/info.xml
+++ b/apps/encryption/appinfo/info.xml
@@ -19,7 +19,7 @@
admin-encryption
false
- 1.4.0
+ 1.4.1
@@ -27,5 +27,7 @@
openssl
-
+
+ OCA\Encryption\Settings\Admin
+
diff --git a/apps/encryption/lib/AppInfo/Application.php b/apps/encryption/lib/AppInfo/Application.php
index bba522fbc8..a43646d86d 100644
--- a/apps/encryption/lib/AppInfo/Application.php
+++ b/apps/encryption/lib/AppInfo/Application.php
@@ -269,7 +269,6 @@ class Application extends \OCP\AppFramework\App {
public function registerSettings() {
// Register settings scripts
- App::registerAdmin('encryption', 'settings/settings-admin');
App::registerPersonal('encryption', 'settings/settings-personal');
}
}
diff --git a/apps/encryption/lib/Settings/Admin.php b/apps/encryption/lib/Settings/Admin.php
new file mode 100644
index 0000000000..71a365caee
--- /dev/null
+++ b/apps/encryption/lib/Settings/Admin.php
@@ -0,0 +1,127 @@
+
+ *
+ * @author Arthur Schiwon
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see .
+ *
+ */
+
+namespace OCA\Encryption\Settings;
+
+use OC\Files\View;
+use OCA\Encryption\Crypto\Crypt;
+use OCA\Encryption\Session;
+use OCA\Encryption\Util;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IL10N;
+use OCP\ILogger;
+use OCP\ISession;
+use OCP\IUserManager;
+use OCP\IUserSession;
+use OCP\Settings\IAdmin;
+use OCP\IConfig;
+
+class Admin implements IAdmin {
+
+ /** @var IL10N */
+ private $l;
+
+ /** @var ILogger */
+ private $logger;
+
+ /** @var IUserSession */
+ private $userSession;
+
+ /** @var IConfig */
+ private $config;
+
+ /** @var IUserManager */
+ private $userManager;
+
+ /** @var ISession */
+ private $session;
+
+ public function __construct(
+ IL10N $l,
+ ILogger $logger,
+ IUserSession $userSession,
+ IConfig $config,
+ IUserManager $userManager,
+ ISession $session
+ ) {
+ $this->l = $l;
+ $this->logger = $logger;
+ $this->userSession = $userSession;
+ $this->config = $config;
+ $this->userManager = $userManager;
+ $this->session = $session;
+ }
+
+ /**
+ * @return TemplateResponse
+ */
+ public function getForm() {
+ $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();
+
+ $parameters = [
+ 'recoveryEnabled' => $recoveryAdminEnabled,
+ 'initStatus' => $session->getStatus(),
+ 'encryptHomeStorage' => $encryptHomeStorage,
+ 'masterKeyEnabled' => $util->isMasterKeyEnabled(),
+ ];
+
+ return new TemplateResponse('encryption', 'settings-admin', $parameters, '');
+ }
+
+ /**
+ * @return string the section ID, e.g. 'sharing'
+ */
+ public function getSection() {
+ return 'encryption';
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the admin section. The forms are arranged in ascending order of the
+ * priority values. It is required to return a value between 0 and 100.
+ *
+ * E.g.: 70
+ */
+ public function getPriority() {
+ return 5;
+ }
+
+}
diff --git a/apps/encryption/settings/settings-admin.php b/apps/encryption/settings/settings-admin.php
deleted file mode 100644
index a424ea0387..0000000000
--- a/apps/encryption/settings/settings-admin.php
+++ /dev/null
@@ -1,53 +0,0 @@
-
- * @author Clark Tomlinson
- * @author Lukas Reschke
- * @author Thomas Müller
- *
- * @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
- *
- */
-
-$tmpl = new OCP\Template('encryption', 'settings-admin');
-
-$crypt = new \OCA\Encryption\Crypto\Crypt(
- \OC::$server->getLogger(),
- \OC::$server->getUserSession(),
- \OC::$server->getConfig(),
- \OC::$server->getL10N('encryption'));
-
-$util = new \OCA\Encryption\Util(
- new \OC\Files\View(),
- $crypt,
- \OC::$server->getLogger(),
- \OC::$server->getUserSession(),
- \OC::$server->getConfig(),
- \OC::$server->getUserManager());
-
-// Check if an adminRecovery account is enabled for recovering files after lost pwd
-$recoveryAdminEnabled = \OC::$server->getConfig()->getAppValue('encryption', 'recoveryAdminEnabled', '0');
-$session = new \OCA\Encryption\Session(\OC::$server->getSession());
-
-$encryptHomeStorage = $util->shouldEncryptHomeStorage();
-
-$tmpl->assign('recoveryEnabled', $recoveryAdminEnabled);
-$tmpl->assign('initStatus', $session->getStatus());
-$tmpl->assign('encryptHomeStorage', $encryptHomeStorage);
-$tmpl->assign('masterKeyEnabled', $util->isMasterKeyEnabled());
-
-return $tmpl->fetchPage();
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index b7d02ddd34..fa762003c1 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -104,8 +104,10 @@ class Manager implements IManager {
);
return;
}
- if(!$this->hasAdminSection($section)) {
+ if(!$this->hasAdminSection(get_class($section))) {
$this->addAdminSection($section);
+ } else {
+ $this->updateAdminSection($section);
}
}
@@ -134,20 +136,64 @@ class Manager implements IManager {
$query->execute();
}
- private function hasAdminSection(ISection $section) {
- return $this->has(self::TABLE_ADMIN_SECTIONS, 'id', $section->getID());
+ private function updateAdminSettings(IAdmin $settings) {
+ $this->update(
+ self::TABLE_ADMIN_SETTINGS,
+ 'class',
+ get_class($settings),
+ [
+ 'section' => $settings->getSection(),
+ 'priority' => $settings->getPriority(),
+ ]
+ );
}
- private function hasAdminSettings($pageClass) {
- return $this->has(self::TABLE_ADMIN_SETTINGS, 'class', $pageClass);
+ private function updateAdminSection(ISection $section) {
+ $this->update(
+ self::TABLE_ADMIN_SECTIONS,
+ 'class',
+ get_class($section),
+ [
+ 'id' => $section->getID(),
+ 'priority' => $section->getPriority(),
+ ]
+ );
}
-
- private function has($table, $idCol, $id) {
+ private function update($table, $idCol, $id, $values) {
$query = $this->dbc->getQueryBuilder();
- $query->select($idCol)
+ $query->update($table);
+ foreach($values as $key => $value) {
+ $query->set($key, $query->createNamedParameter($value));
+ }
+ $query
+ ->where($query->expr()->eq($idCol, $query->createParameter($idCol)))
+ ->setParameter($idCol, $id)
+ ->execute();
+ }
+
+ /**
+ * @param string $className
+ * @return bool
+ */
+ private function hasAdminSection($className) {
+ return $this->has(self::TABLE_ADMIN_SECTIONS, $className);
+ }
+
+ /**
+ * @param string $className
+ * @return bool
+ */
+ private function hasAdminSettings($className) {
+ return $this->has(self::TABLE_ADMIN_SETTINGS, $className);
+ }
+
+
+ private function has($table, $className) {
+ $query = $this->dbc->getQueryBuilder();
+ $query->select('class')
->from($table)
- ->where($query->expr()->eq($idCol, $query->createNamedParameter($id)))
+ ->where($query->expr()->eq('class', $query->createNamedParameter($className)))
->setMaxResults(1);
$result = $query->execute();
@@ -164,6 +210,7 @@ class Manager implements IManager {
}
try {
+ /** @var IAdmin $settings */
$settings = $this->query($settingsClassName);
} catch (QueryException $e) {
// cancel
@@ -177,8 +224,10 @@ class Manager implements IManager {
);
return;
}
- if(!$this->hasAdminSettings($settings)) {
+ if(!$this->hasAdminSettings(get_class($settings))) {
$this->addAdminSettings($settings);
+ } else {
+ $this->updateAdminSettings($settings);
}
}
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index 802c4b908b..4144f3f6cf 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -345,6 +345,12 @@ class OC_App {
} else {
$appManager->enableApp($app);
}
+
+ $info = self::getAppInfo($app);
+ if(isset($info['settings']) && is_array($info['settings'])) {
+ self::loadApp($app, false);
+ \OC::$server->getSettingsManager()->setupSettings($info['settings']);
+ }
}
/**