Passed
Push — master ( 5ee687...8001c8 )
by Morris
10:18 queued 10s
created

Capabilities::getCapabilities()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 61
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 41
nc 6
nop 0
dl 0
loc 61
rs 8.9528
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bjoern Schiessle <[email protected]>
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license AGPL-3.0
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
namespace OCA\Files_Sharing;
24
25
use OCP\Capabilities\ICapability;
26
use OCP\Constants;
27
use \OCP\IConfig;
28
29
/**
30
 * Class Capabilities
31
 *
32
 * @package OCA\Files_Sharing
33
 */
34
class Capabilities implements ICapability {
35
36
	/** @var IConfig */
37
	private $config;
38
39
	public function __construct(IConfig $config) {
40
		$this->config = $config;
41
	}
42
43
	/**
44
	 * Return this classes capabilities
45
	 *
46
	 * @return array
47
	 */
48
	public function getCapabilities() {
49
		$res = [];
50
51
		if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
52
			$res['api_enabled'] = false;
53
			$res['public'] = ['enabled' => false];
54
			$res['user'] = ['send_mail' => false];
55
			$res['resharing'] = false;
56
		} else {
57
			$res['api_enabled'] = true;
58
59
			$public = [];
60
			$public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
61
			if ($public['enabled']) {
62
				$public['password'] = [];
63
				$public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes');
64
65
				if ($public['password']['enforced']) {
66
					$public['password']['askForOptionalPassword'] = false;
67
				} else {
68
					$public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes');
69
				}
70
71
				$public['expire_date'] = [];
72
				$public['multiple_links'] = true;
73
				$public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
74
				if ($public['expire_date']['enabled']) {
75
					$public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
76
					$public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
77
				}
78
79
				$public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
80
				$public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
81
				$public['upload_files_drop'] = $public['upload'];
82
			}
83
			$res['public'] = $public;
84
85
			$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
86
87
			$res['user']['send_mail'] = false;
88
			$res['user']['expire_date']['enabled'] = true;
89
90
			// deprecated in favour of 'group', but we need to keep it for now
91
			// in order to stay compatible with older clients
92
			$res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
93
94
			$res['group'] = [];
95
			$res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
96
			$res['group']['expire_date']['enabled'] = true;
97
			$res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
98
		}
99
100
		//Federated sharing
101
		$res['federation'] = [
102
			'outgoing'  => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes',
103
			'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
104
			'expire_date' => ['enabled' => true]
105
		];
106
107
		return [
108
			'files_sharing' => $res,
109
		];
110
	}
111
}
112