Completed
Push — master ( b25307...4e53ea )
by Morris
46:04 queued 20:51
created

Outbox::getACL()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 69
rs 8.6763
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) 2018, Georg Ehrke
4
 *
5
 * @author Georg Ehrke <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
namespace OCA\DAV\CalDAV;
23
24
use OCP\IConfig;
25
use Sabre\CalDAV\Plugin as CalDAVPlugin;
26
27
/**
28
 * Class Outbox
29
 *
30
 * @package OCA\DAV\CalDAV
31
 */
32
class Outbox extends \Sabre\CalDAV\Schedule\Outbox {
33
34
	/** @var IConfig */
35
	private $config;
36
37
	/** @var null|bool */
38
	private $disableFreeBusy = null;
39
40
	/**
41
	 * Outbox constructor.
42
	 *
43
	 * @param IConfig $config
44
	 * @param string $principalUri
45
	 */
46
	public function __construct(IConfig $config, string $principalUri) {
47
		parent::__construct($principalUri);
48
		$this->config = $config;
49
	}
50
51
	/**
52
	 * Returns a list of ACE's for this node.
53
	 *
54
	 * Each ACE has the following properties:
55
	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
56
	 *     currently the only supported privileges
57
	 *   * 'principal', a url to the principal who owns the node
58
	 *   * 'protected' (optional), indicating that this ACE is not allowed to
59
	 *      be updated.
60
	 *
61
	 * @return array
62
	 */
63
	function getACL() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
		// getACL is called so frequently that we cache the config result
65
		if ($this->disableFreeBusy === null) {
66
			$this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes');
67
		}
68
69
		$commonAcl = [
70
			[
71
				'privilege' => '{DAV:}read',
72
				'principal' => $this->getOwner(),
73
				'protected' => true,
74
			],
75
			[
76
				'privilege' => '{DAV:}read',
77
				'principal' => $this->getOwner() . '/calendar-proxy-read',
78
				'protected' => true,
79
			],
80
			[
81
				'privilege' => '{DAV:}read',
82
				'principal' => $this->getOwner() . '/calendar-proxy-write',
83
				'protected' => true,
84
			],
85
		];
86
87
		// schedule-send is an aggregate privilege for:
88
		// - schedule-send-invite
89
		// - schedule-send-reply
90
		// - schedule-send-freebusy
91
		//
92
		// If FreeBusy is disabled, we have to remove the latter privilege
93
94
		if ($this->disableFreeBusy) {
95
			return array_merge($commonAcl, [
96
				[
97
					'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite',
98
					'principal' => $this->getOwner(),
99
					'protected' => true,
100
				],
101
				[
102
					'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite',
103
					'principal' => $this->getOwner() . '/calendar-proxy-write',
104
					'protected' => true,
105
				],
106
				[
107
					'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply',
108
					'principal' => $this->getOwner(),
109
					'protected' => true,
110
				],
111
				[
112
					'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply',
113
					'principal' => $this->getOwner() . '/calendar-proxy-write',
114
					'protected' => true,
115
				],
116
			]);
117
		}
118
119
		return array_merge($commonAcl, [
120
			[
121
				'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send',
122
				'principal' => $this->getOwner(),
123
				'protected' => true,
124
			],
125
			[
126
				'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send',
127
				'principal' => $this->getOwner() . '/calendar-proxy-write',
128
				'protected' => true,
129
			],
130
		]);
131
	}
132
}
133