Passed
Push — master ( 846eb8...1b3311 )
by Roeland
10:34 queued 10s
created

Sharing::getForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
c 0
b 0
f 0
dl 0
loc 30
rs 9.52
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Bjoern Schiessle <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 * @author Roeland Jago Douma <[email protected]>
11
 * @author Sascha Wiswedel <[email protected]>
12
 *
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OCA\Settings\Settings\Admin;
31
32
use OC\Share\Share;
33
use OCP\AppFramework\Http\TemplateResponse;
34
use OCP\Constants;
35
use OCP\IConfig;
36
use OCP\IL10N;
37
use OCP\L10N\IFactory;
38
use OCP\Settings\ISettings;
39
use OCP\Share\IManager;
40
use OCP\Util;
41
42
class Sharing implements ISettings {
43
	/** @var IConfig */
44
	private $config;
45
46
	/** @var IL10N */
47
	private $l;
48
49
	/** @var IManager */
50
	private $shareManager;
51
52
	/**
53
	 * @param IConfig $config
54
	 */
55
	public function __construct(IConfig $config, IFactory $l, IManager $shareManager) {
56
		$this->config = $config;
57
		$this->l = $l->get('lib');
58
		$this->shareManager = $shareManager;
59
	}
60
61
	/**
62
	 * @return TemplateResponse
63
	 */
64
	public function getForm() {
65
		$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
66
		$excludeGroupsList = !is_null(json_decode($excludedGroups))
67
			? implode('|', json_decode($excludedGroups, true)) : '';
68
69
		$parameters = [
70
			// Built-In Sharing
71
			'allowGroupSharing'                    => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
72
			'allowLinks'                           => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
73
			'allowPublicUpload'                    => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
74
			'allowResharing'                       => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
75
			'allowShareDialogUserEnumeration'      => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
76
			'enforceLinkPassword'                  => Util::isPublicLinkPasswordRequired(),
77
			'onlyShareWithGroupMembers'            => $this->shareManager->shareWithGroupMembersOnly(),
78
			'shareAPIEnabled'                      => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
79
			'shareDefaultExpireDateSet'            => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
80
			'shareExpireAfterNDays'                => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
81
			'shareEnforceExpireDate'               => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
82
			'shareExcludeGroups'                   => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
83
			'shareExcludedGroupsList'              => $excludeGroupsList,
84
			'publicShareDisclaimerText'            => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
85
			'enableLinkPasswordByDefault'          => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
86
			'shareApiDefaultPermissions'           => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
87
			'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
88
			'shareDefaultInternalExpireDateSet'    => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
89
			'shareInternalExpireAfterNDays'        => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
90
			'shareInternalEnforceExpireDate'       => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'),
91
		];
92
93
		return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
94
	}
95
96
	/**
97
	 * get share permission list for template
98
	 *
99
	 * @return array
100
	 */
101
	private function getSharePermissionList() {
102
		return [
103
			[
104
				'id' => 'cancreate',
105
				'label' => $this->l->t('Create'),
106
				'value' => Constants::PERMISSION_CREATE
107
			],
108
			[
109
				'id' => 'canupdate',
110
				'label' => $this->l->t('Change'),
111
				'value' => Constants::PERMISSION_UPDATE
112
			],
113
			[
114
				'id' => 'candelete',
115
				'label' => $this->l->t('Delete'),
116
				'value' => Constants::PERMISSION_DELETE
117
			],
118
			[
119
				'id' => 'canshare',
120
				'label' => $this->l->t('Reshare'),
121
				'value' => Constants::PERMISSION_SHARE
122
			],
123
		];
124
	}
125
126
	/**
127
	 * @return string the section ID, e.g. 'sharing'
128
	 */
129
	public function getSection() {
130
		return 'sharing';
131
	}
132
133
	/**
134
	 * @return int whether the form should be rather on the top or bottom of
135
	 * the admin section. The forms are arranged in ascending order of the
136
	 * priority values. It is required to return a value between 0 and 100.
137
	 *
138
	 * E.g.: 70
139
	 */
140
	public function getPriority() {
141
		return 0;
142
	}
143
}
144