Completed
Push — master ( 08b58a...0efd05 )
by Daniel
30:08 queued 21s
created
lib/private/Group/Backend.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 	 * compared with \OC\Group\Backend::CREATE_GROUP etc.
68 68
 	 */
69 69
 	public function implementsActions($actions) {
70
-		return (bool)($this->getSupportedActions() & $actions);
70
+		return (bool) ($this->getSupportedActions() & $actions);
71 71
 	}
72 72
 
73 73
 	/**
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -11,107 +11,107 @@
 block discarded – undo
11 11
  * Abstract base class for user management
12 12
  */
13 13
 abstract class Backend implements \OCP\GroupInterface {
14
-	/**
15
-	 * error code for functions not provided by the group backend
16
-	 */
17
-	public const NOT_IMPLEMENTED = -501;
14
+    /**
15
+     * error code for functions not provided by the group backend
16
+     */
17
+    public const NOT_IMPLEMENTED = -501;
18 18
 
19
-	protected $possibleActions = [
20
-		self::CREATE_GROUP => 'createGroup',
21
-		self::DELETE_GROUP => 'deleteGroup',
22
-		self::ADD_TO_GROUP => 'addToGroup',
23
-		self::REMOVE_FROM_GOUP => 'removeFromGroup',
24
-		self::COUNT_USERS => 'countUsersInGroup',
25
-		self::GROUP_DETAILS => 'getGroupDetails',
26
-		self::IS_ADMIN => 'isAdmin',
27
-	];
19
+    protected $possibleActions = [
20
+        self::CREATE_GROUP => 'createGroup',
21
+        self::DELETE_GROUP => 'deleteGroup',
22
+        self::ADD_TO_GROUP => 'addToGroup',
23
+        self::REMOVE_FROM_GOUP => 'removeFromGroup',
24
+        self::COUNT_USERS => 'countUsersInGroup',
25
+        self::GROUP_DETAILS => 'getGroupDetails',
26
+        self::IS_ADMIN => 'isAdmin',
27
+    ];
28 28
 
29
-	/**
30
-	 * Get all supported actions
31
-	 * @return int bitwise-or'ed actions
32
-	 *
33
-	 * Returns the supported actions as int to be
34
-	 * compared with \OC\Group\Backend::CREATE_GROUP etc.
35
-	 */
36
-	public function getSupportedActions() {
37
-		$actions = 0;
38
-		foreach ($this->possibleActions as $action => $methodName) {
39
-			if (method_exists($this, $methodName)) {
40
-				$actions |= $action;
41
-			}
42
-		}
29
+    /**
30
+     * Get all supported actions
31
+     * @return int bitwise-or'ed actions
32
+     *
33
+     * Returns the supported actions as int to be
34
+     * compared with \OC\Group\Backend::CREATE_GROUP etc.
35
+     */
36
+    public function getSupportedActions() {
37
+        $actions = 0;
38
+        foreach ($this->possibleActions as $action => $methodName) {
39
+            if (method_exists($this, $methodName)) {
40
+                $actions |= $action;
41
+            }
42
+        }
43 43
 
44
-		return $actions;
45
-	}
44
+        return $actions;
45
+    }
46 46
 
47
-	/**
48
-	 * Check if backend implements actions
49
-	 * @param int $actions bitwise-or'ed actions
50
-	 * @return bool
51
-	 *
52
-	 * Returns the supported actions as int to be
53
-	 * compared with \OC\Group\Backend::CREATE_GROUP etc.
54
-	 */
55
-	public function implementsActions($actions) {
56
-		return (bool)($this->getSupportedActions() & $actions);
57
-	}
47
+    /**
48
+     * Check if backend implements actions
49
+     * @param int $actions bitwise-or'ed actions
50
+     * @return bool
51
+     *
52
+     * Returns the supported actions as int to be
53
+     * compared with \OC\Group\Backend::CREATE_GROUP etc.
54
+     */
55
+    public function implementsActions($actions) {
56
+        return (bool)($this->getSupportedActions() & $actions);
57
+    }
58 58
 
59
-	/**
60
-	 * is user in group?
61
-	 * @param string $uid uid of the user
62
-	 * @param string $gid gid of the group
63
-	 * @return bool
64
-	 *
65
-	 * Checks whether the user is member of a group or not.
66
-	 */
67
-	public function inGroup($uid, $gid) {
68
-		return in_array($gid, $this->getUserGroups($uid));
69
-	}
59
+    /**
60
+     * is user in group?
61
+     * @param string $uid uid of the user
62
+     * @param string $gid gid of the group
63
+     * @return bool
64
+     *
65
+     * Checks whether the user is member of a group or not.
66
+     */
67
+    public function inGroup($uid, $gid) {
68
+        return in_array($gid, $this->getUserGroups($uid));
69
+    }
70 70
 
71
-	/**
72
-	 * Get all groups a user belongs to
73
-	 * @param string $uid Name of the user
74
-	 * @return list<string> an array of group names
75
-	 *
76
-	 * This function fetches all groups a user belongs to. It does not check
77
-	 * if the user exists at all.
78
-	 */
79
-	public function getUserGroups($uid) {
80
-		return [];
81
-	}
71
+    /**
72
+     * Get all groups a user belongs to
73
+     * @param string $uid Name of the user
74
+     * @return list<string> an array of group names
75
+     *
76
+     * This function fetches all groups a user belongs to. It does not check
77
+     * if the user exists at all.
78
+     */
79
+    public function getUserGroups($uid) {
80
+        return [];
81
+    }
82 82
 
83
-	/**
84
-	 * get a list of all groups
85
-	 * @param string $search
86
-	 * @param int $limit
87
-	 * @param int $offset
88
-	 * @return array an array of group names
89
-	 *
90
-	 * Returns a list with all groups
91
-	 */
83
+    /**
84
+     * get a list of all groups
85
+     * @param string $search
86
+     * @param int $limit
87
+     * @param int $offset
88
+     * @return array an array of group names
89
+     *
90
+     * Returns a list with all groups
91
+     */
92 92
 
93
-	public function getGroups($search = '', $limit = -1, $offset = 0) {
94
-		return [];
95
-	}
93
+    public function getGroups($search = '', $limit = -1, $offset = 0) {
94
+        return [];
95
+    }
96 96
 
97
-	/**
98
-	 * check if a group exists
99
-	 * @param string $gid
100
-	 * @return bool
101
-	 */
102
-	public function groupExists($gid) {
103
-		return in_array($gid, $this->getGroups($gid, 1));
104
-	}
97
+    /**
98
+     * check if a group exists
99
+     * @param string $gid
100
+     * @return bool
101
+     */
102
+    public function groupExists($gid) {
103
+        return in_array($gid, $this->getGroups($gid, 1));
104
+    }
105 105
 
106
-	/**
107
-	 * get a list of all users in a group
108
-	 * @param string $gid
109
-	 * @param string $search
110
-	 * @param int $limit
111
-	 * @param int $offset
112
-	 * @return array<int,string> an array of user ids
113
-	 */
114
-	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
115
-		return [];
116
-	}
106
+    /**
107
+     * get a list of all users in a group
108
+     * @param string $gid
109
+     * @param string $search
110
+     * @param int $limit
111
+     * @param int $offset
112
+     * @return array<int,string> an array of user ids
113
+     */
114
+    public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
115
+        return [];
116
+    }
117 117
 }
Please login to merge, or discard this patch.
lib/private/Activity/EventMerger.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 
134 134
 		// Check that all parameters from $event exist in $previousEvent
