summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-03-30 10:06:05 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-03-30 10:06:05 +0200
commitcfe241a959d02fa856c0aca3cb7779b02cb3c943 (patch)
tree8ad1a40e73e9dc209b7208913192563163f60f74 /apps/files_sharing
parent00b2be11dda5934998636ae774d29a16bd6d1f10 (diff)
parentec31ee911779aeba9c81a95ceb5891bd93b97dd5 (diff)
downloadnextcloud-server-cfe241a959d02fa856c0aca3cb7779b02cb3c943.tar.gz
nextcloud-server-cfe241a959d02fa856c0aca3cb7779b02cb3c943.zip
Merge pull request #13964 from rullzer/capabilities
Add OCS sharing info to capabilities - take 2
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/appinfo/routes.php6
-rw-r--r--apps/files_sharing/lib/capabilities.php87
-rw-r--r--apps/files_sharing/tests/capabilities.php187
3 files changed, 280 insertions, 0 deletions
diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php
index 3e2df122fde..16f8727a510 100644
--- a/apps/files_sharing/appinfo/routes.php
+++ b/apps/files_sharing/appinfo/routes.php
@@ -79,3 +79,9 @@ $this->create('sharing_external_test_remote', '/testremote')
'/apps/files_sharing/api/v1/shares/{id}',
array('\OCA\Files_Sharing\API\Local', 'deleteShare'),
'files_sharing');
+
+// Register with the capabilities API
+\OC_API::register('get',
+ '/cloud/capabilities',
+ array('OCA\Files_Sharing\Capabilities', 'getCapabilities'),
+ 'files_sharing', \OC_API::USER_AUTH);
diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php
new file mode 100644
index 00000000000..ac6454c3433
--- /dev/null
+++ b/apps/files_sharing/lib/capabilities.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 OCA\Files_Sharing;
+
+use \OCP\IConfig;
+
+/**
+ * Class Capabilities
+ *
+ * @package OCA\Files_Sharing
+ */
+class Capabilities {
+
+ /** @var IConfig */
+ private $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
+ /**
+ * @return \OC_OCS_Result
+ */
+ public static function getCapabilities() {
+ $config = \OC::$server->getConfig();
+ $cap = new Capabilities($config);
+ return $cap->getCaps();
+ }
+
+
+ /**
+ * @return \OC_OCS_Result
+ */
+ public function getCaps() {
+ $res = [];
+
+ $public = [];
+ $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
+ if ($public['enabled']) {
+ $public['password'] = [];
+ $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes');
+
+ $public['expire_date'] = [];
+ $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes';
+ if ($public['expire_date']['enabled']) {
+ $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
+ $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes';
+ }
+
+ $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'yes') === 'yes';
+ }
+ $res["public"] = $public;
+
+ $res['user']['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'yes') === 'yes';
+
+ $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
+
+
+ return new \OC_OCS_Result([
+ 'capabilities' => [
+ 'files_sharing' => $res
+ ],
+ ]);
+ }
+
+}
diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php
new file mode 100644
index 00000000000..a7c487bf589
--- /dev/null
+++ b/apps/files_sharing/tests/capabilities.php
@@ -0,0 +1,187 @@
+<?php
+/**
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 OCA\Files_Sharing\Tests;
+
+use OCA\Files_Sharing\Capabilities;
+use OCA\Files_Sharing\Tests\TestCase;
+
+/**
+ * Class FilesSharingCapabilitiesTest
+ */
+class FilesSharingCapabilitiesTest extends \Test\TestCase {
+
+ /**
+ * Test for the general part in each return statement and assert.
+ * Strip of the general part on the way.
+ *
+ * @param string[] $data Capabilities
+ * @return string[]
+ */
+ private function getFilesSharingPart(array $data) {
+ $this->assertArrayHasKey('capabilities', $data);
+ $this->assertArrayHasKey('files_sharing', $data['capabilities']);
+ return $data['capabilities']['files_sharing'];
+ }
+
+ /**
+ * Create a mock config object and insert the values in $map tot the getAppValue
+ * function. Then obtain the capabilities and extract the first few
+ * levels in the array
+ *
+ * @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
+ * @return string[]
+ */
+ private function getResults(array $map) {
+ $stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
+ $stub->method('getAppValue')->will($this->returnValueMap($map));
+ $cap = new Capabilities($stub);
+ $result = $this->getFilesSharingPart($cap->getCaps()->getData());
+ return $result;
+ }
+
+ public function testNoLinkSharing() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertInternalType('array', $result['public']);
+ $this->assertFalse($result['public']['enabled']);
+ }
+
+ public function testOnlyLinkSharing() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertInternalType('array', $result['public']);
+ $this->assertTrue($result['public']['enabled']);
+ }
+
+ public function testLinkPassword() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_enforce_links_password', 'yes', 'yes'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertArrayHasKey('password', $result['public']);
+ $this->assertArrayHasKey('enforced', $result['public']['password']);
+ $this->assertTrue($result['public']['password']['enforced']);
+ }
+
+ public function testLinkNoPassword() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_enforce_links_password', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertArrayHasKey('password', $result['public']);
+ $this->assertArrayHasKey('enforced', $result['public']['password']);
+ $this->assertFalse($result['public']['password']['enforced']);
+ }
+
+ public function testLinkNoExpireDate() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_default_expire_date', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertArrayHasKey('expire_date', $result['public']);
+ $this->assertInternalType('array', $result['public']['expire_date']);
+ $this->assertFalse($result['public']['expire_date']['enabled']);
+ }
+
+ public function testLinkExpireDate() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_default_expire_date', 'yes', 'yes'],
+ ['core', 'shareapi_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_expire_date', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertArrayHasKey('expire_date', $result['public']);
+ $this->assertInternalType('array', $result['public']['expire_date']);
+ $this->assertTrue($result['public']['expire_date']['enabled']);
+ $this->assertArrayHasKey('days', $result['public']['expire_date']);
+ $this->assertFalse($result['public']['expire_date']['enforced']);
+ }
+
+ public function testLinkExpireDateEnforced() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_default_expire_date', 'yes', 'yes'],
+ ['core', 'shareapi_enforce_expire_date', 'yes', 'yes'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertArrayHasKey('expire_date', $result['public']);
+ $this->assertInternalType('array', $result['public']['expire_date']);
+ $this->assertTrue($result['public']['expire_date']['enforced']);
+ }
+
+ public function testLinkSendMail() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_allow_public_notification', 'yes', 'yes'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertTrue($result['public']['send_mail']);
+ }
+
+ public function testLinkNoSendMail() {
+ $map = [
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_allow_public_notification', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertFalse($result['public']['send_mail']);
+ }
+
+ public function testUserSendMail() {
+ $map = [
+ ['core', 'shareapi_allow_mail_notification', 'yes', 'yes'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertTrue($result['user']['send_mail']);
+ }
+
+ public function testUserNoSendMail() {
+ $map = [
+ ['core', 'shareapi_allow_mail_notification', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertFalse($result['user']['send_mail']);
+ }
+
+ public function testResharing() {
+ $map = [
+ ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertTrue($result['resharing']);
+ }
+
+ public function testNoResharing() {
+ $map = [
+ ['core', 'shareapi_allow_resharing', 'yes', 'no'],
+ ];
+ $result = $this->getResults($map);
+ $this->assertFalse($result['resharing']);
+ }
+}