Completed
Push — master ( 01f420...7bc3c2 )
by Morris
99:18 queued 80:12
created

Sharing::getSharePermissionList()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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