135 135
 		foreach ($params1 as $key => $parameter) {
136
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
136
+			if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) {
137 137
 				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
138 138
 					$combined++;
139
-					$params[$mergeParameter . $combined] = $parameter;
139
+					$params[$mergeParameter.$combined] = $parameter;
140 140
 				}
141 141
 				continue;
142 142
 			}
@@ -151,10 +151,10 @@  discard block
 block discarded – undo
151 151
 
152 152
 		// Check that all parameters from $previousEvent exist in $event
153 153
 		foreach ($params2 as $key => $parameter) {
154
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
154
+			if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) {
155 155
 				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
156 156
 					$combined++;
157
-					$params[$mergeParameter . $combined] = $parameter;
157
+					$params[$mergeParameter.$combined] = $parameter;
158 158
 				}
159 159
 				continue;
160 160
 			}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) {
180 180
 		foreach ($parameters as $key => $param) {
181
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
181
+			if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) {
182 182
 				if ($param === $parameter) {
183 183
 					return true;
184 184
 				}
@@ -196,30 +196,30 @@  discard block
 block discarded – undo
196 196
 	protected function getExtendedSubject($subject, $parameter, $counter) {
197 197
 		switch ($counter) {
198 198
 			case 1:
199
-				$replacement = '{' . $parameter . '1}';
199
+				$replacement = '{'.$parameter.'1}';
200 200
 				break;
201 201
 			case 2:
202 202
 				$replacement = $this->l10n->t(
203 203
 					'%1$s and %2$s',
204
-					['{' . $parameter . '2}', '{' . $parameter . '1}']
204
+					['{'.$parameter.'2}', '{'.$parameter.'1}']
205 205
 				);
206 206
 				break;
207 207
 			case 3:
208 208
 				$replacement = $this->l10n->t(
209 209
 					'%1$s, %2$s and %3$s',
210
-					['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
210
+					['{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}']
211 211
 				);
212 212
 				break;
213 213
 			case 4:
214 214
 				$replacement = $this->l10n->t(
215 215
 					'%1$s, %2$s, %3$s and %4$s',
216
-					['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
216
+					['{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}']
217 217
 				);
218 218
 				break;
219 219
 			case 5:
220 220
 				$replacement = $this->l10n->t(
221 221
 					'%1$s, %2$s, %3$s, %4$s and %5$s',
222
-					['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
222
+					['{'.$parameter.'5}', '{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}']
223 223
 				);
224 224
 				break;
225 225
 			default:
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 
229 229
 		return str_replace(
230
-			'{' . $parameter . '}',
230
+			'{'.$parameter.'}',
231 231
 			$replacement,
232 232
 			$subject
233 233
 		);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	protected function generateParsedSubject($subject, $parameters) {
242 242
 		$placeholders = $replacements = [];
243 243
 		foreach ($parameters as $placeholder => $parameter) {
244
-			$placeholders[] = '{' . $placeholder . '}';
244
+			$placeholders[] = '{'.$placeholder.'}';
245 245
 			if ($parameter['type'] === 'file') {
246 246
 				$replacements[] = trim($parameter['path'], '/');
247 247
 			} elseif (isset($parameter['name'])) {
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -10,231 +10,231 @@
 block discarded – undo
10 10
 use OCP\IL10N;
11 11
 
12 12
 class EventMerger implements IEventMerger {
13
-	/** @var IL10N */
14
-	protected $l10n;
15
-
16
-	/**
17
-	 * @param IL10N $l10n
18
-	 */
19
-	public function __construct(IL10N $l10n) {
20
-		$this->l10n = $l10n;
21
-	}
22
-
23
-	/**
24
-	 * Combines two events when possible to have grouping:
25
-	 *
26
-	 * Example1: Two events with subject '{user} created {file}' and
27
-	 * $mergeParameter file with different file and same user will be merged
28
-	 * to '{user} created {file1} and {file2}' and the childEvent on the return
29
-	 * will be set, if the events have been merged.
30
-	 *
31
-	 * Example2: Two events with subject '{user} created {file}' and
32
-	 * $mergeParameter file with same file and same user will be merged to
33
-	 * '{user} created {file1}' and the childEvent on the return will be set, if
34
-	 * the events have been merged.
35
-	 *
36
-	 * The following requirements have to be met, in order to be merged:
37
-	 * - Both events need to have the same `getApp()`
38
-	 * - Both events must not have a message `getMessage()`
39
-	 * - Both events need to have the same subject `getSubject()`
40
-	 * - Both events need to have the same object type `getObjectType()`
41
-	 * - The time difference between both events must not be bigger then 3 hours
42
-	 * - Only up to 5 events can be merged.
43
-	 * - All parameters apart from such starting with $mergeParameter must be
44
-	 *   the same for both events.
45
-	 *
46
-	 * @param string $mergeParameter
47
-	 * @param IEvent $event
48
-	 * @param IEvent|null $previousEvent
49
-	 * @return IEvent
50
-	 */
51
-	public function mergeEvents($mergeParameter, IEvent $event, ?IEvent $previousEvent = null) {
52
-		// No second event => can not combine
53
-		if (!$previousEvent instanceof IEvent) {
54
-			return $event;
55
-		}
56
-
57
-		// Different app => can not combine
58
-		if ($event->getApp() !== $previousEvent->getApp()) {
59
-			return $event;
60
-		}
61
-
62
-		// Message is set => can not combine
63
-		if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') {
64
-			return $event;
65
-		}
66
-
67
-		// Different subject => can not combine
68
-		if ($event->getSubject() !== $previousEvent->getSubject()) {
69
-			return $event;
70
-		}
71
-
72
-		// Different object type => can not combine
73
-		if ($event->getObjectType() !== $previousEvent->getObjectType()) {
74
-			return $event;
75
-		}
76
-
77
-		// More than 3 hours difference => can not combine
78
-		if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) {
79
-			return $event;
80
-		}
81
-
82
-		// Other parameters are not the same => can not combine
83
-		try {
84
-			[$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent);
85
-		} catch (\UnexpectedValueException $e) {
86
-			return $event;
87
-		}
88
-
89
-		try {
90
-			$newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined);
91
-			$parsedSubject = $this->generateParsedSubject($newSubject, $parameters);
92
-
93
-			$event->setRichSubject($newSubject, $parameters)
94
-				->setParsedSubject($parsedSubject)
95
-				->setChildEvent($previousEvent)
96
-				->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp()));
97
-		} catch (\UnexpectedValueException $e) {
98
-			return $event;
99
-		}
100
-
101
-		return $event;
102
-	}
103
-
104
-	/**
105
-	 * @param string $mergeParameter
106
-	 * @param IEvent $event
107
-	 * @param IEvent $previousEvent
108
-	 * @return array
109
-	 * @throws \UnexpectedValueException
110
-	 */
111
-	protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) {
112
-		$params1 = $event->getRichSubjectParameters();
113
-		$params2 = $previousEvent->getRichSubjectParameters();
114
-		$params = [];
115
-
116
-		$combined = 0;
117
-
118
-		// Check that all parameters from $event exist in $previousEvent
119
-		foreach ($params1 as $key => $parameter) {
120
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
121
-				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
122
-					$combined++;
123
-					$params[$mergeParameter . $combined] = $parameter;
124
-				}
125
-				continue;
126
-			}
127
-
128
-			if (!isset($params2[$key]) || $params2[$key] !== $parameter) {
129
-				// Parameter missing on $previousEvent or different => can not combine
130
-				throw new \UnexpectedValueException();
131
-			}
132
-
133
-			$params[$key] = $parameter;
134
-		}
135
-
136
-		// Check that all parameters from $previousEvent exist in $event
137
-		foreach ($params2 as $key => $parameter) {
138
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
139
-				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
140
-					$combined++;
141
-					$params[$mergeParameter . $combined] = $parameter;
142
-				}
143
-				continue;
144
-			}
145
-
146
-			if (!isset($params1[$key]) || $params1[$key] !== $parameter) {
147
-				// Parameter missing on $event or different => can not combine
148
-				throw new \UnexpectedValueException();
149
-			}
150
-
151
-			$params[$key] = $parameter;
152
-		}
153
-
154
-		return [$combined, $params];
155
-	}
156
-
157
-	/**
158
-	 * @param array[] $parameters
159
-	 * @param string $mergeParameter
160
-	 * @param array $parameter
161
-	 * @return bool
162
-	 */
163
-	protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) {
164
-		foreach ($parameters as $key => $param) {
165
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
166
-				if ($param === $parameter) {
167
-					return true;
168
-				}
169
-			}
170
-		}
171
-		return false;
172
-	}
173
-
174
-	/**
175
-	 * @param string $subject
176
-	 * @param string $parameter
177
-	 * @param int $counter
178
-	 * @return mixed
179
-	 */
180
-	protected function getExtendedSubject($subject, $parameter, $counter) {
181
-		switch ($counter) {
182
-			case 1:
183
-				$replacement = '{' . $parameter . '1}';
184
-				break;
185
-			case 2:
186
-				$replacement = $this->l10n->t(
187
-					'%1$s and %2$s',
188
-					['{' . $parameter . '2}', '{' . $parameter . '1}']
189
-				);
190
-				break;
191
-			case 3:
192
-				$replacement = $this->l10n->t(
193
-					'%1$s, %2$s and %3$s',
194
-					['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
195
-				);
196
-				break;
197
-			case 4:
198
-				$replacement = $this->l10n->t(
199
-					'%1$s, %2$s, %3$s and %4$s',
200
-					['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
201
-				);
202
-				break;
203
-			case 5:
204
-				$replacement = $this->l10n->t(
205
-					'%1$s, %2$s, %3$s, %4$s and %5$s',
206
-					['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
207
-				);
208
-				break;
209
-			default:
210
-				throw new \UnexpectedValueException();
211
-		}
212
-
213
-		return str_replace(
214
-			'{' . $parameter . '}',
215
-			$replacement,
216
-			$subject
217
-		);
218
-	}
219
-
220
-	/**
221
-	 * @param string $subject
222
-	 * @param array[] $parameters
223
-	 * @return string
224
-	 */
225
-	protected function generateParsedSubject($subject, $parameters) {
226
-		$placeholders = $replacements = [];
227
-		foreach ($parameters as $placeholder => $parameter) {
228
-			$placeholders[] = '{' . $placeholder . '}';
229
-			if ($parameter['type'] === 'file') {
230
-				$replacements[] = trim($parameter['path'], '/');
231
-			} elseif (isset($parameter['name'])) {
232
-				$replacements[] = $parameter['name'];
233
-			} else {
234
-				$replacements[] = $parameter['id'];
235
-			}
236
-		}
237
-
238
-		return str_replace($placeholders, $replacements, $subject);
239
-	}
13
+    /** @var IL10N */
14
+    protected $l10n;
15
+
16
+    /**
17
+     * @param IL10N $l10n
18
+     */
19
+    public function __construct(IL10N $l10n) {
20
+        $this->l10n = $l10n;
21
+    }
22
+
23
+    /**
24
+     * Combines two events when possible to have grouping:
25
+     *
26
+     * Example1: Two events with subject '{user} created {file}' and
27
+     * $mergeParameter file with different file and same user will be merged
28
+     * to '{user} created {file1} and {file2}' and the childEvent on the return
29
+     * will be set, if the events have been merged.
30
+     *
31
+     * Example2: Two events with subject '{user} created {file}' and
32
+     * $mergeParameter file with same file and same user will be merged to
33
+     * '{user} created {file1}' and the childEvent on the return will be set, if
34
+     * the events have been merged.
35
+     *
36
+     * The following requirements have to be met, in order to be merged:
37
+     * - Both events need to have the same `getApp()`
38
+     * - Both events must not have a message `getMessage()`
39
+     * - Both events need to have the same subject `getSubject()`
40
+     * - Both events need to have the same object type `getObjectType()`
41
+     * - The time difference between both events must not be bigger then 3 hours
42
+     * - Only up to 5 events can be merged.
43
+     * - All parameters apart from such starting with $mergeParameter must be
44
+     *   the same for both events.
45
+     *
46
+     * @param string $mergeParameter
47
+     * @param IEvent $event
48
+     * @param IEvent|null $previousEvent
49
+     * @return IEvent
50
+     */
51
+    public function mergeEvents($mergeParameter, IEvent $event, ?IEvent $previousEvent = null) {
52
+        // No second event => can not combine
53
+        if (!$previousEvent instanceof IEvent) {
54
+            return $event;
55
+        }
56
+
57
+        // Different app => can not combine
58
+        if ($event->getApp() !== $previousEvent->getApp()) {
59
+            return $event;
60
+        }
61
+
62
+        // Message is set => can not combine
63
+        if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') {
64
+            return $event;
65
+        }
66
+
67
+        // Different subject => can not combine
68
+        if ($event->getSubject() !== $previousEvent->getSubject()) {
69
+            return $event;
70
+        }
71
+
72
+        // Different object type => can not combine
73
+        if ($event->getObjectType() !== $previousEvent->getObjectType()) {
74
+            return $event;
75
+        }
76
+
77
+        // More than 3 hours difference => can not combine
78
+        if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) {
79
+            return $event;
80
+        }
81
+
82
+        // Other parameters are not the same => can not combine
83
+        try {
84
+            [$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent);
85
+        } catch (\UnexpectedValueException $e) {
86
+            return $event;
87
+        }
88
+
89
+        try {
90
+            $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined);
91
+            $parsedSubject = $this->generateParsedSubject($newSubject, $parameters);
92
+
93
+            $event->setRichSubject($newSubject, $parameters)
94
+                ->setParsedSubject($parsedSubject)
95
+                ->setChildEvent($previousEvent)
96
+                ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp()));
97
+        } catch (\UnexpectedValueException $e) {
98
+            return $event;
99
+        }
100
+
101
+        return $event;
102
+    }
103
+
104
+    /**
105
+     * @param string $mergeParameter
106
+     * @param IEvent $event
107
+     * @param IEvent $previousEvent
108
+     * @return array
109
+     * @throws \UnexpectedValueException
110
+     */
111
+    protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) {
112
+        $params1 = $event->getRichSubjectParameters();
113
+        $params2 = $previousEvent->getRichSubjectParameters();
114
+        $params = [];
115
+
116
+        $combined = 0;
117
+
118
+        // Check that all parameters from $event exist in $previousEvent
119
+        foreach ($params1 as $key => $parameter) {
120
+            if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
121
+                if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
122
+                    $combined++;
123
+                    $params[$mergeParameter . $combined] = $parameter;
124
+                }
125
+                continue;
126
+            }
127
+
128
+            if (!isset($params2[$key]) || $params2[$key] !== $parameter) {
129
+                // Parameter missing on $previousEvent or different => can not combine
130
+                throw new \UnexpectedValueException();
131
+            }
132
+
133
+            $params[$key] = $parameter;
134
+        }
135
+
136
+        // Check that all parameters from $previousEvent exist in $event
137
+        foreach ($params2 as $key => $parameter) {
138
+            if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
139
+                if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
140
+                    $combined++;
141
+                    $params[$mergeParameter . $combined] = $parameter;
142
+                }
143
+                continue;
144
+            }
145
+
146
+            if (!isset($params1[$key]) || $params1[$key] !== $parameter) {
147
+                // Parameter missing on $event or different => can not combine
148
+                throw new \UnexpectedValueException();
149
+            }
150
+
151
+            $params[$key] = $parameter;
152
+        }
153
+
154
+        return [$combined, $params];
155
+    }
156
+
157
+    /**
158
+     * @param array[] $parameters
159
+     * @param string $mergeParameter
160
+     * @param array $parameter
161
+     * @return bool
162
+     */
163
+    protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) {
164
+        foreach ($parameters as $key => $param) {
165
+            if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
166
+                if ($param === $parameter) {
167
+                    return true;
168
+                }
169
+            }
170
+        }
171
+        return false;
172
+    }
173
+
174
+    /**
175
+     * @param string $subject
176
+     * @param string $parameter
177
+     * @param int $counter
178
+     * @return mixed
179
+     */
180
+    protected function getExtendedSubject($subject, $parameter, $counter) {
181
+        switch ($counter) {
182
+            case 1:
183
+                $replacement = '{' . $parameter . '1}';
184
+                break;
185
+            case 2:
186
+                $replacement = $this->l10n->t(
187
+                    '%1$s and %2$s',
188
+                    ['{' . $parameter . '2}', '{' . $parameter . '1}']
189
+                );
190
+                break;
191
+            case 3:
192
+                $replacement = $this->l10n->t(
193
+                    '%1$s, %2$s and %3$s',
194
+                    ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
195
+                );
196
+                break;
197
+            case 4:
198
+                $replacement = $this->l10n->t(
199
+                    '%1$s, %2$s, %3$s and %4$s',
200
+                    ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
201
+                );
202
+                break;
203
+            case 5:
204
+                $replacement = $this->l10n->t(
205
+                    '%1$s, %2$s, %3$s, %4$s and %5$s',
206
+                    ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
207
+                );
208
+                break;
209
+            default:
210
+                throw new \UnexpectedValueException();
211
+        }
212
+
213
+        return str_replace(
214
+            '{' . $parameter . '}',
215
+            $replacement,
216
+            $subject
217
+        );
218
+    }
219
+
220
+    /**
221
+     * @param string $subject
222
+     * @param array[] $parameters
223
+     * @return string
224
+     */
225
+    protected function generateParsedSubject($subject, $parameters) {
226
+        $placeholders = $replacements = [];
227
+        foreach ($parameters as $placeholder => $parameter) {
228
+            $placeholders[] = '{' . $placeholder . '}';
229
+            if ($parameter['type'] === 'file') {
230
+                $replacements[] = trim($parameter['path'], '/');
231
+            } elseif (isset($parameter['name'])) {
232
+                $replacements[] = $parameter['name'];
233
+            } else {
234
+                $replacements[] = $parameter['id'];
235
+            }
236
+        }
237
+
238
+        return str_replace($placeholders, $replacements, $subject);
239
+    }
240 240
 }
