summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/appinfo/database.xml2
-rw-r--r--apps/files_external/appinfo/info.xml11
-rw-r--r--apps/files_external/css/settings.css13
-rw-r--r--apps/files_external/js/settings.js5
-rw-r--r--apps/files_external/l10n/fr.js3
-rw-r--r--apps/files_external/l10n/fr.json3
-rw-r--r--apps/files_external/lib/AppInfo/Application.php4
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php2
-rw-r--r--apps/files_external/lib/Service/DBConfigService.php2
-rw-r--r--apps/files_external/lib/Settings/Admin.php96
-rw-r--r--apps/files_external/lib/Settings/Section.php67
-rw-r--r--apps/files_external/lib/config.php12
-rw-r--r--apps/files_external/settings.php48
-rw-r--r--apps/files_external/templates/settings.php45
-rw-r--r--apps/files_external/tests/Settings/AdminTest.php109
-rw-r--r--apps/files_external/tests/Settings/SectionTest.php62
16 files changed, 397 insertions, 87 deletions
diff --git a/apps/files_external/appinfo/database.xml b/apps/files_external/appinfo/database.xml
index 54ee642ead6..e39144931a7 100644
--- a/apps/files_external/appinfo/database.xml
+++ b/apps/files_external/appinfo/database.xml
@@ -144,7 +144,7 @@
<field>
<name>value</name>
<type>text</type>
- <notnull>true</notnull>
+ <notnull>false</notnull>
<length>4096</length>
</field>
diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml
index 43f06d60843..f99ef3b6c49 100644
--- a/apps/files_external/appinfo/info.xml
+++ b/apps/files_external/appinfo/info.xml
@@ -3,9 +3,9 @@
<id>files_external</id>
<name>External storage support</name>
<description>
- This application enables administrators to configure connections to external storage providers, such as FTP servers, S3 or SWIFT object stores, Google Drive, Dropbox, other ownCloud servers, WebDAV servers, and more. Administrators can choose which types of storage to enable and can mount these storage locations for a user, a group, or the entire system. Users will see a new folder appear in their root ownCloud directory, which they can access and use like any other ownCloud folder. External Storage also allows users to share files stored in these external locations. In these cases, the credentials for the owner of the file are used when the recipient requests the file from external storage, thereby ensuring that the recipient can access the shared file.
+ This application enables administrators to configure connections to external storage providers, such as FTP servers, S3 or SWIFT object stores, Google Drive, Dropbox, other ownCloud servers, WebDAV servers, and more. Administrators can choose which types of storage to enable and can mount these storage locations for a user, a group, or the entire system. Users will see a new folder appear in their root ownCloud directory, which they can access and use like any other ownCloud folder. External storage also allows users to share files stored in these external locations. In these cases, the credentials for the owner of the file are used when the recipient requests the file from external storage, thereby ensuring that the recipient can access the shared file.
- External Storage can be configured using the GUI or at the command line. This second option provides the advanced user with more flexibility for configuring bulk external storage mounts and setting mount priorities. More information is available in the External Storage GUI documentation and the External Storage Configuration File documentation.
+ External storage can be configured using the GUI or at the command line. This second option provides the advanced user with more flexibility for configuring bulk external storage mounts and setting mount priorities. More information is available in the external storage GUI documentation and the external storage Configuration File documentation.
</description>
<licence>AGPL</licence>
<author>Robin Appelman, Michael Gapczynski, Vincent Petry</author>
@@ -13,7 +13,7 @@
<admin>admin-external-storage</admin>
</documentation>
<rememberlogin>false</rememberlogin>
- <version>1.1.0</version>
+ <version>1.1.2</version>
<types>
<filesystem/>
</types>
@@ -24,4 +24,9 @@
<dependencies>
<owncloud min-version="9.2" max-version="9.2" />
</dependencies>
+
+ <settings>
+ <admin>OCA\Files_External\Settings\Admin</admin>
+ <admin-section>OCA\Files_External\Settings\Section</admin-section>
+ </settings>
</info>
diff --git a/apps/files_external/css/settings.css b/apps/files_external/css/settings.css
index 4d5dc69a4e7..38e497eebe6 100644
--- a/apps/files_external/css/settings.css
+++ b/apps/files_external/css/settings.css
@@ -1,3 +1,16 @@
+#global_credentials {
+ padding: 0 30px;
+ margin-bottom: 0px;
+}
+
+#files_external {
+ margin-bottom: 0px;
+}
+
+#externalStorage {
+ margin: 15px 0 20px 0;
+}
+
#externalStorage td.status {
/* overwrite conflicting core styles */
display: table-cell;
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index fc6edefc648..da3e2397b7e 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -945,6 +945,11 @@ MountConfigListView.prototype = _.extend({
$tr.find('.configuration').text(t('files_external', 'Admin defined'));
}
});
+ var mainForm = $('#files_external');
+ if (result.length === 0 && mainForm.attr('data-can-create') === 'false') {
+ mainForm.hide();
+ $('a[href="#external-storage"]').parent().hide();
+ }
onCompletion.resolve();
}
});
diff --git a/apps/files_external/l10n/fr.js b/apps/files_external/l10n/fr.js
index 486431de5e0..6454d005102 100644
--- a/apps/files_external/l10n/fr.js
+++ b/apps/files_external/l10n/fr.js
@@ -126,6 +126,7 @@ OC.L10N.register(
"Advanced settings" : "Paramètres avancés",
"Delete" : "Supprimer",
"Allow users to mount external storage" : "Autoriser les utilisateurs à monter des espaces de stockage externes",
- "Allow users to mount the following external storage" : "Autoriser les utilisateurs à monter les stockages externes suivants"
+ "Allow users to mount the following external storage" : "Autoriser les utilisateurs à monter les stockages externes suivants",
+ "Access granted" : "Accès autorisé"
},
"nplurals=2; plural=(n > 1);");
diff --git a/apps/files_external/l10n/fr.json b/apps/files_external/l10n/fr.json
index 0ab8b413928..3268f6a47f6 100644
--- a/apps/files_external/l10n/fr.json
+++ b/apps/files_external/l10n/fr.json
@@ -124,6 +124,7 @@
"Advanced settings" : "Paramètres avancés",
"Delete" : "Supprimer",
"Allow users to mount external storage" : "Autoriser les utilisateurs à monter des espaces de stockage externes",
- "Allow users to mount the following external storage" : "Autoriser les utilisateurs à monter les stockages externes suivants"
+ "Allow users to mount the following external storage" : "Autoriser les utilisateurs à monter les stockages externes suivants",
+ "Access granted" : "Accès autorisé"
},"pluralForm" :"nplurals=2; plural=(n > 1);"
} \ No newline at end of file
diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php
index a32a3a26c7f..06c163419f0 100644
--- a/apps/files_external/lib/AppInfo/Application.php
+++ b/apps/files_external/lib/AppInfo/Application.php
@@ -68,10 +68,6 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
* Register settings templates
*/
public function registerSettings() {
- $container = $this->getContainer();
- $backendService = $container->query('OCA\\Files_External\\Service\\BackendService');
-
- \OCP\App::registerAdmin('files_external', 'settings');
\OCP\App::registerPersonal('files_external', 'personal');
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
index 502024be4f2..c0ece745aa4 100644
--- a/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
+++ b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
@@ -48,7 +48,7 @@ class GlobalAuth extends AuthMechanism {
->setIdentifier('password::global')
->setVisibility(BackendService::VISIBILITY_DEFAULT)
->setScheme(self::SCHEME_PASSWORD)
- ->setText($l->t('Global Credentials'));
+ ->setText($l->t('Global credentials'));
}
public function getAuth($uid) {
diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php
index a94b73772e7..61cca9a0224 100644
--- a/apps/files_external/lib/Service/DBConfigService.php
+++ b/apps/files_external/lib/Service/DBConfigService.php
@@ -208,7 +208,7 @@ class DBConfigService {
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
]);
$query->execute();
- return (int)$this->connection->lastInsertId('external_mounts');
+ return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
}
/**
diff --git a/apps/files_external/lib/Settings/Admin.php b/apps/files_external/lib/Settings/Admin.php
new file mode 100644
index 00000000000..54711443f89
--- /dev/null
+++ b/apps/files_external/lib/Settings/Admin.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_External\Settings;
+
+use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
+use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\GlobalStoragesService;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Encryption\IManager;
+use OCP\Settings\ISettings;
+
+class Admin implements ISettings {
+
+ /** @var IManager */
+ private $encryptionManager;
+
+ /** @var GlobalStoragesService */
+ private $globalStoragesService;
+
+ /** @var BackendService */
+ private $backendService;
+
+ /** @var GlobalAuth */
+ private $globalAuth;
+
+ public function __construct(
+ IManager $encryptionManager,
+ GlobalStoragesService $globalStoragesService,
+ BackendService $backendService,
+ GlobalAuth $globalAuth
+ ) {
+ $this->encryptionManager = $encryptionManager;
+ $this->globalStoragesService = $globalStoragesService;
+ $this->backendService = $backendService;
+ $this->globalAuth = $globalAuth;
+ }
+
+ /**
+ * @return TemplateResponse
+ */
+ public function getForm() {
+ $parameters = [
+ 'encryptionEnabled' => $this->encryptionManager->isEnabled(),
+ 'visibilityType' => BackendService::VISIBILITY_ADMIN,
+ 'storages' => $this->globalStoragesService->getStorages(),
+ 'backends' => $this->backendService->getAvailableBackends(),
+ 'authMechanisms' => $this->backendService->getAuthMechanisms(),
+ 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
+ 'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
+ 'globalCredentials' => $this->globalAuth->getAuth(''),
+ 'globalCredentialsUid' => '',
+ ];
+
+ return new TemplateResponse('files_external', 'settings', $parameters, '');
+ }
+
+ /**
+ * @return string the section ID, e.g. 'sharing'
+ */
+ public function getSection() {
+ return 'externalstorages';
+ }
+
+ /**
+ * @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 40;
+ }
+
+}
diff --git a/apps/files_external/lib/Settings/Section.php b/apps/files_external/lib/Settings/Section.php
new file mode 100644
index 00000000000..4b4bac93d29
--- /dev/null
+++ b/apps/files_external/lib/Settings/Section.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_External\Settings;
+
+use OCP\IL10N;
+use OCP\Settings\ISection;
+
+class Section implements ISection {
+ /** @var IL10N */
+ private $l;
+
+ public function __construct(IL10N $l) {
+ $this->l = $l;
+ }
+
+ /**
+ * returns the ID of the section. It is supposed to be a lower case string,
+ * e.g. 'ldap'
+ *
+ * @returns string
+ */
+ public function getID() {
+ return 'externalstorages';
+ }
+
+ /**
+ * returns the translated name as it should be displayed, e.g. 'LDAP / AD
+ * integration'. Use the L10N service to translate it.
+ *
+ * @return string
+ */
+ public function getName() {
+ return $this->l->t('External storages');
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the settings navigation. The sections are arranged in ascending order of
+ * the priority values. It is required to return a value between 0 and 99.
+ *
+ * E.g.: 70
+ */
+ public function getPriority() {
+ return 10;
+ }
+}
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index cd3b4d9f3cb..7a10d4bbc24 100644
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -285,7 +285,7 @@ class OC_Mount_Config {
foreach ($backends as $backend) {
foreach ($backend->checkDependencies() as $dependency) {
if ($message = $dependency->getMessage()) {
- $message .= '<br />' . $l->t('<b>Note:</b> ') . $message;
+ $message .= '<p>' . $message . '</p>';
} else {
$dependencyGroups[$dependency->getDependency()][] = $backend;
}
@@ -294,9 +294,9 @@ class OC_Mount_Config {
foreach ($dependencyGroups as $module => $dependants) {
$backends = implode(', ', array_map(function($backend) {
- return '<i>' . $backend->getText() . '</i>';
+ return '"' . $backend->getText() . '"';
}, $dependants));
- $message .= '<br />' . OC_Mount_Config::getSingleDependencyMessage($l, $module, $backends);
+ $message .= '<p>' . OC_Mount_Config::getSingleDependencyMessage($l, $module, $backends) . '</p>';
}
return $message;
@@ -313,11 +313,11 @@ class OC_Mount_Config {
private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
switch (strtolower($module)) {
case 'curl':
- return (string)$l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
+ return (string)$l->t('The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
case 'ftp':
- return (string)$l->t('<b>Note:</b> The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
+ return (string)$l->t('The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
default:
- return (string)$l->t('<b>Note:</b> "%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', array($module, $backend));
+ return (string)$l->t('"%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', array($module, $backend));
}
}
diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php
deleted file mode 100644
index cb9ee5ccde0..00000000000
--- a/apps/files_external/settings.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- *
- * @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/>
- *
- */
-
-use \OCA\Files_External\Service\BackendService;
-
-// we must use the same container
-$appContainer = \OC_Mount_Config::$app->getContainer();
-$backendService = $appContainer->query('OCA\Files_External\Service\BackendService');
-$globalStoragesService = $appContainer->query('OCA\Files_External\Service\GlobalStoragesService');
-$globalAuth = $appContainer->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth');
-
-\OC_Util::addVendorScript('select2/select2');
-\OC_Util::addVendorStyle('select2/select2');
-
-$tmpl = new OCP\Template('files_external', 'settings');
-$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
-$tmpl->assign('visibilityType', BackendService::VISIBILITY_ADMIN);
-$tmpl->assign('storages', $globalStoragesService->getStorages());
-$tmpl->assign('backends', $backendService->getAvailableBackends());
-$tmpl->assign('authMechanisms', $backendService->getAuthMechanisms());
-$tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends()));
-$tmpl->assign('allowUserMounting', $backendService->isUserMountingAllowed());
-$tmpl->assign('globalCredentials', $globalAuth->getAuth(''));
-$tmpl->assign('globalCredentialsUid', '');
-return $tmpl->fetchPage();
diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php
index 6fb2a018547..53d2412425c 100644
--- a/apps/files_external/templates/settings.php
+++ b/apps/files_external/templates/settings.php
@@ -4,6 +4,8 @@
use \OCA\Files_External\Lib\DefinitionParameter;
use \OCA\Files_External\Service\BackendService;
+ $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting'];
+
$l->t("Enable encryption");
$l->t("Enable previews");
$l->t("Enable sharing");
@@ -84,25 +86,10 @@
}
}
?>
-<form autocomplete="false" class="section" action="#"
- id="global_credentials">
- <h2><?php p($l->t('External Storage')); ?></h2>
- <p><?php p($l->t('Global Credentials')); ?></p>
- <input type="text" name="username"
- autocomplete="false"
- value="<?php p($_['globalCredentials']['user']); ?>"
- placeholder="<?php p($l->t('Username')) ?>"/>
- <input type="password" name="password"
- autocomplete="false"
- value="<?php p($_['globalCredentials']['password']); ?>"
- placeholder="<?php p($l->t('Password')) ?>"/>
- <input type="hidden" name="uid"
- value="<?php p($_['globalCredentialsUid']); ?>"/>
- <input type="submit" value="<?php p($l->t('Save')) ?>"/>
-</form>
-<form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
- <?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?>
+<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
+ <h2><?php p($l->t('External storage')); ?></h2>
+ <?php if (isset($_['dependencies']) and ($_['dependencies']<>'') and $canCreateMounts) print_unescaped(''.$_['dependencies'].''); ?>
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
<thead>
<tr>
@@ -118,7 +105,7 @@
</thead>
<tbody>
<tr id="addMountPoint"
- <?php if ($_['visibilityType'] === BackendService::VISIBILITY_PERSONAL && $_['allowUserMounting'] === false): ?>
+ <?php if (!$canCreateMounts): ?>
style="display: none;"
<?php endif; ?>
>
@@ -173,10 +160,8 @@
</tr>
</tbody>
</table>
- <br />
<?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
- <br />
<input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox"
value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> />
<label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span>
@@ -200,3 +185,21 @@
</p>
<?php endif; ?>
</form>
+
+<?php if ($canCreateMounts): ?>
+ <form autocomplete="false" class="section" action="#"
+ id="global_credentials">
+ <p><?php p($l->t('Global credentials')); ?></p>
+ <input type="text" name="username"
+ autocomplete="false"
+ value="<?php p($_['globalCredentials']['user']); ?>"
+ placeholder="<?php p($l->t('Username')) ?>"/>
+ <input type="password" name="password"
+ autocomplete="false"
+ value="<?php p($_['globalCredentials']['password']); ?>"
+ placeholder="<?php p($l->t('Password')) ?>"/>
+ <input type="hidden" name="uid"
+ value="<?php p($_['globalCredentialsUid']); ?>"/>
+ <input type="submit" value="<?php p($l->t('Save')) ?>"/>
+ </form>
+<?php endif; ?>
diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php
new file mode 100644
index 00000000000..fdf9680e7c3
--- /dev/null
+++ b/apps/files_external/tests/Settings/AdminTest.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_External\Tests\Settings;
+
+use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
+use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\GlobalStoragesService;
+use OCA\Files_External\Settings\Admin;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Encryption\IManager;
+use Test\TestCase;
+
+class AdminTest extends TestCase {
+ /** @var Admin */
+ private $admin;
+ /** @var IManager */
+ private $encryptionManager;
+ /** @var GlobalStoragesService */
+ private $globalStoragesService;
+ /** @var BackendService */
+ private $backendService;
+ /** @var GlobalAuth */
+ private $globalAuth;
+
+ public function setUp() {
+ parent::setUp();
+ $this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock();
+ $this->globalStoragesService = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')->disableOriginalConstructor()->getMock();
+ $this->backendService = $this->getMockBuilder('\OCA\Files_External\Service\BackendService')->disableOriginalConstructor()->getMock();
+ $this->globalAuth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Password\GlobalAuth')->disableOriginalConstructor()->getMock();
+
+ $this->admin = new Admin(
+ $this->encryptionManager,
+ $this->globalStoragesService,
+ $this->backendService,
+ $this->globalAuth
+ );
+ }
+
+ public function testGetForm() {
+ $this->encryptionManager
+ ->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn(false);
+ $this->globalStoragesService
+ ->expects($this->once())
+ ->method('getStorages')
+ ->willReturn(['a', 'b', 'c']);
+ $this->backendService
+ ->expects($this->once())
+ ->method('getAvailableBackends')
+ ->willReturn(['d', 'e', 'f']);
+ $this->backendService
+ ->expects($this->once())
+ ->method('getAuthMechanisms')
+ ->willReturn(['g', 'h', 'i']);
+ $this->backendService
+ ->expects($this->once())
+ ->method('isUserMountingAllowed')
+ ->willReturn(true);
+ $this->globalAuth
+ ->expects($this->once())
+ ->method('getAuth')
+ ->with('')
+ ->willReturn('asdf:asdf');
+ $params = [
+ 'encryptionEnabled' => false,
+ 'visibilityType' => BackendService::VISIBILITY_ADMIN,
+ 'storages' => ['a', 'b', 'c'],
+ 'backends' => ['d', 'e', 'f'],
+ 'authMechanisms' => ['g', 'h', 'i'],
+ 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
+ 'allowUserMounting' => true,
+ 'globalCredentials' => 'asdf:asdf',
+ 'globalCredentialsUid' => '',
+ ];
+ $expected = new TemplateResponse('files_external', 'settings', $params, '');
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('externalstorages', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(40, $this->admin->getPriority());
+ }
+}
diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php
new file mode 100644
index 00000000000..b5dfb28b382
--- /dev/null
+++ b/apps/files_external/tests/Settings/SectionTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_External\Tests\Settings;
+
+use OCA\Files_External\Settings\Section;
+use OCP\IL10N;
+use Test\TestCase;
+
+class SectionTest extends TestCase {
+ /** @var IL10N */
+ private $l;
+ /** @var Section */
+ private $section;
+
+ public function setUp() {
+ parent::setUp();
+ $this->l = $this->getMockBuilder('\OCP\IL10N')->disableOriginalConstructor()->getMock();
+
+ $this->section = new Section(
+ $this->l
+ );
+ }
+
+ public function testGetID() {
+ $this->assertSame('externalstorages', $this->section->getID());
+ }
+
+ public function testGetName() {
+ $this->l
+ ->expects($this->once())
+ ->method('t')
+ ->with('External storages')
+ ->willReturn('External storages');
+
+ $this->assertSame('External storages', $this->section->getName());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(10, $this->section->getPriority());
+ }
+}