Completed
Push — stable12 ( eb1ce1...bc3034 )
by Morris
26:43 queued 12:20
created
apps/dav/lib/CardDAV/AddressBook.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 	}
101 101
 
102 102
 	public function getACL() {
103
-		$acl =  [
103
+		$acl = [
104 104
 			[
105 105
 				'privilege' => '{DAV:}read',
106 106
 				'principal' => $this->getOwner(),
107 107
 				'protected' => true,
108
-			],[
108
+			], [
109 109
 				'privilege' => '{DAV:}write',
110 110
 				'principal' => $this->getOwner(),
111 111
 				'protected' => true,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		}
118 118
 
119 119
 		if ($this->getOwner() !== parent::getOwner()) {
120
-			$acl[] =  [
120
+			$acl[] = [
121 121
 					'privilege' => '{DAV:}read',
122 122
 					'principal' => parent::getOwner(),
123 123
 					'protected' => true,
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 	public function delete() {
178 178
 		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
179
-			$principal = 'principal:' . parent::getOwner();
179
+			$principal = 'principal:'.parent::getOwner();
180 180
 			$shares = $this->carddavBackend->getShares($this->getResourceId());
181 181
 			$shares = array_filter($shares, function($share) use ($principal){
182 182
 				return $share['href'] === $principal;
Please login to merge, or discard this patch.
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -37,184 +37,184 @@
 block discarded – undo
37 37
  */
38 38
 class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
39 39
 
40
-	/**
41
-	 * AddressBook constructor.
42
-	 *
43
-	 * @param BackendInterface $carddavBackend
44
-	 * @param array $addressBookInfo
45
-	 * @param IL10N $l10n
46
-	 */
47
-	public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) {
48
-		parent::__construct($carddavBackend, $addressBookInfo);
49
-
50
-		if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME &&
51
-			$this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) {
52
-			$this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts');
53
-		}
54
-	}
55
-
56
-	/**
57
-	 * Updates the list of shares.
58
-	 *
59
-	 * The first array is a list of people that are to be added to the
60
-	 * addressbook.
61
-	 *
62
-	 * Every element in the add array has the following properties:
63
-	 *   * href - A url. Usually a mailto: address
64
-	 *   * commonName - Usually a first and last name, or false
65
-	 *   * summary - A description of the share, can also be false
66
-	 *   * readOnly - A boolean value
67
-	 *
68
-	 * Every element in the remove array is just the address string.
69
-	 *
70
-	 * @param array $add
71
-	 * @param array $remove
72
-	 * @return void
73
-	 * @throws Forbidden
74
-	 */
75
-	public function updateShares(array $add, array $remove) {
76
-		if ($this->isShared()) {
77
-			throw new Forbidden();
78
-		}
79
-		$this->carddavBackend->updateShares($this, $add, $remove);
80
-	}
81
-
82
-	/**
83
-	 * Returns the list of people whom this addressbook is shared with.
84
-	 *
85
-	 * Every element in this array should have the following properties:
86
-	 *   * href - Often a mailto: address
87
-	 *   * commonName - Optional, for example a first + last name
88
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
89
-	 *   * readOnly - boolean
90
-	 *   * summary - Optional, a description for the share
91
-	 *
92
-	 * @return array
93
-	 */
94
-	public function getShares() {
95
-		if ($this->isShared()) {
96
-			return [];
97
-		}
98
-		return $this->carddavBackend->getShares($this->getResourceId());
99
-	}
100
-
101
-	public function getACL() {
102
-		$acl =  [
103
-			[
104
-				'privilege' => '{DAV:}read',
105
-				'principal' => $this->getOwner(),
106
-				'protected' => true,
107
-			],[
108
-				'privilege' => '{DAV:}write',
109
-				'principal' => $this->getOwner(),
110
-				'protected' => true,
111
-			]
112
-		];
113
-
114
-		if (!$this->isShared()) {
115
-			return $acl;
116
-		}
117
-
118
-		if ($this->getOwner() !== parent::getOwner()) {
119
-			$acl[] =  [
120
-					'privilege' => '{DAV:}read',
121
-					'principal' => parent::getOwner(),
122
-					'protected' => true,
123
-				];
124
-			if ($this->canWrite()) {
125
-				$acl[] = [
126
-					'privilege' => '{DAV:}write',
127
-					'principal' => parent::getOwner(),
128
-					'protected' => true,
129
-				];
130
-			}
131
-		}
132
-		if ($this->getOwner() === 'principals/system/system') {
133
-			$acl[] = [
134
-					'privilege' => '{DAV:}read',
135
-					'principal' => '{DAV:}authenticated',
136
-					'protected' => true,
137
-			];
138
-		}
139
-
140
-		$acl = $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl);
141
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/system'];
142
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
143
-			return \in_array($rule['principal'], $allowedPrincipals, true);
144
-		});
145
-	}
146
-
147
-	public function getChildACL() {
148
-		return $this->getACL();
149
-	}
150
-
151
-	public function getChild($name) {
152
-
153
-		$obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name);
154
-		if (!$obj) {
155
-			throw new NotFound('Card not found');
156
-		}
157
-		$obj['acl'] = $this->getChildACL();
158
-		return new Card($this->carddavBackend, $this->addressBookInfo, $obj);
159
-
160
-	}
161
-
162
-	/**
163
-	 * @return int
164
-	 */
165
-	public function getResourceId() {
166
-		return $this->addressBookInfo['id'];
167
-	}
168
-
169
-	public function getOwner() {
170
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
171
-			return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'];
172
-		}
173
-		return parent::getOwner();
174
-	}
175
-
176
-	public function delete() {
177
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
178
-			$principal = 'principal:' . parent::getOwner();
179
-			$shares = $this->carddavBackend->getShares($this->getResourceId());
180
-			$shares = array_filter($shares, function($share) use ($principal){
181
-				return $share['href'] === $principal;
182
-			});
183
-			if (empty($shares)) {
184
-				throw new Forbidden();
185
-			}
186
-
187
-			$this->carddavBackend->updateShares($this, [], [
188
-				'href' => $principal
189
-			]);
190
-			return;
191
-		}
192
-		parent::delete();
193
-	}
194
-
195
-	public function propPatch(PropPatch $propPatch) {
196
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
197
-			throw new Forbidden();
198
-		}
199
-		parent::propPatch($propPatch);
200
-	}
201
-
202
-	public function getContactsGroups() {
203
-		return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES');
204
-	}
205
-
206
-	private function isShared() {
207
-		if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
208
-			return false;
209
-		}
210
-
211
-		return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri'];
212
-	}
213
-
214
-	private function canWrite() {
215
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) {
216
-			return !$this->addressBookInfo['{http://owncloud.org/ns}read-only'];
217
-		}
218
-		return true;
219
-	}
40
+    /**
41
+     * AddressBook constructor.
42
+     *
43
+     * @param BackendInterface $carddavBackend
44
+     * @param array $addressBookInfo
45
+     * @param IL10N $l10n
46
+     */
47
+    public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) {
48
+        parent::__construct($carddavBackend, $addressBookInfo);
49
+
50
+        if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME &&
51
+            $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) {
52
+            $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts');
53
+        }
54
+    }
55
+
56
+    /**
57
+     * Updates the list of shares.
58
+     *
59
+     * The first array is a list of people that are to be added to the
60
+     * addressbook.
61
+     *
62
+     * Every element in the add array has the following properties:
63
+     *   * href - A url. Usually a mailto: address
64
+     *   * commonName - Usually a first and last name, or false
65
+     *   * summary - A description of the share, can also be false
66
+     *   * readOnly - A boolean value
67
+     *
68
+     * Every element in the remove array is just the address string.
69
+     *
70
+     * @param array $add
71
+     * @param array $remove
72
+     * @return void
73
+     * @throws Forbidden
74
+     */
75
+    public function updateShares(array $add, array $remove) {
76
+        if ($this->isShared()) {
77
+            throw new Forbidden();
78
+        }
79
+        $this->carddavBackend->updateShares($this, $add, $remove);
80
+    }
81
+
82
+    /**
83
+     * Returns the list of people whom this addressbook is shared with.
84
+     *
85
+     * Every element in this array should have the following properties:
86
+     *   * href - Often a mailto: address
87
+     *   * commonName - Optional, for example a first + last name
88
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
89
+     *   * readOnly - boolean
90
+     *   * summary - Optional, a description for the share
91
+     *
92
+     * @return array
93
+     */
94
+    public function getShares() {
95
+        if ($this->isShared()) {
96
+            return [];
97
+        }
98
+        return $this->carddavBackend->getShares($this->getResourceId());
99
+    }
100
+
101
+    public function getACL() {
102
+        $acl =  [
103
+            [
104
+                'privilege' => '{DAV:}read',
105
+                'principal' => $this->getOwner(),
106
+                'protected' => true,
107
+            ],[
108
+                'privilege' => '{DAV:}write',
109
+                'principal' => $this->getOwner(),
110
+                'protected' => true,
111
+            ]
112
+        ];
113
+
114
+        if (!$this->isShared()) {
115
+            return $acl;
116
+        }
117
+
118
+        if ($this->getOwner() !== parent::getOwner()) {
119
+            $acl[] =  [
120
+                    'privilege' => '{DAV:}read',
121
+                    'principal' => parent::getOwner(),
122
+                    'protected' => true,
123
+                ];
124
+            if ($this->canWrite()) {
125
+                $acl[] = [
126
+                    'privilege' => '{DAV:}write',
127
+                    'principal' => parent::getOwner(),
128
+                    'protected' => true,
129
+                ];
130
+            }
131
+        }
132
+        if ($this->getOwner() === 'principals/system/system') {
133
+            $acl[] = [
134
+                    'privilege' => '{DAV:}read',
135
+                    'principal' => '{DAV:}authenticated',
136
+                    'protected' => true,
137
+            ];
138
+        }
139
+
140
+        $acl = $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl);
141
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/system'];
142
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
143
+            return \in_array($rule['principal'], $allowedPrincipals, true);
144
+        });
145
+    }
146
+
147
+    public function getChildACL() {
148
+        return $this->getACL();
149
+    }
150
+
151
+    public function getChild($name) {
152
+
153
+        $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name);
154
+        if (!$obj) {
155
+            throw new NotFound('Card not found');
156
+        }
157
+        $obj['acl'] = $this->getChildACL();
158
+        return new Card($this->carddavBackend, $this->addressBookInfo, $obj);
159
+
160
+    }
161
+
162
+    /**
163
+     * @return int
164
+     */
165
+    public function getResourceId() {
166
+        return $this->addressBookInfo['id'];
167
+    }
168
+
169
+    public function getOwner() {
170
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
171
+            return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'];
172
+        }
173
+        return parent::getOwner();
174
+    }
175
+
176
+    public function delete() {
177
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
178
+            $principal = 'principal:' . parent::getOwner();
179
+            $shares = $this->carddavBackend->getShares($this->getResourceId());
180
+            $shares = array_filter($shares, function($share) use ($principal){
181
+                return $share['href'] === $principal;
182
+            });
183
+            if (empty($shares)) {
184
+                throw new Forbidden();
185
+            }
186
+
187
+            $this->carddavBackend->updateShares($this, [], [
188
+                'href' => $principal
189
+            ]);
190
+            return;
191
+        }
192
+        parent::delete();
193
+    }
194
+
195
+    public function propPatch(PropPatch $propPatch) {
196
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
197
+            throw new Forbidden();
198
+        }
199
+        parent::propPatch($propPatch);
200
+    }
201
+
202
+    public function getContactsGroups() {
203
+        return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES');
204
+    }
205
+
206
+    private function isShared() {
207
+        if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
208
+            return false;
209
+        }
210
+
211
+        return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri'];
212
+    }
213
+
214
+    private function canWrite() {
215
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) {
216
+            return !$this->addressBookInfo['{http://owncloud.org/ns}read-only'];
217
+        }
218
+        return true;
219
+    }
220 220
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Calendar.php 1 patch
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -38,286 +38,286 @@
 block discarded – undo