Please login to merge, or discard this patch.
lib/private/Encryption/Exceptions/EncryptionHeaderToLargeException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 use OCP\Encryption\Exceptions\GenericEncryptionException;
28 28
 
29 29
 class EncryptionHeaderToLargeException extends GenericEncryptionException {
30
-	public function __construct() {
31
-		parent::__construct('max header size exceeded');
32
-	}
30
+    public function __construct() {
31
+        parent::__construct('max header size exceeded');
32
+    }
33 33
 }
Please login to merge, or discard this patch.
lib/private/Encryption/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 		// always add owner to the list of users with access to the file
74 74
 		$userIds = [$owner];
75 75
 
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
76
+		if (!$this->util->isFile($owner.'/'.$ownerPath)) {
77 77
 			return ['users' => $userIds, 'public' => false];
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -15,98 +15,98 @@
 block discarded – undo
15 15
 use OCP\Share\IManager;
16 16
 
17 17
 class File implements \OCP\Encryption\IFile {
18
-	protected Util $util;
19
-	private IRootFolder $rootFolder;
20
-	private IManager $shareManager;
21
-
22
-	/**
23
-	 * Cache results of already checked folders
24
-	 * @var CappedMemoryCache<array>
25
-	 */
26
-	protected CappedMemoryCache $cache;
27
-	private ?IAppManager $appManager = null;
28
-
29
-	public function __construct(Util $util,
30
-		IRootFolder $rootFolder,
31
-		IManager $shareManager) {
32
-		$this->util = $util;
33
-		$this->cache = new CappedMemoryCache();
34
-		$this->rootFolder = $rootFolder;
35
-		$this->shareManager = $shareManager;
36
-	}
37
-
38
-	public function getAppManager(): IAppManager {
39
-		// Lazy evaluate app manager as it initialize the db too early otherwise
40
-		if ($this->appManager) {
41
-			return $this->appManager;
42
-		}
43
-		$this->appManager = \OCP\Server::get(IAppManager::class);
44
-		return $this->appManager;
45
-	}
46
-
47
-	/**
48
-	 * Get list of users with access to the file
49
-	 *
50
-	 * @param string $path to the file
51
-	 * @return array{users: string[], public: bool}
52
-	 */
53
-	public function getAccessList($path) {
54
-		// Make sure that a share key is generated for the owner too
55
-		[$owner, $ownerPath] = $this->util->getUidAndFilename($path);
56
-
57
-		// always add owner to the list of users with access to the file
58
-		$userIds = [$owner];
59
-
60
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
61
-			return ['users' => $userIds, 'public' => false];
62
-		}
63
-
64
-		$ownerPath = substr($ownerPath, strlen('/files'));
65
-		$userFolder = $this->rootFolder->getUserFolder($owner);
66
-		try {
67
-			$file = $userFolder->get($ownerPath);
68
-		} catch (NotFoundException $e) {
69
-			$file = null;
70
-		}
71
-		$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
72
-
73
-		// first get the shares for the parent and cache the result so that we don't
74
-		// need to check all parents for every file
75
-		$parent = dirname($ownerPath);
76
-		$parentNode = $userFolder->get($parent);
77
-		if (isset($this->cache[$parent])) {
78
-			$resultForParents = $this->cache[$parent];
79
-		} else {
80
-			$resultForParents = $this->shareManager->getAccessList($parentNode);
81
-			$this->cache[$parent] = $resultForParents;
82
-		}
83
-		$userIds = array_merge($userIds, $resultForParents['users']);
84
-		$public = $resultForParents['public'] || $resultForParents['remote'];
85
-
86
-
87
-		// Find out who, if anyone, is sharing the file
88
-		if ($file !== null) {
89
-			$resultForFile = $this->shareManager->getAccessList($file, false);
90
-			$userIds = array_merge($userIds, $resultForFile['users']);
91
-			$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
92
-		}
93
-
94
-		// check if it is a group mount
95
-		if ($this->getAppManager()->isEnabledForUser('files_external')) {
96
-			/** @var GlobalStoragesService $storageService */
97
-			$storageService = \OC::$server->get(GlobalStoragesService::class);
98
-			$storages = $storageService->getAllStorages();
99
-			foreach ($storages as $storage) {
100
-				if ($storage->getMountPoint() == substr($ownerPath, 0, strlen($storage->getMountPoint()))) {
101
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($storage->getApplicableUsers(), $storage->getApplicableGroups());
102
-					$userIds = array_merge($userIds, $mountedFor);
103
-				}
104
-			}
105
-		}
106
-
107
-		// Remove duplicate UIDs
108
-		$uniqueUserIds = array_unique($userIds);
109
-
110
-		return ['users' => $uniqueUserIds, 'public' => $public];
111
-	}
18
+    protected Util $util;
19
+    private IRootFolder $rootFolder;
20
+    private IManager $shareManager;
21
+
22
+    /**
23
+     * Cache results of already checked folders
24
+     * @var CappedMemoryCache<array>
25
+     */
26
+    protected CappedMemoryCache $cache;
27
+    private ?IAppManager $appManager = null;
28
+
29
+    public function __construct(Util $util,
30
+        IRootFolder $rootFolder,
31
+        IManager $shareManager) {
32
+        $this->util = $util;
33
+        $this->cache = new CappedMemoryCache();
34
+        $this->rootFolder = $rootFolder;
35
+        $this->shareManager = $shareManager;
36
+    }
37
+
38
+    public function getAppManager(): IAppManager {
39
+        // Lazy evaluate app manager as it initialize the db too early otherwise
40
+        if ($this->appManager) {
41
+            return $this->appManager;
42
+        }
43
+        $this->appManager = \OCP\Server::get(IAppManager::class);
44
+        return $this->appManager;
45
+    }
46
+
47
+    /**
48
+     * Get list of users with access to the file
49
+     *
50
+     * @param string $path to the file
51
+     * @return array{users: string[], public: bool}
52
+     */
53
+    public function getAccessList($path) {
54
+        // Make sure that a share key is generated for the owner too
55
+        [$owner, $ownerPath] = $this->util->getUidAndFilename($path);
56
+
57
+        // always add owner to the list of users with access to the file
58
+        $userIds = [$owner];
59
+
60
+        if (!$this->util->isFile($owner . '/' . $ownerPath)) {
61
+            return ['users' => $userIds, 'public' => false];
62
+        }
63
+
64
+        $ownerPath = substr($ownerPath, strlen('/files'));
65
+        $userFolder = $this->rootFolder->getUserFolder($owner);
66
+        try {
67
+            $file = $userFolder->get($ownerPath);
68
+        } catch (NotFoundException $e) {
69
+            $file = null;
70
+        }
71
+        $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
72
+
73
+        // first get the shares for the parent and cache the result so that we don't
74
+        // need to check all parents for every file
75
+        $parent = dirname($ownerPath);
76
+        $parentNode = $userFolder->get($parent);
77
+        if (isset($this->cache[$parent])) {
78
+            $resultForParents = $this->cache[$parent];
79
+        } else {
80
+            $resultForParents = $this->shareManager->getAccessList($parentNode);
81
+            $this->cache[$parent] = $resultForParents;
82
+        }
83
+        $userIds = array_merge($userIds, $resultForParents['users']);
84
+        $public = $resultForParents['public'] || $resultForParents['remote'];
85
+
86
+
87
+        // Find out who, if anyone, is sharing the file
88
+        if ($file !== null) {
89
+            $resultForFile = $this->shareManager->getAccessList($file, false);
90
+            $userIds = array_merge($userIds, $resultForFile['users']);
91
+            $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
92
+        }
93
+
94
+        // check if it is a group mount
95
+        if ($this->getAppManager()->isEnabledForUser('files_external')) {
96
+            /** @var GlobalStoragesService $storageService */
97
+            $storageService = \OC::$server->get(GlobalStoragesService::class);
98
+            $storages = $storageService->getAllStorages();
99
+            foreach ($storages as $storage) {
100
+                if ($storage->getMountPoint() == substr($ownerPath, 0, strlen($storage->getMountPoint()))) {
101
+                    $mountedFor = $this->util->getUserWithAccessToMountPoint($storage->getApplicableUsers(), $storage->getApplicableGroups());
102
+                    $userIds = array_merge($userIds, $mountedFor);
103
+                }
104
+            }
105
+        }
106
+
107
+        // Remove duplicate UIDs
108
+        $uniqueUserIds = array_unique($userIds);
109
+
110
+        return ['users' => $uniqueUserIds, 'public' => $public];
111
+    }
112 112
 }
