Completed
Push — master ( a423c8...b64e63 )
by
unknown
65:12 queued 48:58
created

Capabilities::getCapabilities()   B

Complexity

Conditions 8
Paths 29

Size

Total Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 29
nop 0
dl 0
loc 79
rs 7.2137
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
 * @author Roeland Jago Douma <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
namespace OCA\Files_Sharing;
22
23
use OCP\Capabilities\ICapability;
24
use OCP\IConfig;
25
use OCP\IGroupManager;
26
use OCP\IUserSession;
27
use OCP\Util\UserSearch;
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
	/**
40
	 * @var UserSearch
41
	 */
42
	private $userSearch;
43
44
	/**
45
	 * @var IUserSession
46
	 */
47
	private $userSession;
48
49
	/**
50
	 * @var IGroupManager
51
	 */
52
	private $groupManager;
53
54
	/**
55
	 * Capabilities constructor.
56
	 *
57
	 * @param IConfig $config
58
	 * @param UserSearch $userSearch
59
	 */
60
	public function __construct(IConfig $config, UserSearch $userSearch, IUserSession $userSession, IGroupManager $groupManager) {
61
		$this->config = $config;
62
		$this->userSearch = $userSearch;
63
		$this->userSession = $userSession;
64
		$this->groupManager = $groupManager;
65
	}
66
67
	/**
68
	 * Return this classes capabilities
69
	 *
70
	 * @return array
71
	 */
72
	public function getCapabilities() {
73
		$res = [];
74
75
		if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
76
			$res['api_enabled'] = false;
77
			$res['public'] = ['enabled' => false];
78
			$res['user'] = ['send_mail' => false];
79
			$res['resharing'] = false;
80
			$res['can_share'] = false;
81
		} else {
82
			$res['api_enabled'] = true;
83
84
			$public = [];
85
			$public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
86
			if ($public['enabled']) {
87
				$public['password'] = [];
88
				$public['password']['enforced_for'] = [];
89
				$roPasswordEnforced = $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_only', 'no') === 'yes';
90
				$rwPasswordEnforced = $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_write', 'no') === 'yes';
91
				$woPasswordEnforced = $this->config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no') === 'yes';
92
				$public['password']['enforced_for']['read_only'] = $roPasswordEnforced;
93
				$public['password']['enforced_for']['read_write'] = $rwPasswordEnforced;
94
				$public['password']['enforced_for']['upload_only'] = $woPasswordEnforced;
95
				$public['password']['enforced'] = $roPasswordEnforced || $rwPasswordEnforced || $woPasswordEnforced;
96
97
				$public['expire_date'] = [];
98
				$public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
99
				if ($public['expire_date']['enabled']) {
100
					$public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
101
					$public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
102
				}
103
104
				$public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
105
				$public['social_share'] = $this->config->getAppValue('core', 'shareapi_allow_social_share', 'yes') === 'yes';
106
				$public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
107
				$public['multiple'] = true;
108
				$public['supports_upload_only'] = true;
109
			}
110
			$res["public"] = $public;
111
112
			$res['user']['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'no') === 'yes';
113
114
			$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
115
116
			$res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
117
118
			$res['auto_accept_share'] = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes') === 'yes';
119
120
			$res['share_with_group_members_only'] = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'yes') === 'yes';
121
			$res['share_with_membership_groups_only'] = $this->config->getAppValue('core', 'shareapi_only_share_with_membership_groups', 'yes') === 'yes';
122
123
			if (\OC_Util::isSharingDisabledForUser($this->config, $this->groupManager, $this->userSession->getUser())) {
124
				$res['can_share'] = false;
125
			} else {
126
				$res['can_share'] = true;
127
			}
128
129
			$user_enumeration = [];
130
			$user_enumeration['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
131
			if ($user_enumeration['enabled']) {
132
				$user_enumeration['group_members_only'] = $this->config->getAppValue('core', 'shareapi_share_dialog_user_enumeration_group_members', 'no') === 'yes';
133
			}
134
			$res["user_enumeration"] = $user_enumeration;
135
136
			$res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', \OCP\Constants::PERMISSION_ALL);
137
		}
138
139
		//Federated sharing
140
		$res['federation'] = [
141
			'outgoing'  => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes',
142
			'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes'
143
		];
144
145
		$res['search_min_length'] = $this->userSearch->getSearchMinLength();
146
147
		return [
148
			'files_sharing' => $res,
149
		];
150
	}
151
}
152