38 38
  */
39 39
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
40 40
 
41
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
42
-		parent::__construct($caldavBackend, $calendarInfo);
43
-
44
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
45
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
46
-		}
47
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
48
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
49
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
50
-		}
51
-	}
52
-
53
-	/**
54
-	 * Updates the list of shares.
55
-	 *
56
-	 * The first array is a list of people that are to be added to the
57
-	 * resource.
58
-	 *
59
-	 * Every element in the add array has the following properties:
60
-	 *   * href - A url. Usually a mailto: address
61
-	 *   * commonName - Usually a first and last name, or false
62
-	 *   * summary - A description of the share, can also be false
63
-	 *   * readOnly - A boolean value
64
-	 *
65
-	 * Every element in the remove array is just the address string.
66
-	 *
67
-	 * @param array $add
68
-	 * @param array $remove
69
-	 * @return void
70
-	 * @throws Forbidden
71
-	 */
72
-	public function updateShares(array $add, array $remove) {
73
-		if ($this->isShared()) {
74
-			throw new Forbidden();
75
-		}
76
-		$this->caldavBackend->updateShares($this, $add, $remove);
77
-	}
78
-
79
-	/**
80
-	 * Returns the list of people whom this resource is shared with.
81
-	 *
82
-	 * Every element in this array should have the following properties:
83
-	 *   * href - Often a mailto: address
84
-	 *   * commonName - Optional, for example a first + last name
85
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
86
-	 *   * readOnly - boolean
87
-	 *   * summary - Optional, a description for the share
88
-	 *
89
-	 * @return array
90
-	 */
91
-	public function getShares() {
92
-		if ($this->isShared()) {
93
-			return [];
94
-		}
95
-		return $this->caldavBackend->getShares($this->getResourceId());
96
-	}
97
-
98
-	/**
99
-	 * @return int
100
-	 */
101
-	public function getResourceId() {
102
-		return $this->calendarInfo['id'];
103
-	}
104
-
105
-	/**
106
-	 * @return string
107
-	 */
108
-	public function getPrincipalURI() {
109
-		return $this->calendarInfo['principaluri'];
110
-	}
111
-
112
-	public function getACL() {
113
-		$acl =  [
114
-			[
115
-				'privilege' => '{DAV:}read',
116
-				'principal' => $this->getOwner(),
117
-				'protected' => true,
118
-			]];
119
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
120
-			$acl[] = [
121
-				'privilege' => '{DAV:}write',
122
-				'principal' => $this->getOwner(),
123
-				'protected' => true,
124
-			];
125
-		} else {
126
-			$acl[] = [
127
-				'privilege' => '{DAV:}write-properties',
128
-				'principal' => $this->getOwner(),
129
-				'protected' => true,
130
-			];
131
-		}
132
-
133
-		if (!$this->isShared()) {
134
-			return $acl;
135
-		}
136
-
137
-		if ($this->getOwner() !== parent::getOwner()) {
138
-			$acl[] =  [
139
-					'privilege' => '{DAV:}read',
140
-					'principal' => parent::getOwner(),
141
-					'protected' => true,
142
-				];
143
-			if ($this->canWrite()) {
144
-				$acl[] = [
145
-					'privilege' => '{DAV:}write',
146
-					'principal' => parent::getOwner(),
147
-					'protected' => true,
148
-				];
149
-			} else {
150
-				$acl[] = [
151
-					'privilege' => '{DAV:}write-properties',
152
-					'principal' => parent::getOwner(),
153
-					'protected' => true,
154
-				];
155
-			}
156
-		}
157
-		if ($this->isPublic()) {
158
-			$acl[] = [
159
-				'privilege' => '{DAV:}read',
160
-				'principal' => 'principals/system/public',
161
-				'protected' => true,
162
-			];
163
-		}
164
-
165
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
166
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
167
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
168
-			return \in_array($rule['principal'], $allowedPrincipals, true);
169
-		});
170
-	}
171
-
172
-	public function getChildACL() {
173
-		return $this->getACL();
174
-	}
175
-
176
-	public function getOwner() {
177
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
178
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
179
-		}
180
-		return parent::getOwner();
181
-	}
182
-
183
-	public function delete() {
184
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
185
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
186
-			$principal = 'principal:' . parent::getOwner();
187
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
188
-			$shares = array_filter($shares, function($share) use ($principal){
189
-				return $share['href'] === $principal;
190
-			});
191
-			if (empty($shares)) {
192
-				throw new Forbidden();
193
-			}
194
-
195
-			$this->caldavBackend->updateShares($this, [], [
196
-				'href' => $principal
197
-			]);
198
-			return;
199
-		}
200
-		parent::delete();
201
-	}
202
-
203
-	public function propPatch(PropPatch $propPatch) {
204
-		// parent::propPatch will only update calendars table
205
-		// if calendar is shared, changes have to be made to the properties table
206
-		if (!$this->isShared()) {
207
-			parent::propPatch($propPatch);
208
-		}
209
-	}
210
-
211
-	public function getChild($name) {
212
-
213
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
214
-
215
-		if (!$obj) {
216
-			throw new NotFound('Calendar object not found');
217
-		}
218
-
219
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
220
-			throw new NotFound('Calendar object not found');
221
-		}
222
-
223
-		$obj['acl'] = $this->getChildACL();
224
-
225
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
226
-
227
-	}
228
-
229
-	public function getChildren() {
230
-
231
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
232
-		$children = [];
233
-		foreach ($objs as $obj) {
234
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
235
-				continue;
236
-			}
237
-			$obj['acl'] = $this->getChildACL();
238
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
239
-		}
240
-		return $children;
241
-
242
-	}
243
-
244
-	public function getMultipleChildren(array $paths) {
245
-
246
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
247
-		$children = [];
248
-		foreach ($objs as $obj) {
249
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
250
-				continue;
251
-			}
252
-			$obj['acl'] = $this->getChildACL();
253
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
254
-		}
255
-		return $children;
256
-
257
-	}
258
-
259
-	public function childExists($name) {
260
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
261
-		if (!$obj) {
262
-			return false;
263
-		}
264
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
265
-			return false;
266
-		}
267
-
268
-		return true;
269
-	}
270
-
271
-	public function calendarQuery(array $filters) {
272
-
273
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
274
-		if ($this->isShared()) {
275
-			return array_filter($uris, function ($uri) {
276
-				return $this->childExists($uri);
277
-			});
278
-		}
279
-
280
-		return $uris;
281
-	}
282
-
283
-	/**
284
-	 * @param boolean $value
285
-	 * @return string|null
286
-	 */
287
-	public function setPublishStatus($value) {
288
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
289
-		$this->calendarInfo['publicuri'] = $publicUri;
290
-		return $publicUri;
291
-	}
292
-
293
-	/**
294
-	 * @return mixed $value
295
-	 */
296
-	public function getPublishStatus() {
297
-		return $this->caldavBackend->getPublishStatus($this);
298
-	}
299
-
300
-	private function canWrite() {
301
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
302
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
303
-		}
304
-		return true;
305
-	}
306
-
307
-	private function isPublic() {
308
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
309
-	}
310
-
311
-	protected function isShared() {
312
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
313
-			return false;
314
-		}
315
-
316
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
317
-	}
318
-
319
-	public function isSubscription() {
320
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
321
-	}
41
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
42
+        parent::__construct($caldavBackend, $calendarInfo);
43
+
44
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
45
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
46
+        }
47
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
48
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
49
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
50
+        }
51
+    }
52
+
53
+    /**
54
+     * Updates the list of shares.
55
+     *
56
+     * The first array is a list of people that are to be added to the
57
+     * resource.
58
+     *
59
+     * Every element in the add array has the following properties:
60
+     *   * href - A url. Usually a mailto: address
61
+     *   * commonName - Usually a first and last name, or false
62
+     *   * summary - A description of the share, can also be false
63
+     *   * readOnly - A boolean value
64
+     *
65
+     * Every element in the remove array is just the address string.
66
+     *
67
+     * @param array $add
68
+     * @param array $remove
69
+     * @return void
70
+     * @throws Forbidden
71
+     */
72
+    public function updateShares(array $add, array $remove) {
73
+        if ($this->isShared()) {
74
+            throw new Forbidden();
75
+        }
76
+        $this->caldavBackend->updateShares($this, $add, $remove);
77
+    }
78
+
79
+    /**
80
+     * Returns the list of people whom this resource is shared with.
81
+     *
82
+     * Every element in this array should have the following properties:
83
+     *   * href - Often a mailto: address
84
+     *   * commonName - Optional, for example a first + last name
85
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
86
+     *   * readOnly - boolean
87
+     *   * summary - Optional, a description for the share
88
+     *
89
+     * @return array
90
+     */
91
+    public function getShares() {
92
+        if ($this->isShared()) {
93
+            return [];
94
+        }
95
+        return $this->caldavBackend->getShares($this->getResourceId());
96
+    }
97
+
98
+    /**
99
+     * @return int
100
+     */
101
+    public function getResourceId() {
102
+        return $this->calendarInfo['id'];
103
+    }
104
+
105
+    /**
106
+     * @return string
107
+     */
108
+    public function getPrincipalURI() {
109
+        return $this->calendarInfo['principaluri'];
110
+    }
111
+
112
+    public function getACL() {
113
+        $acl =  [
114
+            [
115
+                'privilege' => '{DAV:}read',
116
+                'principal' => $this->getOwner(),
117
+                'protected' => true,
118
+            ]];
119
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
120
+            $acl[] = [
121
+                'privilege' => '{DAV:}write',
122
+                'principal' => $this->getOwner(),
123
+                'protected' => true,
124
+            ];
125
+        } else {
126
+            $acl[] = [
127
+                'privilege' => '{DAV:}write-properties',
128
+                'principal' => $this->getOwner(),
129
+                'protected' => true,
130
+            ];
131
+        }
132
+
133
+        if (!$this->isShared()) {
134
+            return $acl;
135
+        }
136
+
137
+        if ($this->getOwner() !== parent::getOwner()) {
138
+            $acl[] =  [
139
+                    'privilege' => '{DAV:}read',
140
+                    'principal' => parent::getOwner(),
141
+                    'protected' => true,
142
+                ];
143
+            if ($this->canWrite()) {
144
+                $acl[] = [
145
+                    'privilege' => '{DAV:}write',
146
+                    'principal' => parent::getOwner(),
147
+                    'protected' => true,
148
+                ];
149
+            } else {
150
+                $acl[] = [
151
+                    'privilege' => '{DAV:}write-properties',
152
+                    'principal' => parent::getOwner(),
153
+                    'protected' => true,
154
+                ];
155
+            }
156
+        }
157
+        if ($this->isPublic()) {
158
+            $acl[] = [
159
+                'privilege' => '{DAV:}read',
160
+                'principal' => 'principals/system/public',
161
+                'protected' => true,
162
+            ];
163
+        }
164
+
165
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
166
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
167
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
168
+            return \in_array($rule['principal'], $allowedPrincipals, true);
169
+        });
170
+    }
171
+
172
+    public function getChildACL() {
173
+        return $this->getACL();
174
+    }
175
+
176
+    public function getOwner() {
177
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
178
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
179
+        }
180
+        return parent::getOwner();
181
+    }
182
+
183
+    public function delete() {
184
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
185
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
186
+            $principal = 'principal:' . parent::getOwner();
187
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
188
+            $shares = array_filter($shares, function($share) use ($principal){
189
+                return $share['href'] === $principal;
190
+            });
191
+            if (empty($shares)) {
192
+                throw new Forbidden();
193
+            }
194
+
195
+            $this->caldavBackend->updateShares($this, [], [
196
+                'href' => $principal
197
+            ]);
198
+            return;
199
+        }
200
+        parent::delete();
201
+    }
202
+
203
+    public function propPatch(PropPatch $propPatch) {
204
+        // parent::propPatch will only update calendars table
205
+        // if calendar is shared, changes have to be made to the properties table
206
+        if (!$this->isShared()) {
207
+            parent::propPatch($propPatch);
208
+        }
209
+    }
210
+
211
+    public function getChild($name) {
212
+
213
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
214
+
215
+        if (!$obj) {
216
+            throw new NotFound('Calendar object not found');
217
+        }
218
+
219
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
220
+            throw new NotFound('Calendar object not found');
221
+        }
222
+
223
+        $obj['acl'] = $this->getChildACL();
224
+
225
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
226
+
227
+    }
228
+
229
+    public function getChildren() {
230
+
231
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
232
+        $children = [];
233
+        foreach ($objs as $obj) {
234
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
235
+                continue;
236
+            }
237
+            $obj['acl'] = $this->getChildACL();
238
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
239
+        }
240
+        return $children;
241
+
242
+    }
243
+
244
+    public function getMultipleChildren(array $paths) {
245
+
246
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
247
+        $children = [];
248
+        foreach ($objs as $obj) {
249
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
250
+                continue;
251
+            }
252
+            $obj['acl'] = $this->getChildACL();
253
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
254
+        }
255
+        return $children;
256
+
257
+    }
258
+
259
+    public function childExists($name) {
260
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
261
+        if (!$obj) {
262
+            return false;
263
+        }
264
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
265
+            return false;
266
+        }
267
+
268
+        return true;
269
+    }
270
+
271
+    public function calendarQuery(array $filters) {
272
+
273
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
274
+        if ($this->isShared()) {
275
+            return array_filter($uris, function ($uri) {
276
+                return $this->childExists($uri);
277
+            });
278
+        }
279
+
280
+        return $uris;
281
+    }
282
+
283
+    /**
284
+     * @param boolean $value
285
+     * @return string|null
286
+     */
287
+    public function setPublishStatus($value) {
288
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
289
+        $this->calendarInfo['publicuri'] = $publicUri;
290
+        return $publicUri;
291
+    }
292
+
293
+    /**
294
+     * @return mixed $value
295
+     */
296
+    public function getPublishStatus() {
297
+        return $this->caldavBackend->getPublishStatus($this);
298
+    }
299
+
300
+    private function canWrite() {
301
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
302
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
303
+        }
304
+        return true;
305
+    }
306
+
307
+    private function isPublic() {
308
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
309
+    }
310
+
311
+    protected function isShared() {
312
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
313
+            return false;
314
+        }
315
+
316
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
317
+    }
318
+
319
+    public function isSubscription() {
320
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
321
+    }
322 322
 
323 323
 }
Please login to merge, or discard this patch.