Please login to merge, or discard this patch.
Middleware/Security/Exceptions/StrictCookieMissingException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
  * @package OC\AppFramework\Middleware\Security\Exceptions
33 33
  */
34 34
 class StrictCookieMissingException extends SecurityException {
35
-	public function __construct() {
36
-		parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
-	}
35
+    public function __construct() {
36
+        parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/dav/lib/Comments/RootCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
 		if (isset($this->entityTypeCollections[$name])) {
148 148
 			return $this->entityTypeCollections[$name];
149 149
 		}
150
-		throw new NotFound('Entity type "' . $name . '" not found."');
150
+		throw new NotFound('Entity type "'.$name.'" not found."');
151 151
 	}
152 152
 
153 153
 	/**
Please login to merge, or discard this patch.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -19,151 +19,151 @@
 block discarded – undo
19 19
 use Sabre\DAV\ICollection;
20 20
 
21 21
 class RootCollection implements ICollection {
22
-	/** @var EntityTypeCollection[]|null */
23
-	private ?array $entityTypeCollections = null;
24
-	protected string $name = 'comments';
25
-
26
-	public function __construct(
27
-		protected ICommentsManager $commentsManager,
28
-		protected IUserManager $userManager,
29
-		protected IUserSession $userSession,
30
-		protected IEventDispatcher $dispatcher,
31
-		protected LoggerInterface $logger,
32
-	) {
33
-	}
34
-
35
-	/**
36
-	 * initializes the collection. At this point of time, we need the logged in
37
-	 * user. Since it is not the case when the instance is created, we cannot
38
-	 * have this in the constructor.
39
-	 *
40
-	 * @throws NotAuthenticated
41
-	 */
42
-	protected function initCollections() {
43
-		if ($this->entityTypeCollections !== null) {
44
-			return;
45
-		}
46
-		$user = $this->userSession->getUser();
47
-		if (is_null($user)) {
48
-			throw new NotAuthenticated();
49
-		}
50
-
51
-		$event = new CommentsEntityEvent();
52
-		$this->dispatcher->dispatchTyped($event);
53
-		$this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
54
-
55
-		$this->entityTypeCollections = [];
56
-		foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
57
-			$this->entityTypeCollections[$entity] = new EntityTypeCollection(
58
-				$entity,
59
-				$this->commentsManager,
60
-				$this->userManager,
61
-				$this->userSession,
62
-				$this->logger,
63
-				$entityExistsFunction
64
-			);
65
-		}
66
-	}
67
-
68
-	/**
69
-	 * Creates a new file in the directory
70
-	 *
71
-	 * @param string $name Name of the file
72
-	 * @param resource|string $data Initial payload
73
-	 * @return null|string
74
-	 * @throws Forbidden
75
-	 */
76
-	public function createFile($name, $data = null) {
77
-		throw new Forbidden('Cannot create comments by id');
78
-	}
79
-
80
-	/**
81
-	 * Creates a new subdirectory
82
-	 *
83
-	 * @param string $name
84
-	 * @throws Forbidden
85
-	 */
86
-	public function createDirectory($name) {
87
-		throw new Forbidden('Permission denied to create collections');
88
-	}
89
-
90
-	/**
91
-	 * Returns a specific child node, referenced by its name
92
-	 *
93
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
94
-	 * exist.
95
-	 *
96
-	 * @param string $name
97
-	 * @return \Sabre\DAV\INode
98
-	 * @throws NotFound
99
-	 */
100
-	public function getChild($name) {
101
-		$this->initCollections();
102
-		if (isset($this->entityTypeCollections[$name])) {
103
-			return $this->entityTypeCollections[$name];
104
-		}
105
-		throw new NotFound('Entity type "' . $name . '" not found."');
106
-	}
107
-
108
-	/**
109
-	 * Returns an array with all the child nodes
110
-	 *
111
-	 * @return \Sabre\DAV\INode[]
112
-	 */
113
-	public function getChildren() {
114
-		$this->initCollections();
115
-		assert(!is_null($this->entityTypeCollections));
116
-		return $this->entityTypeCollections;
117
-	}
118
-
119
-	/**
120
-	 * Checks if a child-node with the specified name exists
121
-	 *
122
-	 * @param string $name
123
-	 * @return bool
124
-	 */
125
-	public function childExists($name) {
126
-		$this->initCollections();
127
-		assert(!is_null($this->entityTypeCollections));
128
-		return isset($this->entityTypeCollections[$name]);
129
-	}
130
-
131
-	/**
132
-	 * Deleted the current node
133
-	 *
134
-	 * @throws Forbidden
135
-	 */
136
-	public function delete() {
137
-		throw new Forbidden('Permission denied to delete this collection');
138
-	}
139
-
140
-	/**
141
-	 * Returns the name of the node.
142
-	 *
143
-	 * This is used to generate the url.
144
-	 *
145
-	 * @return string
146
-	 */
147
-	public function getName() {
148
-		return $this->name;
149
-	}
150
-
151
-	/**
152
-	 * Renames the node
153
-	 *
154
-	 * @param string $name The new name
155
-	 * @throws Forbidden
156
-	 */
157
-	public function setName($name) {
158
-		throw new Forbidden('Permission denied to rename this collection');
159
-	}
160
-
161
-	/**
162
-	 * Returns the last modification time, as a unix timestamp
163
-	 *
164
-	 * @return ?int
165
-	 */
166
-	public function getLastModified() {
167
-		return null;
168
-	}
22
+    /** @var EntityTypeCollection[]|null */
23
+    private ?array $entityTypeCollections = null;
24
+    protected string $name = 'comments';
25
+
26
+    public function __construct(
27
+        protected ICommentsManager $commentsManager,
28
+        protected IUserManager $userManager,
29
+        protected IUserSession $userSession,
30
+        protected IEventDispatcher $dispatcher,
31
+        protected LoggerInterface $logger,
32
+    ) {
33
+    }
34
+
35
+    /**
36
+     * initializes the collection. At this point of time, we need the logged in
37
+     * user. Since it is not the case when the instance is created, we cannot
38
+     * have this in the constructor.
39
+     *
40
+     * @throws NotAuthenticated
41
+     */
42
+    protected function initCollections() {
43
+        if ($this->entityTypeCollections !== null) {
44
+            return;
45
+        }
46
+        $user = $this->userSession->getUser();
47
+        if (is_null($user)) {
48
+            throw new NotAuthenticated();
49
+        }
50
+
51
+        $event = new CommentsEntityEvent();
52
+        $this->dispatcher->dispatchTyped($event);
53
+        $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
54
+
55
+        $this->entityTypeCollections = [];
56
+        foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
57
+            $this->entityTypeCollections[$entity] = new EntityTypeCollection(
58
+                $entity,
59
+                $this->commentsManager,
60
+                $this->userManager,
61
+                $this->userSession,
62
+                $this->logger,
63
+                $entityExistsFunction
64
+            );
65
+        }
66
+    }
67
+
68
+    /**
69
+     * Creates a new file in the directory
70
+     *
71
+     * @param string $name Name of the file
72
+     * @param resource|string $data Initial payload
73
+     * @return null|string
74
+     * @throws Forbidden
75
+     */
76
+    public function createFile($name, $data = null) {
77
+        throw new Forbidden('Cannot create comments by id');
78
+    }
79
+
80
+    /**
81
+     * Creates a new subdirectory
82
+     *
83
+     * @param string $name
84
+     * @throws Forbidden
85
+     */
86
+    public function createDirectory($name) {
87
+        throw new Forbidden('Permission denied to create collections');
88
+    }
89
+
90
+    /**
91
+     * Returns a specific child node, referenced by its name
92
+     *
93
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
94
+     * exist.
95
+     *
96
+     * @param string $name
97
+     * @return \Sabre\DAV\INode
98
+     * @throws NotFound
99
+     */
100
+    public function getChild($name) {
101
+        $this->initCollections();
102
+        if (isset($this->entityTypeCollections[$name])) {
103
+            return $this->entityTypeCollections[$name];
104
+        }
105
+        throw new NotFound('Entity type "' . $name . '" not found."');
106
+    }
107
+
108
+    /**
109
+     * Returns an array with all the child nodes
110
+     *
111
+     * @return \Sabre\DAV\INode[]
112
+     */
113
+    public function getChildren() {
114
+        $this->initCollections();
115
+        assert(!is_null($this->entityTypeCollections));
116
+        return $this->entityTypeCollections;
117
+    }
118
+
119
+    /**
120
+     * Checks if a child-node with the specified name exists
121
+     *
122
+     * @param string $name
123
+     * @return bool
124
+     */
125
+    public function childExists($name) {
126
+        $this->initCollections();
127
+        assert(!is_null($this->entityTypeCollections));
128
+        return isset($this->entityTypeCollections[$name]);
129
+    }
130
+
131
+    /**
132
+     * Deleted the current node
133
+     *
134
+     * @throws Forbidden
135
+     */
136
+    public function delete() {
137
+        throw new Forbidden('Permission denied to delete this collection');
138
+    }
139
+
140
+    /**
141
+     * Returns the name of the node.
142
+     *
143
+     * This is used to generate the url.
144
+     *
145
+     * @return string
146
+     */
147
+    public function getName() {
148
+        return $this->name;
149
+    }
150
+
151
+    /**
152
+     * Renames the node
153
+     *
154
+     * @param string $name The new name
155
+     * @throws Forbidden
156
+     */
157
+    public function setName($name) {
158
+        throw new Forbidden('Permission denied to rename this collection');
159
+    }
160
+
161
+    /**
162
+     * Returns the last modification time, as a unix timestamp
163
+     *
164
+     * @return ?int
165
+     */
166
+    public function getLastModified() {
167
+        return null;
168
+    }
169 169
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/Xml/Groups.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
 
40 40
 	public function xmlSerialize(Writer $writer) {
41 41
 		foreach ($this->groups as $group) {
42
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group);
42
+			$writer->writeElement('{'.self::NS_OWNCLOUD.'}group', $group);
43 43
 		}
44 44
 	}
45 45
 }
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@
 block discarded – undo
11 11
 use Sabre\Xml\XmlSerializable;
12 12
 
13 13
 class Groups implements XmlSerializable {
14
-	public const NS_OWNCLOUD = 'http://owncloud.org/ns';
14
+    public const NS_OWNCLOUD = 'http://owncloud.org/ns';
15 15
 
16
-	/**
17
-	 * @param list<string> $groups
18
-	 */
19
-	public function __construct(
20
-		private array $groups,
21
-	) {
22
-	}
16
+    /**
17
+     * @param list<string> $groups
18
+     */
19
+    public function __construct(
20
+        private array $groups,
21
+    ) {
22
+    }
23 23
 
24
-	public function xmlSerialize(Writer $writer) {
25
-		foreach ($this->groups as $group) {
26
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group);
27
-		}
28
-	}
24
+    public function xmlSerialize(Writer $writer) {
25
+        foreach ($this->groups as $group) {
26
+            $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group);
27
+        }
28
+    }
29 29
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Xml/Invite.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -116,42 +116,42 @@
 block discarded – undo
116 116
 	 * @return void
117 117
 	 */
118 118
 	public function xmlSerialize(Writer $writer) {
119
-		$cs = '{' . Plugin::NS_OWNCLOUD . '}';
119
+		$cs = '{'.Plugin::NS_OWNCLOUD.'}';
120 120
 
121 121
 		if (!is_null($this->organizer)) {
122
-			$writer->startElement($cs . 'organizer');
122
+			$writer->startElement($cs.'organizer');
123 123
 			$writer->writeElement('{DAV:}href', $this->organizer['href']);
124 124
 
125 125
 			if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
126
-				$writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
126
+				$writer->writeElement($cs.'common-name', $this->organizer['commonName']);
127 127
 			}
128 128
 			if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
129
-				$writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
129
+				$writer->writeElement($cs.'first-name', $this->organizer['firstName']);
130 130
 			}
131 131
 			if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
132
-				$writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
132
+				$writer->writeElement($cs.'last-name', $this->organizer['lastName']);
133 133
 			}
134 134
 			$writer->endElement(); // organizer
135 135
 		}
136 136
 
137 137
 		foreach ($this->users as $user) {
138
-			$writer->startElement($cs . 'user');
138
+			$writer->startElement($cs.'user');
139 139
 			$writer->writeElement('{DAV:}href', $user['href']);
140 140
 			if (isset($user['commonName']) && $user['commonName']) {
141
-				$writer->writeElement($cs . 'common-name', $user['commonName']);
141
+				$writer->writeElement($cs.'common-name', $user['commonName']);
142 142
 			}
143
-			$writer->writeElement($cs . 'invite-accepted');
143
+			$writer->writeElement($cs.'invite-accepted');
144 144
 
145
-			$writer->startElement($cs . 'access');
145
+			$writer->startElement($cs.'access');
146 146
 			if ($user['readOnly']) {
147
-				$writer->writeElement($cs . 'read');
147
+				$writer->writeElement($cs.'read');
148 148
 			} else {
149
-				$writer->writeElement($cs . 'read-write');
149
+				$writer->writeElement($cs.'read-write');
150 150
 			}
151 151
 			$writer->endElement(); // access
152 152
 
153 153
 			if (isset($user['summary']) && $user['summary']) {
154
-				$writer->writeElement($cs . 'summary', $user['summary']);
154
+				$writer->writeElement($cs.'summary', $user['summary']);
155 155
 			}
156 156
 
157 157
 			$writer->endElement(); //user
Please login to merge, or discard this patch.
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -26,113 +26,113 @@
 block discarded – undo
26 26
  */
27 27
 class Invite implements XmlSerializable {
28 28
 
29
-	/**
30
-	 * Creates the property.
31
-	 *
32
-	 * Users is an array. Each element of the array has the following
33
-	 * properties:
34
-	 *
35
-	 *   * href - Often a mailto: address
36
-	 *   * commonName - Optional, for example a first and lastname for a user.
37
-	 *   * status - One of the SharingPlugin::STATUS_* constants.
38
-	 *   * readOnly - true or false
39
-	 *   * summary - Optional, description of the share
40
-	 *
41
-	 * The organizer key is optional to specify. It's only useful when a
42
-	 * 'sharee' requests the sharing information.
43
-	 *
44
-	 * The organizer may have the following properties:
45
-	 *   * href - Often a mailto: address.
46
-	 *   * commonName - Optional human-readable name.
47
-	 *   * firstName - Optional first name.
48
-	 *   * lastName - Optional last name.
49
-	 *
50
-	 * If you wonder why these two structures are so different, I guess a
51
-	 * valid answer is that the current spec is still a draft.
52
-	 *
53
-	 * @param array $users
54
-	 */
55
-	public function __construct(
56
-		/**
57
-		 * The list of users a calendar has been shared to.
58
-		 */
59
-		protected array $users,
60
-		/**
61
-		 * The organizer contains information about the person who shared the
62
-		 * object.
63
-		 */
64
-		protected ?array $organizer = null,
65
-	) {
66
-	}
29
+    /**
30
+     * Creates the property.
31
+     *
32
+     * Users is an array. Each element of the array has the following
33
+     * properties:
34
+     *
35
+     *   * href - Often a mailto: address
36
+     *   * commonName - Optional, for example a first and lastname for a user.
37
+     *   * status - One of the SharingPlugin::STATUS_* constants.
38
+     *   * readOnly - true or false
39
+     *   * summary - Optional, description of the share
40
+     *
41
+     * The organizer key is optional to specify. It's only useful when a
42
+     * 'sharee' requests the sharing information.
43
+     *
44
+     * The organizer may have the following properties:
45
+     *   * href - Often a mailto: address.
46
+     *   * commonName - Optional human-readable name.
47
+     *   * firstName - Optional first name.
48
+     *   * lastName - Optional last name.
49
+     *
50
+     * If you wonder why these two structures are so different, I guess a
51
+     * valid answer is that the current spec is still a draft.
52
+     *
53
+     * @param array $users
54
+     */
55
+    public function __construct(
56
+        /**
57
+         * The list of users a calendar has been shared to.
58
+         */
59
+        protected array $users,
60
+        /**
61
+         * The organizer contains information about the person who shared the
62
+         * object.
63
+         */
64
+        protected ?array $organizer = null,
65
+    ) {
66
+    }
67 67
 
68
-	/**
69
-	 * Returns the list of users, as it was passed to the constructor.
70
-	 *
71
-	 * @return array
72
-	 */
73
-	public function getValue() {
74
-		return $this->users;
75
-	}
68
+    /**
69
+     * Returns the list of users, as it was passed to the constructor.
70
+     *
71
+     * @return array
72
+     */
73
+    public function getValue() {
74
+        return $this->users;
75
+    }
76 76
 
77
-	/**
78
-	 * The xmlSerialize method is called during xml writing.
79
-	 *
80
-	 * Use the $writer argument to write its own xml serialization.
81
-	 *
82
-	 * An important note: do _not_ create a parent element. Any element
83
-	 * implementing XmlSerializble should only ever write what's considered
84
-	 * its 'inner xml'.
85
-	 *
86
-	 * The parent of the current element is responsible for writing a
87
-	 * containing element.
88
-	 *
89
-	 * This allows serializers to be re-used for different element names.
90
-	 *
91
-	 * If you are opening new elements, you must also close them again.
92
-	 *
93
-	 * @param Writer $writer
94
-	 * @return void
95
-	 */
96
-	public function xmlSerialize(Writer $writer) {
97
-		$cs = '{' . Plugin::NS_OWNCLOUD . '}';
77
+    /**
78
+     * The xmlSerialize method is called during xml writing.
79
+     *
80
+     * Use the $writer argument to write its own xml serialization.
81
+     *
82
+     * An important note: do _not_ create a parent element. Any element
83
+     * implementing XmlSerializble should only ever write what's considered
84
+     * its 'inner xml'.
85
+     *
86
+     * The parent of the current element is responsible for writing a
87
+     * containing element.
88
+     *
89
+     * This allows serializers to be re-used for different element names.
90
+     *
91
+     * If you are opening new elements, you must also close them again.
92
+     *
93
+     * @param Writer $writer
94
+     * @return void
95
+     */
96
+    public function xmlSerialize(Writer $writer) {
97
+        $cs = '{' . Plugin::NS_OWNCLOUD . '}';
98 98
 
99
-		if (!is_null($this->organizer)) {
100
-			$writer->startElement($cs . 'organizer');
101
-			$writer->writeElement('{DAV:}href', $this->organizer['href']);
99
+        if (!is_null($this->organizer)) {
100
+            $writer->startElement($cs . 'organizer');
101
+            $writer->writeElement('{DAV:}href', $this->organizer['href']);
102 102
 
103
-			if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
104
-				$writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
105
-			}
106
-			if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
107
-				$writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
108
-			}
109
-			if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
110
-				$writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
111
-			}
112
-			$writer->endElement(); // organizer
113
-		}
103
+            if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
104
+                $writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
105
+            }
106
+            if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
107
+                $writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
108
+            }
109
+            if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
110
+                $writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
111
+            }
112
+            $writer->endElement(); // organizer
113
+        }
114 114
 
115
-		foreach ($this->users as $user) {
116
-			$writer->startElement($cs . 'user');
117
-			$writer->writeElement('{DAV:}href', $user['href']);
118
-			if (isset($user['commonName']) && $user['commonName']) {
119
-				$writer->writeElement($cs . 'common-name', $user['commonName']);
120
-			}
121
-			$writer->writeElement($cs . 'invite-accepted');
115
+        foreach ($this->users as $user) {
116
+            $writer->startElement($cs . 'user');
117
+            $writer->writeElement('{DAV:}href', $user['href']);
118
+            if (isset($user['commonName']) && $user['commonName']) {
119
+                $writer->writeElement($cs . 'common-name', $user['commonName']);
120
+            }
121
+            $writer->writeElement($cs . 'invite-accepted');
122 122
 
123
-			$writer->startElement($cs . 'access');
124
-			if ($user['readOnly']) {
125
-				$writer->writeElement($cs . 'read');
126
-			} else {
127
-				$writer->writeElement($cs . 'read-write');
128
-			}
129
-			$writer->endElement(); // access
123
+            $writer->startElement($cs . 'access');
124
+            if ($user['readOnly']) {
125
+                $writer->writeElement($cs . 'read');
126
+            } else {
127
+                $writer->writeElement($cs . 'read-write');
128
+            }
129
+            $writer->endElement(); // access
130 130
 
131
-			if (isset($user['summary']) && $user['summary']) {
132
-				$writer->writeElement($cs . 'summary', $user['summary']);
133
-			}
131
+            if (isset($user['summary']) && $user['summary']) {
132
+                $writer->writeElement($cs . 'summary', $user['summary']);
133
+            }
134 134
 
135
-			$writer->endElement(); //user
136
-		}
137
-	}
135
+            $writer->endElement(); //user
136
+        }
137
+    }
138 138
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/BearerAuth.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
 	private function setupUserFs($userId) {
64 64
 		\OC_Util::setupFS($userId);
65 65
 		$this->session->close();
66
-		return $this->principalPrefix . $userId;
66
+		return $this->principalPrefix.$userId;
67 67
 	}
68 68
 
69 69
 	/**
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -16,57 +16,57 @@
 block discarded – undo
16 16
 use Sabre\HTTP\ResponseInterface;
17 17
 
18 18
 class BearerAuth extends AbstractBearer {
19
-	public function __construct(
20
-		private IUserSession $userSession,
21
-		private ISession $session,
22
-		private IRequest $request,
23
-		private IConfig $config,
24
-		private string $principalPrefix = 'principals/users/',
25
-	) {
26
-		// setup realm
27
-		$defaults = new Defaults();
28
-		$this->realm = $defaults->getName() ?: 'Nextcloud';
29
-	}
19
+    public function __construct(
20
+        private IUserSession $userSession,
21
+        private ISession $session,
22
+        private IRequest $request,
23
+        private IConfig $config,
24
+        private string $principalPrefix = 'principals/users/',
25
+    ) {
26
+        // setup realm
27
+        $defaults = new Defaults();
28
+        $this->realm = $defaults->getName() ?: 'Nextcloud';
29
+    }
30 30
 
31
-	private function setupUserFs($userId) {
32
-		\OC_Util::setupFS($userId);
33
-		$this->session->close();
34
-		return $this->principalPrefix . $userId;
35
-	}
31
+    private function setupUserFs($userId) {
32
+        \OC_Util::setupFS($userId);
33
+        $this->session->close();
34
+        return $this->principalPrefix . $userId;
35
+    }
36 36
 
37
-	/**
38
-	 * {@inheritdoc}
39
-	 */
40
-	public function validateBearerToken($bearerToken) {
41
-		\OC_Util::setupFS();
37
+    /**
38
+     * {@inheritdoc}
39
+     */
40
+    public function validateBearerToken($bearerToken) {
41
+        \OC_Util::setupFS();
42 42
 
43
-		if (!$this->userSession->isLoggedIn()) {
44
-			$this->userSession->tryTokenLogin($this->request);
45
-		}
46
-		if ($this->userSession->isLoggedIn()) {
47
-			return $this->setupUserFs($this->userSession->getUser()->getUID());
48
-		}
43
+        if (!$this->userSession->isLoggedIn()) {
44
+            $this->userSession->tryTokenLogin($this->request);
45
+        }
46
+        if ($this->userSession->isLoggedIn()) {
47
+            return $this->setupUserFs($this->userSession->getUser()->getUID());
48
+        }
49 49
 
50
-		return false;
51
-	}
50
+        return false;
51
+    }
52 52
 
53
-	/**
54
-	 * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
55
-	 * header which some DAV clients can't handle. Thus we override this function
56
-	 * and make it simply return a 401.
57
-	 *
58
-	 * @param RequestInterface $request
59
-	 * @param ResponseInterface $response
60
-	 */
61
-	public function challenge(RequestInterface $request, ResponseInterface $response): void {
62
-		// Legacy ownCloud clients still authenticate via OAuth2
63
-		$enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false);
64
-		$userAgent = $request->getHeader('User-Agent');
65
-		if ($enableOcClients && $userAgent !== null && str_contains($userAgent, 'mirall')) {
66
-			parent::challenge($request, $response);
67
-			return;
68
-		}
53
+    /**
54
+     * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
55
+     * header which some DAV clients can't handle. Thus we override this function
56
+     * and make it simply return a 401.
57
+     *
58
+     * @param RequestInterface $request
59
+     * @param ResponseInterface $response
60
+     */
61
+    public function challenge(RequestInterface $request, ResponseInterface $response): void {
62
+        // Legacy ownCloud clients still authenticate via OAuth2
63
+        $enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false);
64
+        $userAgent = $request->getHeader('User-Agent');
65
+        if ($enableOcClients && $userAgent !== null && str_contains($userAgent, 'mirall')) {
66
+            parent::challenge($request, $response);
67
+            return;
68
+        }
69 69
 
70
-		$response->setStatus(Http::STATUS_UNAUTHORIZED);
71
-	}
70
+        $response->setStatus(Http::STATUS_UNAUTHORIZED);
71
+    }
72 72
 }
Please login to merge, or discard this patch.