@@ -46,379 +46,379 @@ |
||
46 | 46 | use Symfony\Component\EventDispatcher\GenericEvent; |
47 | 47 | |
48 | 48 | class Group implements IGroup { |
49 | - /** @var null|string */ |
|
50 | - protected $displayName; |
|
51 | - |
|
52 | - /** @var string */ |
|
53 | - private $gid; |
|
54 | - |
|
55 | - /** @var \OC\User\User[] */ |
|
56 | - private $users = []; |
|
57 | - |
|
58 | - /** @var bool */ |
|
59 | - private $usersLoaded; |
|
60 | - |
|
61 | - /** @var Backend[] */ |
|
62 | - private $backends; |
|
63 | - /** @var EventDispatcherInterface */ |
|
64 | - private $dispatcher; |
|
65 | - /** @var \OC\User\Manager|IUserManager */ |
|
66 | - private $userManager; |
|
67 | - /** @var PublicEmitter */ |
|
68 | - private $emitter; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $gid |
|
73 | - * @param Backend[] $backends |
|
74 | - * @param EventDispatcherInterface $dispatcher |
|
75 | - * @param IUserManager $userManager |
|
76 | - * @param PublicEmitter $emitter |
|
77 | - * @param string $displayName |
|
78 | - */ |
|
79 | - public function __construct(string $gid, array $backends, EventDispatcherInterface $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) { |
|
80 | - $this->gid = $gid; |
|
81 | - $this->backends = $backends; |
|
82 | - $this->dispatcher = $dispatcher; |
|
83 | - $this->userManager = $userManager; |
|
84 | - $this->emitter = $emitter; |
|
85 | - $this->displayName = $displayName; |
|
86 | - } |
|
87 | - |
|
88 | - public function getGID() { |
|
89 | - return $this->gid; |
|
90 | - } |
|
91 | - |
|
92 | - public function getDisplayName() { |
|
93 | - if (is_null($this->displayName)) { |
|
94 | - foreach ($this->backends as $backend) { |
|
95 | - if ($backend instanceof IGetDisplayNameBackend) { |
|
96 | - $displayName = $backend->getDisplayName($this->gid); |
|
97 | - if (trim($displayName) !== '') { |
|
98 | - $this->displayName = $displayName; |
|
99 | - return $this->displayName; |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - return $this->gid; |
|
104 | - } |
|
105 | - return $this->displayName; |
|
106 | - } |
|
107 | - |
|
108 | - public function setDisplayName(string $displayName): bool { |
|
109 | - $displayName = trim($displayName); |
|
110 | - if ($displayName !== '') { |
|
111 | - foreach ($this->backends as $backend) { |
|
112 | - if (($backend instanceof ISetDisplayNameBackend) |
|
113 | - && $backend->setDisplayName($this->gid, $displayName)) { |
|
114 | - $this->displayName = $displayName; |
|
115 | - return true; |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * get all users in the group |
|
124 | - * |
|
125 | - * @return \OC\User\User[] |
|
126 | - */ |
|
127 | - public function getUsers() { |
|
128 | - if ($this->usersLoaded) { |
|
129 | - return $this->users; |
|
130 | - } |
|
131 | - |
|
132 | - $userIds = []; |
|
133 | - foreach ($this->backends as $backend) { |
|
134 | - $diff = array_diff( |
|
135 | - $backend->usersInGroup($this->gid), |
|
136 | - $userIds |
|
137 | - ); |
|
138 | - if ($diff) { |
|
139 | - $userIds = array_merge($userIds, $diff); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - $this->users = $this->getVerifiedUsers($userIds); |
|
144 | - $this->usersLoaded = true; |
|
145 | - return $this->users; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * check if a user is in the group |
|
150 | - * |
|
151 | - * @param IUser $user |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - public function inGroup(IUser $user) { |
|
155 | - if (isset($this->users[$user->getUID()])) { |
|
156 | - return true; |
|
157 | - } |
|
158 | - foreach ($this->backends as $backend) { |
|
159 | - if ($backend->inGroup($user->getUID(), $this->gid)) { |
|
160 | - $this->users[$user->getUID()] = $user; |
|
161 | - return true; |
|
162 | - } |
|
163 | - } |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * add a user to the group |
|
169 | - * |
|
170 | - * @param IUser $user |
|
171 | - */ |
|
172 | - public function addUser(IUser $user) { |
|
173 | - if ($this->inGroup($user)) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - $this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [ |
|
178 | - 'user' => $user, |
|
179 | - ])); |
|
180 | - |
|
181 | - if ($this->emitter) { |
|
182 | - $this->emitter->emit('\OC\Group', 'preAddUser', [$this, $user]); |
|
183 | - } |
|
184 | - foreach ($this->backends as $backend) { |
|
185 | - if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { |
|
186 | - $backend->addToGroup($user->getUID(), $this->gid); |
|
187 | - if ($this->users) { |
|
188 | - $this->users[$user->getUID()] = $user; |
|
189 | - } |
|
190 | - |
|
191 | - $this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [ |
|
192 | - 'user' => $user, |
|
193 | - ])); |
|
194 | - |
|
195 | - if ($this->emitter) { |
|
196 | - $this->emitter->emit('\OC\Group', 'postAddUser', [$this, $user]); |
|
197 | - } |
|
198 | - return; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * remove a user from the group |
|
205 | - * |
|
206 | - * @param \OC\User\User $user |
|
207 | - */ |
|
208 | - public function removeUser($user) { |
|
209 | - $result = false; |
|
210 | - $this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [ |
|
211 | - 'user' => $user, |
|
212 | - ])); |
|
213 | - if ($this->emitter) { |
|
214 | - $this->emitter->emit('\OC\Group', 'preRemoveUser', [$this, $user]); |
|
215 | - } |
|
216 | - foreach ($this->backends as $backend) { |
|
217 | - if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { |
|
218 | - $backend->removeFromGroup($user->getUID(), $this->gid); |
|
219 | - $result = true; |
|
220 | - } |
|
221 | - } |
|
222 | - if ($result) { |
|
223 | - $this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [ |
|
224 | - 'user' => $user, |
|
225 | - ])); |
|
226 | - if ($this->emitter) { |
|
227 | - $this->emitter->emit('\OC\Group', 'postRemoveUser', [$this, $user]); |
|
228 | - } |
|
229 | - if ($this->users) { |
|
230 | - foreach ($this->users as $index => $groupUser) { |
|
231 | - if ($groupUser->getUID() === $user->getUID()) { |
|
232 | - unset($this->users[$index]); |
|
233 | - return; |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * search for users in the group by userid |
|
242 | - * |
|
243 | - * @param string $search |
|
244 | - * @param int $limit |
|
245 | - * @param int $offset |
|
246 | - * @return \OC\User\User[] |
|
247 | - */ |
|
248 | - public function searchUsers($search, $limit = null, $offset = null) { |
|
249 | - $users = []; |
|
250 | - foreach ($this->backends as $backend) { |
|
251 | - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
252 | - $users += $this->getVerifiedUsers($userIds); |
|
253 | - if (!is_null($limit) and $limit <= 0) { |
|
254 | - return $users; |
|
255 | - } |
|
256 | - } |
|
257 | - return $users; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * returns the number of users matching the search string |
|
262 | - * |
|
263 | - * @param string $search |
|
264 | - * @return int|bool |
|
265 | - */ |
|
266 | - public function count($search = '') { |
|
267 | - $users = false; |
|
268 | - foreach ($this->backends as $backend) { |
|
269 | - if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { |
|
270 | - if ($users === false) { |
|
271 | - //we could directly add to a bool variable, but this would |
|
272 | - //be ugly |
|
273 | - $users = 0; |
|
274 | - } |
|
275 | - $users += $backend->countUsersInGroup($this->gid, $search); |
|
276 | - } |
|
277 | - } |
|
278 | - return $users; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * returns the number of disabled users |
|
283 | - * |
|
284 | - * @return int|bool |
|
285 | - */ |
|
286 | - public function countDisabled() { |
|
287 | - $users = false; |
|
288 | - foreach ($this->backends as $backend) { |
|
289 | - if ($backend instanceof ICountDisabledInGroup) { |
|
290 | - if ($users === false) { |
|
291 | - //we could directly add to a bool variable, but this would |
|
292 | - //be ugly |
|
293 | - $users = 0; |
|
294 | - } |
|
295 | - $users += $backend->countDisabledInGroup($this->gid); |
|
296 | - } |
|
297 | - } |
|
298 | - return $users; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * search for users in the group by displayname |
|
303 | - * |
|
304 | - * @param string $search |
|
305 | - * @param int $limit |
|
306 | - * @param int $offset |
|
307 | - * @return \OC\User\User[] |
|
308 | - */ |
|
309 | - public function searchDisplayName($search, $limit = null, $offset = null) { |
|
310 | - $users = []; |
|
311 | - foreach ($this->backends as $backend) { |
|
312 | - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
313 | - $users = $this->getVerifiedUsers($userIds); |
|
314 | - if (!is_null($limit) and $limit <= 0) { |
|
315 | - return array_values($users); |
|
316 | - } |
|
317 | - } |
|
318 | - return array_values($users); |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Get the names of the backend classes the group is connected to |
|
323 | - * |
|
324 | - * @return string[] |
|
325 | - */ |
|
326 | - public function getBackendNames() { |
|
327 | - $backends = []; |
|
328 | - foreach ($this->backends as $backend) { |
|
329 | - if ($backend instanceof INamedBackend) { |
|
330 | - $backends[] = $backend->getBackendName(); |
|
331 | - } else { |
|
332 | - $backends[] = get_class($backend); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - return $backends; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * delete the group |
|
341 | - * |
|
342 | - * @return bool |
|
343 | - */ |
|
344 | - public function delete() { |
|
345 | - // Prevent users from deleting group admin |
|
346 | - if ($this->getGID() === 'admin') { |
|
347 | - return false; |
|
348 | - } |
|
349 | - |
|
350 | - $result = false; |
|
351 | - $this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this)); |
|
352 | - if ($this->emitter) { |
|
353 | - $this->emitter->emit('\OC\Group', 'preDelete', [$this]); |
|
354 | - } |
|
355 | - foreach ($this->backends as $backend) { |
|
356 | - if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { |
|
357 | - $result = true; |
|
358 | - $backend->deleteGroup($this->gid); |
|
359 | - } |
|
360 | - } |
|
361 | - if ($result) { |
|
362 | - $this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this)); |
|
363 | - if ($this->emitter) { |
|
364 | - $this->emitter->emit('\OC\Group', 'postDelete', [$this]); |
|
365 | - } |
|
366 | - } |
|
367 | - return $result; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * returns all the Users from an array that really exists |
|
372 | - * @param string[] $userIds an array containing user IDs |
|
373 | - * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value |
|
374 | - */ |
|
375 | - private function getVerifiedUsers($userIds) { |
|
376 | - if (!is_array($userIds)) { |
|
377 | - return []; |
|
378 | - } |
|
379 | - $users = []; |
|
380 | - foreach ($userIds as $userId) { |
|
381 | - $user = $this->userManager->get($userId); |
|
382 | - if (!is_null($user)) { |
|
383 | - $users[$userId] = $user; |
|
384 | - } |
|
385 | - } |
|
386 | - return $users; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @return bool |
|
391 | - * @since 14.0.0 |
|
392 | - */ |
|
393 | - public function canRemoveUser() { |
|
394 | - foreach ($this->backends as $backend) { |
|
395 | - if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) { |
|
396 | - return true; |
|
397 | - } |
|
398 | - } |
|
399 | - return false; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * @return bool |
|
404 | - * @since 14.0.0 |
|
405 | - */ |
|
406 | - public function canAddUser() { |
|
407 | - foreach ($this->backends as $backend) { |
|
408 | - if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) { |
|
409 | - return true; |
|
410 | - } |
|
411 | - } |
|
412 | - return false; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @return bool |
|
417 | - * @since 16.0.0 |
|
418 | - */ |
|
419 | - public function hideFromCollaboration(): bool { |
|
420 | - return array_reduce($this->backends, function (bool $hide, GroupInterface $backend) { |
|
421 | - return $hide | ($backend instanceof IHideFromCollaborationBackend && $backend->hideGroup($this->gid)); |
|
422 | - }, false); |
|
423 | - } |
|
49 | + /** @var null|string */ |
|
50 | + protected $displayName; |
|
51 | + |
|
52 | + /** @var string */ |
|
53 | + private $gid; |
|
54 | + |
|
55 | + /** @var \OC\User\User[] */ |
|
56 | + private $users = []; |
|
57 | + |
|
58 | + /** @var bool */ |
|
59 | + private $usersLoaded; |
|
60 | + |
|
61 | + /** @var Backend[] */ |
|
62 | + private $backends; |
|
63 | + /** @var EventDispatcherInterface */ |
|
64 | + private $dispatcher; |
|
65 | + /** @var \OC\User\Manager|IUserManager */ |
|
66 | + private $userManager; |
|
67 | + /** @var PublicEmitter */ |
|
68 | + private $emitter; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $gid |
|
73 | + * @param Backend[] $backends |
|
74 | + * @param EventDispatcherInterface $dispatcher |
|
75 | + * @param IUserManager $userManager |
|
76 | + * @param PublicEmitter $emitter |
|
77 | + * @param string $displayName |
|
78 | + */ |
|
79 | + public function __construct(string $gid, array $backends, EventDispatcherInterface $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) { |
|
80 | + $this->gid = $gid; |
|
81 | + $this->backends = $backends; |
|
82 | + $this->dispatcher = $dispatcher; |
|
83 | + $this->userManager = $userManager; |
|
84 | + $this->emitter = $emitter; |
|
85 | + $this->displayName = $displayName; |
|
86 | + } |
|
87 | + |
|
88 | + public function getGID() { |
|
89 | + return $this->gid; |
|
90 | + } |
|
91 | + |
|
92 | + public function getDisplayName() { |
|
93 | + if (is_null($this->displayName)) { |
|
94 | + foreach ($this->backends as $backend) { |
|
95 | + if ($backend instanceof IGetDisplayNameBackend) { |
|
96 | + $displayName = $backend->getDisplayName($this->gid); |
|
97 | + if (trim($displayName) !== '') { |
|
98 | + $this->displayName = $displayName; |
|
99 | + return $this->displayName; |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + return $this->gid; |
|
104 | + } |
|
105 | + return $this->displayName; |
|
106 | + } |
|
107 | + |
|
108 | + public function setDisplayName(string $displayName): bool { |
|
109 | + $displayName = trim($displayName); |
|
110 | + if ($displayName !== '') { |
|
111 | + foreach ($this->backends as $backend) { |
|
112 | + if (($backend instanceof ISetDisplayNameBackend) |
|
113 | + && $backend->setDisplayName($this->gid, $displayName)) { |
|
114 | + $this->displayName = $displayName; |
|
115 | + return true; |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * get all users in the group |
|
124 | + * |
|
125 | + * @return \OC\User\User[] |
|
126 | + */ |
|
127 | + public function getUsers() { |
|
128 | + if ($this->usersLoaded) { |
|
129 | + return $this->users; |
|
130 | + } |
|
131 | + |
|
132 | + $userIds = []; |
|
133 | + foreach ($this->backends as $backend) { |
|
134 | + $diff = array_diff( |
|
135 | + $backend->usersInGroup($this->gid), |
|
136 | + $userIds |
|
137 | + ); |
|
138 | + if ($diff) { |
|
139 | + $userIds = array_merge($userIds, $diff); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + $this->users = $this->getVerifiedUsers($userIds); |
|
144 | + $this->usersLoaded = true; |
|
145 | + return $this->users; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * check if a user is in the group |
|
150 | + * |
|
151 | + * @param IUser $user |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + public function inGroup(IUser $user) { |
|
155 | + if (isset($this->users[$user->getUID()])) { |
|
156 | + return true; |
|
157 | + } |
|
158 | + foreach ($this->backends as $backend) { |
|
159 | + if ($backend->inGroup($user->getUID(), $this->gid)) { |
|
160 | + $this->users[$user->getUID()] = $user; |
|
161 | + return true; |
|
162 | + } |
|
163 | + } |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * add a user to the group |
|
169 | + * |
|
170 | + * @param IUser $user |
|
171 | + */ |
|
172 | + public function addUser(IUser $user) { |
|
173 | + if ($this->inGroup($user)) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + $this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [ |
|
178 | + 'user' => $user, |
|
179 | + ])); |
|
180 | + |
|
181 | + if ($this->emitter) { |
|
182 | + $this->emitter->emit('\OC\Group', 'preAddUser', [$this, $user]); |
|
183 | + } |
|
184 | + foreach ($this->backends as $backend) { |
|
185 | + if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { |
|
186 | + $backend->addToGroup($user->getUID(), $this->gid); |
|
187 | + if ($this->users) { |
|
188 | + $this->users[$user->getUID()] = $user; |
|
189 | + } |
|
190 | + |
|
191 | + $this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [ |
|
192 | + 'user' => $user, |
|
193 | + ])); |
|
194 | + |
|
195 | + if ($this->emitter) { |
|
196 | + $this->emitter->emit('\OC\Group', 'postAddUser', [$this, $user]); |
|
197 | + } |
|
198 | + return; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * remove a user from the group |
|
205 | + * |
|
206 | + * @param \OC\User\User $user |
|
207 | + */ |
|
208 | + public function removeUser($user) { |
|
209 | + $result = false; |
|
210 | + $this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [ |
|
211 | + 'user' => $user, |
|
212 | + ])); |
|
213 | + if ($this->emitter) { |
|
214 | + $this->emitter->emit('\OC\Group', 'preRemoveUser', [$this, $user]); |
|
215 | + } |
|
216 | + foreach ($this->backends as $backend) { |
|
217 | + if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { |
|
218 | + $backend->removeFromGroup($user->getUID(), $this->gid); |
|
219 | + $result = true; |
|
220 | + } |
|
221 | + } |
|
222 | + if ($result) { |
|
223 | + $this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [ |
|
224 | + 'user' => $user, |
|
225 | + ])); |
|
226 | + if ($this->emitter) { |
|
227 | + $this->emitter->emit('\OC\Group', 'postRemoveUser', [$this, $user]); |
|
228 | + } |
|
229 | + if ($this->users) { |
|
230 | + foreach ($this->users as $index => $groupUser) { |
|
231 | + if ($groupUser->getUID() === $user->getUID()) { |
|
232 | + unset($this->users[$index]); |
|
233 | + return; |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * search for users in the group by userid |
|
242 | + * |
|
243 | + * @param string $search |
|
244 | + * @param int $limit |
|
245 | + * @param int $offset |
|
246 | + * @return \OC\User\User[] |
|
247 | + */ |
|
248 | + public function searchUsers($search, $limit = null, $offset = null) { |
|
249 | + $users = []; |
|
250 | + foreach ($this->backends as $backend) { |
|
251 | + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
252 | + $users += $this->getVerifiedUsers($userIds); |
|
253 | + if (!is_null($limit) and $limit <= 0) { |
|
254 | + return $users; |
|
255 | + } |
|
256 | + } |
|
257 | + return $users; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * returns the number of users matching the search string |
|
262 | + * |
|
263 | + * @param string $search |
|
264 | + * @return int|bool |
|
265 | + */ |
|
266 | + public function count($search = '') { |
|
267 | + $users = false; |
|
268 | + foreach ($this->backends as $backend) { |
|
269 | + if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { |
|
270 | + if ($users === false) { |
|
271 | + //we could directly add to a bool variable, but this would |
|
272 | + //be ugly |
|
273 | + $users = 0; |
|
274 | + } |
|
275 | + $users += $backend->countUsersInGroup($this->gid, $search); |
|
276 | + } |
|
277 | + } |
|
278 | + return $users; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * returns the number of disabled users |
|
283 | + * |
|
284 | + * @return int|bool |
|
285 | + */ |
|
286 | + public function countDisabled() { |
|
287 | + $users = false; |
|
288 | + foreach ($this->backends as $backend) { |
|
289 | + if ($backend instanceof ICountDisabledInGroup) { |
|
290 | + if ($users === false) { |
|
291 | + //we could directly add to a bool variable, but this would |
|
292 | + //be ugly |
|
293 | + $users = 0; |
|
294 | + } |
|
295 | + $users += $backend->countDisabledInGroup($this->gid); |
|
296 | + } |
|
297 | + } |
|
298 | + return $users; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * search for users in the group by displayname |
|
303 | + * |
|
304 | + * @param string $search |
|
305 | + * @param int $limit |
|
306 | + * @param int $offset |
|
307 | + * @return \OC\User\User[] |
|
308 | + */ |
|
309 | + public function searchDisplayName($search, $limit = null, $offset = null) { |
|
310 | + $users = []; |
|
311 | + foreach ($this->backends as $backend) { |
|
312 | + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
313 | + $users = $this->getVerifiedUsers($userIds); |
|
314 | + if (!is_null($limit) and $limit <= 0) { |
|
315 | + return array_values($users); |
|
316 | + } |
|
317 | + } |
|
318 | + return array_values($users); |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Get the names of the backend classes the group is connected to |
|
323 | + * |
|
324 | + * @return string[] |
|
325 | + */ |
|
326 | + public function getBackendNames() { |
|
327 | + $backends = []; |
|
328 | + foreach ($this->backends as $backend) { |
|
329 | + if ($backend instanceof INamedBackend) { |
|
330 | + $backends[] = $backend->getBackendName(); |
|
331 | + } else { |
|
332 | + $backends[] = get_class($backend); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + return $backends; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * delete the group |
|
341 | + * |
|
342 | + * @return bool |
|
343 | + */ |
|
344 | + public function delete() { |
|
345 | + // Prevent users from deleting group admin |
|
346 | + if ($this->getGID() === 'admin') { |
|
347 | + return false; |
|
348 | + } |
|
349 | + |
|
350 | + $result = false; |
|
351 | + $this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this)); |
|
352 | + if ($this->emitter) { |
|
353 | + $this->emitter->emit('\OC\Group', 'preDelete', [$this]); |
|
354 | + } |
|
355 | + foreach ($this->backends as $backend) { |
|
356 | + if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { |
|
357 | + $result = true; |
|
358 | + $backend->deleteGroup($this->gid); |
|
359 | + } |
|
360 | + } |
|
361 | + if ($result) { |
|
362 | + $this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this)); |
|
363 | + if ($this->emitter) { |
|
364 | + $this->emitter->emit('\OC\Group', 'postDelete', [$this]); |
|
365 | + } |
|
366 | + } |
|
367 | + return $result; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * returns all the Users from an array that really exists |
|
372 | + * @param string[] $userIds an array containing user IDs |
|
373 | + * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value |
|
374 | + */ |
|
375 | + private function getVerifiedUsers($userIds) { |
|
376 | + if (!is_array($userIds)) { |
|
377 | + return []; |
|
378 | + } |
|
379 | + $users = []; |
|
380 | + foreach ($userIds as $userId) { |
|
381 | + $user = $this->userManager->get($userId); |
|
382 | + if (!is_null($user)) { |
|
383 | + $users[$userId] = $user; |
|
384 | + } |
|
385 | + } |
|
386 | + return $users; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @return bool |
|
391 | + * @since 14.0.0 |
|
392 | + */ |
|
393 | + public function canRemoveUser() { |
|
394 | + foreach ($this->backends as $backend) { |
|
395 | + if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) { |
|
396 | + return true; |
|
397 | + } |
|
398 | + } |
|
399 | + return false; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * @return bool |
|
404 | + * @since 14.0.0 |
|
405 | + */ |
|
406 | + public function canAddUser() { |
|
407 | + foreach ($this->backends as $backend) { |
|
408 | + if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) { |
|
409 | + return true; |
|
410 | + } |
|
411 | + } |
|
412 | + return false; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @return bool |
|
417 | + * @since 16.0.0 |
|
418 | + */ |
|
419 | + public function hideFromCollaboration(): bool { |
|
420 | + return array_reduce($this->backends, function (bool $hide, GroupInterface $backend) { |
|
421 | + return $hide | ($backend instanceof IHideFromCollaborationBackend && $backend->hideGroup($this->gid)); |
|
422 | + }, false); |
|
423 | + } |
|
424 | 424 | } |
@@ -62,455 +62,455 @@ |
||
62 | 62 | * Class for group management in a SQL Database (e.g. MySQL, SQLite) |
63 | 63 | */ |
64 | 64 | class Database extends ABackend implements |
65 | - IAddToGroupBackend, |
|
66 | - ICountDisabledInGroup, |
|
67 | - ICountUsersBackend, |
|
68 | - ICreateGroupBackend, |
|
69 | - IDeleteGroupBackend, |
|
70 | - IGetDisplayNameBackend, |
|
71 | - IGroupDetailsBackend, |
|
72 | - IRemoveFromGroupBackend, |
|
73 | - ISetDisplayNameBackend, |
|
74 | - INamedBackend { |
|
75 | - |
|
76 | - /** @var string[] */ |
|
77 | - private $groupCache = []; |
|
78 | - |
|
79 | - /** @var IDBConnection */ |
|
80 | - private $dbConn; |
|
81 | - |
|
82 | - /** |
|
83 | - * \OC\Group\Database constructor. |
|
84 | - * |
|
85 | - * @param IDBConnection|null $dbConn |
|
86 | - */ |
|
87 | - public function __construct(IDBConnection $dbConn = null) { |
|
88 | - $this->dbConn = $dbConn; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * FIXME: This function should not be required! |
|
93 | - */ |
|
94 | - private function fixDI() { |
|
95 | - if ($this->dbConn === null) { |
|
96 | - $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Try to create a new group |
|
102 | - * @param string $gid The name of the group to create |
|
103 | - * @return bool |
|
104 | - * |
|
105 | - * Tries to create a new group. If the group name already exists, false will |
|
106 | - * be returned. |
|
107 | - */ |
|
108 | - public function createGroup(string $gid): bool { |
|
109 | - $this->fixDI(); |
|
110 | - |
|
111 | - try { |
|
112 | - // Add group |
|
113 | - $builder = $this->dbConn->getQueryBuilder(); |
|
114 | - $result = $builder->insert('groups') |
|
115 | - ->setValue('gid', $builder->createNamedParameter($gid)) |
|
116 | - ->setValue('displayname', $builder->createNamedParameter($gid)) |
|
117 | - ->execute(); |
|
118 | - } catch (UniqueConstraintViolationException $e) { |
|
119 | - $result = 0; |
|
120 | - } |
|
121 | - |
|
122 | - // Add to cache |
|
123 | - $this->groupCache[$gid] = [ |
|
124 | - 'gid' => $gid, |
|
125 | - 'displayname' => $gid |
|
126 | - ]; |
|
127 | - |
|
128 | - return $result === 1; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * delete a group |
|
133 | - * @param string $gid gid of the group to delete |
|
134 | - * @return bool |
|
135 | - * |
|
136 | - * Deletes a group and removes it from the group_user-table |
|
137 | - */ |
|
138 | - public function deleteGroup(string $gid): bool { |
|
139 | - $this->fixDI(); |
|
140 | - |
|
141 | - // Delete the group |
|
142 | - $qb = $this->dbConn->getQueryBuilder(); |
|
143 | - $qb->delete('groups') |
|
144 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
145 | - ->execute(); |
|
146 | - |
|
147 | - // Delete the group-user relation |
|
148 | - $qb = $this->dbConn->getQueryBuilder(); |
|
149 | - $qb->delete('group_user') |
|
150 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
151 | - ->execute(); |
|
152 | - |
|
153 | - // Delete the group-groupadmin relation |
|
154 | - $qb = $this->dbConn->getQueryBuilder(); |
|
155 | - $qb->delete('group_admin') |
|
156 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
157 | - ->execute(); |
|
158 | - |
|
159 | - // Delete from cache |
|
160 | - unset($this->groupCache[$gid]); |
|
161 | - |
|
162 | - return true; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * is user in group? |
|
167 | - * @param string $uid uid of the user |
|
168 | - * @param string $gid gid of the group |
|
169 | - * @return bool |
|
170 | - * |
|
171 | - * Checks whether the user is member of a group or not. |
|
172 | - */ |
|
173 | - public function inGroup($uid, $gid) { |
|
174 | - $this->fixDI(); |
|
175 | - |
|
176 | - // check |
|
177 | - $qb = $this->dbConn->getQueryBuilder(); |
|
178 | - $cursor = $qb->select('uid') |
|
179 | - ->from('group_user') |
|
180 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
181 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
182 | - ->execute(); |
|
183 | - |
|
184 | - $result = $cursor->fetch(); |
|
185 | - $cursor->closeCursor(); |
|
186 | - |
|
187 | - return $result ? true : false; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Add a user to a group |
|
192 | - * @param string $uid Name of the user to add to group |
|
193 | - * @param string $gid Name of the group in which add the user |
|
194 | - * @return bool |
|
195 | - * |
|
196 | - * Adds a user to a group. |
|
197 | - */ |
|
198 | - public function addToGroup(string $uid, string $gid): bool { |
|
199 | - $this->fixDI(); |
|
200 | - |
|
201 | - // No duplicate entries! |
|
202 | - if (!$this->inGroup($uid, $gid)) { |
|
203 | - $qb = $this->dbConn->getQueryBuilder(); |
|
204 | - $qb->insert('group_user') |
|
205 | - ->setValue('uid', $qb->createNamedParameter($uid)) |
|
206 | - ->setValue('gid', $qb->createNamedParameter($gid)) |
|
207 | - ->execute(); |
|
208 | - return true; |
|
209 | - } else { |
|
210 | - return false; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Removes a user from a group |
|
216 | - * @param string $uid Name of the user to remove from group |
|
217 | - * @param string $gid Name of the group from which remove the user |
|
218 | - * @return bool |
|
219 | - * |
|
220 | - * removes the user from a group. |
|
221 | - */ |
|
222 | - public function removeFromGroup(string $uid, string $gid): bool { |
|
223 | - $this->fixDI(); |
|
224 | - |
|
225 | - $qb = $this->dbConn->getQueryBuilder(); |
|
226 | - $qb->delete('group_user') |
|
227 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
228 | - ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
229 | - ->execute(); |
|
230 | - |
|
231 | - return true; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Get all groups a user belongs to |
|
236 | - * @param string $uid Name of the user |
|
237 | - * @return array an array of group names |
|
238 | - * |
|
239 | - * This function fetches all groups a user belongs to. It does not check |
|
240 | - * if the user exists at all. |
|
241 | - */ |
|
242 | - public function getUserGroups($uid) { |
|
243 | - //guests has empty or null $uid |
|
244 | - if ($uid === null || $uid === '') { |
|
245 | - return []; |
|
246 | - } |
|
247 | - |
|
248 | - $this->fixDI(); |
|
249 | - |
|
250 | - // No magic! |
|
251 | - $qb = $this->dbConn->getQueryBuilder(); |
|
252 | - $cursor = $qb->select('gu.gid', 'g.displayname') |
|
253 | - ->from('group_user', 'gu') |
|
254 | - ->leftJoin('gu', 'groups', 'g', $qb->expr()->eq('gu.gid', 'g.gid')) |
|
255 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
256 | - ->execute(); |
|
257 | - |
|
258 | - $groups = []; |
|
259 | - while ($row = $cursor->fetch()) { |
|
260 | - $groups[] = $row['gid']; |
|
261 | - $this->groupCache[$row['gid']] = [ |
|
262 | - 'gid' => $row['gid'], |
|
263 | - 'displayname' => $row['displayname'], |
|
264 | - ]; |
|
265 | - } |
|
266 | - $cursor->closeCursor(); |
|
267 | - |
|
268 | - return $groups; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * get a list of all groups |
|
273 | - * @param string $search |
|
274 | - * @param int $limit |
|
275 | - * @param int $offset |
|
276 | - * @return array an array of group names |
|
277 | - * |
|
278 | - * Returns a list with all groups |
|
279 | - */ |
|
280 | - public function getGroups($search = '', $limit = null, $offset = null) { |
|
281 | - $this->fixDI(); |
|
282 | - |
|
283 | - $query = $this->dbConn->getQueryBuilder(); |
|
284 | - $query->select('gid') |
|
285 | - ->from('groups') |
|
286 | - ->orderBy('gid', 'ASC'); |
|
287 | - |
|
288 | - if ($search !== '') { |
|
289 | - $query->where($query->expr()->iLike('gid', $query->createNamedParameter( |
|
290 | - '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
291 | - ))); |
|
292 | - $query->orWhere($query->expr()->iLike('displayname', $query->createNamedParameter( |
|
293 | - '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
294 | - ))); |
|
295 | - } |
|
296 | - |
|
297 | - $query->setMaxResults($limit) |
|
298 | - ->setFirstResult($offset); |
|
299 | - $result = $query->execute(); |
|
300 | - |
|
301 | - $groups = []; |
|
302 | - while ($row = $result->fetch()) { |
|
303 | - $groups[] = $row['gid']; |
|
304 | - } |
|
305 | - $result->closeCursor(); |
|
306 | - |
|
307 | - return $groups; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * check if a group exists |
|
312 | - * @param string $gid |
|
313 | - * @return bool |
|
314 | - */ |
|
315 | - public function groupExists($gid) { |
|
316 | - $this->fixDI(); |
|
317 | - |
|
318 | - // Check cache first |
|
319 | - if (isset($this->groupCache[$gid])) { |
|
320 | - return true; |
|
321 | - } |
|
322 | - |
|
323 | - $qb = $this->dbConn->getQueryBuilder(); |
|
324 | - $cursor = $qb->select('gid', 'displayname') |
|
325 | - ->from('groups') |
|
326 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
327 | - ->execute(); |
|
328 | - $result = $cursor->fetch(); |
|
329 | - $cursor->closeCursor(); |
|
330 | - |
|
331 | - if ($result !== false) { |
|
332 | - $this->groupCache[$gid] = [ |
|
333 | - 'gid' => $gid, |
|
334 | - 'displayname' => $result['displayname'], |
|
335 | - ]; |
|
336 | - return true; |
|
337 | - } |
|
338 | - return false; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * get a list of all users in a group |
|
343 | - * @param string $gid |
|
344 | - * @param string $search |
|
345 | - * @param int $limit |
|
346 | - * @param int $offset |
|
347 | - * @return array an array of user ids |
|
348 | - */ |
|
349 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
350 | - $this->fixDI(); |
|
351 | - |
|
352 | - $query = $this->dbConn->getQueryBuilder(); |
|
353 | - $query->select('g.uid') |
|
354 | - ->from('group_user', 'g') |
|
355 | - ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))) |
|
356 | - ->orderBy('g.uid', 'ASC'); |
|
357 | - |
|
358 | - if ($search !== '') { |
|
359 | - $query->leftJoin('g', 'users', 'u', $query->expr()->eq('g.uid', 'u.uid')) |
|
360 | - ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( |
|
361 | - $query->expr()->eq('p.userid', 'u.uid'), |
|
362 | - $query->expr()->eq('p.appid', $query->expr()->literal('settings')), |
|
363 | - $query->expr()->eq('p.configkey', $query->expr()->literal('email'))) |
|
364 | - ) |
|
365 | - // sqlite doesn't like re-using a single named parameter here |
|
366 | - ->andWhere( |
|
367 | - $query->expr()->orX( |
|
368 | - $query->expr()->ilike('g.uid', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')), |
|
369 | - $query->expr()->ilike('u.displayname', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')), |
|
370 | - $query->expr()->ilike('p.configvalue', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')) |
|
371 | - ) |
|
372 | - ) |
|
373 | - ->orderBy('u.uid_lower', 'ASC'); |
|
374 | - } |
|
375 | - |
|
376 | - if ($limit !== -1) { |
|
377 | - $query->setMaxResults($limit); |
|
378 | - } |
|
379 | - if ($offset !== 0) { |
|
380 | - $query->setFirstResult($offset); |
|
381 | - } |
|
382 | - |
|
383 | - $result = $query->execute(); |
|
384 | - |
|
385 | - $users = []; |
|
386 | - while ($row = $result->fetch()) { |
|
387 | - $users[] = $row['uid']; |
|
388 | - } |
|
389 | - $result->closeCursor(); |
|
390 | - |
|
391 | - return $users; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * get the number of all users matching the search string in a group |
|
396 | - * @param string $gid |
|
397 | - * @param string $search |
|
398 | - * @return int |
|
399 | - */ |
|
400 | - public function countUsersInGroup(string $gid, string $search = ''): int { |
|
401 | - $this->fixDI(); |
|
402 | - |
|
403 | - $query = $this->dbConn->getQueryBuilder(); |
|
404 | - $query->select($query->func()->count('*', 'num_users')) |
|
405 | - ->from('group_user') |
|
406 | - ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))); |
|
407 | - |
|
408 | - if ($search !== '') { |
|
409 | - $query->andWhere($query->expr()->like('uid', $query->createNamedParameter( |
|
410 | - '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
411 | - ))); |
|
412 | - } |
|
413 | - |
|
414 | - $result = $query->execute(); |
|
415 | - $count = $result->fetchOne(); |
|
416 | - $result->closeCursor(); |
|
417 | - |
|
418 | - if ($count !== false) { |
|
419 | - $count = (int)$count; |
|
420 | - } else { |
|
421 | - $count = 0; |
|
422 | - } |
|
423 | - |
|
424 | - return $count; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * get the number of disabled users in a group |
|
429 | - * |
|
430 | - * @param string $search |
|
431 | - * |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function countDisabledInGroup(string $gid): int { |
|
435 | - $this->fixDI(); |
|
436 | - |
|
437 | - $query = $this->dbConn->getQueryBuilder(); |
|
438 | - $query->select($query->createFunction('COUNT(DISTINCT ' . $query->getColumnName('uid') . ')')) |
|
439 | - ->from('preferences', 'p') |
|
440 | - ->innerJoin('p', 'group_user', 'g', $query->expr()->eq('p.userid', 'g.uid')) |
|
441 | - ->where($query->expr()->eq('appid', $query->createNamedParameter('core'))) |
|
442 | - ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('enabled'))) |
|
443 | - ->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('false'), IQueryBuilder::PARAM_STR)) |
|
444 | - ->andWhere($query->expr()->eq('gid', $query->createNamedParameter($gid), IQueryBuilder::PARAM_STR)); |
|
445 | - |
|
446 | - $result = $query->execute(); |
|
447 | - $count = $result->fetchOne(); |
|
448 | - $result->closeCursor(); |
|
449 | - |
|
450 | - if ($count !== false) { |
|
451 | - $count = (int)$count; |
|
452 | - } else { |
|
453 | - $count = 0; |
|
454 | - } |
|
455 | - |
|
456 | - return $count; |
|
457 | - } |
|
458 | - |
|
459 | - public function getDisplayName(string $gid): string { |
|
460 | - if (isset($this->groupCache[$gid])) { |
|
461 | - return $this->groupCache[$gid]['displayname']; |
|
462 | - } |
|
463 | - |
|
464 | - $this->fixDI(); |
|
465 | - |
|
466 | - $query = $this->dbConn->getQueryBuilder(); |
|
467 | - $query->select('displayname') |
|
468 | - ->from('groups') |
|
469 | - ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))); |
|
470 | - |
|
471 | - $result = $query->execute(); |
|
472 | - $displayName = $result->fetchOne(); |
|
473 | - $result->closeCursor(); |
|
474 | - |
|
475 | - return (string) $displayName; |
|
476 | - } |
|
477 | - |
|
478 | - public function getGroupDetails(string $gid): array { |
|
479 | - $displayName = $this->getDisplayName($gid); |
|
480 | - if ($displayName !== '') { |
|
481 | - return ['displayName' => $displayName]; |
|
482 | - } |
|
483 | - |
|
484 | - return []; |
|
485 | - } |
|
486 | - |
|
487 | - public function setDisplayName(string $gid, string $displayName): bool { |
|
488 | - if (!$this->groupExists($gid)) { |
|
489 | - return false; |
|
490 | - } |
|
491 | - |
|
492 | - $this->fixDI(); |
|
493 | - |
|
494 | - $displayName = trim($displayName); |
|
495 | - if ($displayName === '') { |
|
496 | - $displayName = $gid; |
|
497 | - } |
|
498 | - |
|
499 | - $query = $this->dbConn->getQueryBuilder(); |
|
500 | - $query->update('groups') |
|
501 | - ->set('displayname', $query->createNamedParameter($displayName)) |
|
502 | - ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))); |
|
503 | - $query->execute(); |
|
504 | - |
|
505 | - return true; |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Backend name to be shown in group management |
|
510 | - * @return string the name of the backend to be shown |
|
511 | - * @since 21.0.0 |
|
512 | - */ |
|
513 | - public function getBackendName(): string { |
|
514 | - return 'Database'; |
|
515 | - } |
|
65 | + IAddToGroupBackend, |
|
66 | + ICountDisabledInGroup, |
|
67 | + ICountUsersBackend, |
|
68 | + ICreateGroupBackend, |
|
69 | + IDeleteGroupBackend, |
|
70 | + IGetDisplayNameBackend, |
|
71 | + IGroupDetailsBackend, |
|
72 | + IRemoveFromGroupBackend, |
|
73 | + ISetDisplayNameBackend, |
|
74 | + INamedBackend { |
|
75 | + |
|
76 | + /** @var string[] */ |
|
77 | + private $groupCache = []; |
|
78 | + |
|
79 | + /** @var IDBConnection */ |
|
80 | + private $dbConn; |
|
81 | + |
|
82 | + /** |
|
83 | + * \OC\Group\Database constructor. |
|
84 | + * |
|
85 | + * @param IDBConnection|null $dbConn |
|
86 | + */ |
|
87 | + public function __construct(IDBConnection $dbConn = null) { |
|
88 | + $this->dbConn = $dbConn; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * FIXME: This function should not be required! |
|
93 | + */ |
|
94 | + private function fixDI() { |
|
95 | + if ($this->dbConn === null) { |
|
96 | + $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Try to create a new group |
|
102 | + * @param string $gid The name of the group to create |
|
103 | + * @return bool |
|
104 | + * |
|
105 | + * Tries to create a new group. If the group name already exists, false will |
|
106 | + * be returned. |
|
107 | + */ |
|
108 | + public function createGroup(string $gid): bool { |
|
109 | + $this->fixDI(); |
|
110 | + |
|
111 | + try { |
|
112 | + // Add group |
|
113 | + $builder = $this->dbConn->getQueryBuilder(); |
|
114 | + $result = $builder->insert('groups') |
|
115 | + ->setValue('gid', $builder->createNamedParameter($gid)) |
|
116 | + ->setValue('displayname', $builder->createNamedParameter($gid)) |
|
117 | + ->execute(); |
|
118 | + } catch (UniqueConstraintViolationException $e) { |
|
119 | + $result = 0; |
|
120 | + } |
|
121 | + |
|
122 | + // Add to cache |
|
123 | + $this->groupCache[$gid] = [ |
|
124 | + 'gid' => $gid, |
|
125 | + 'displayname' => $gid |
|
126 | + ]; |
|
127 | + |
|
128 | + return $result === 1; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * delete a group |
|
133 | + * @param string $gid gid of the group to delete |
|
134 | + * @return bool |
|
135 | + * |
|
136 | + * Deletes a group and removes it from the group_user-table |
|
137 | + */ |
|
138 | + public function deleteGroup(string $gid): bool { |
|
139 | + $this->fixDI(); |
|
140 | + |
|
141 | + // Delete the group |
|
142 | + $qb = $this->dbConn->getQueryBuilder(); |
|
143 | + $qb->delete('groups') |
|
144 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
145 | + ->execute(); |
|
146 | + |
|
147 | + // Delete the group-user relation |
|
148 | + $qb = $this->dbConn->getQueryBuilder(); |
|
149 | + $qb->delete('group_user') |
|
150 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
151 | + ->execute(); |
|
152 | + |
|
153 | + // Delete the group-groupadmin relation |
|
154 | + $qb = $this->dbConn->getQueryBuilder(); |
|
155 | + $qb->delete('group_admin') |
|
156 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
157 | + ->execute(); |
|
158 | + |
|
159 | + // Delete from cache |
|
160 | + unset($this->groupCache[$gid]); |
|
161 | + |
|
162 | + return true; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * is user in group? |
|
167 | + * @param string $uid uid of the user |
|
168 | + * @param string $gid gid of the group |
|
169 | + * @return bool |
|
170 | + * |
|
171 | + * Checks whether the user is member of a group or not. |
|
172 | + */ |
|
173 | + public function inGroup($uid, $gid) { |
|
174 | + $this->fixDI(); |
|
175 | + |
|
176 | + // check |
|
177 | + $qb = $this->dbConn->getQueryBuilder(); |
|
178 | + $cursor = $qb->select('uid') |
|
179 | + ->from('group_user') |
|
180 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
181 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
182 | + ->execute(); |
|
183 | + |
|
184 | + $result = $cursor->fetch(); |
|
185 | + $cursor->closeCursor(); |
|
186 | + |
|
187 | + return $result ? true : false; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Add a user to a group |
|
192 | + * @param string $uid Name of the user to add to group |
|
193 | + * @param string $gid Name of the group in which add the user |
|
194 | + * @return bool |
|
195 | + * |
|
196 | + * Adds a user to a group. |
|
197 | + */ |
|
198 | + public function addToGroup(string $uid, string $gid): bool { |
|
199 | + $this->fixDI(); |
|
200 | + |
|
201 | + // No duplicate entries! |
|
202 | + if (!$this->inGroup($uid, $gid)) { |
|
203 | + $qb = $this->dbConn->getQueryBuilder(); |
|
204 | + $qb->insert('group_user') |
|
205 | + ->setValue('uid', $qb->createNamedParameter($uid)) |
|
206 | + ->setValue('gid', $qb->createNamedParameter($gid)) |
|
207 | + ->execute(); |
|
208 | + return true; |
|
209 | + } else { |
|
210 | + return false; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Removes a user from a group |
|
216 | + * @param string $uid Name of the user to remove from group |
|
217 | + * @param string $gid Name of the group from which remove the user |
|
218 | + * @return bool |
|
219 | + * |
|
220 | + * removes the user from a group. |
|
221 | + */ |
|
222 | + public function removeFromGroup(string $uid, string $gid): bool { |
|
223 | + $this->fixDI(); |
|
224 | + |
|
225 | + $qb = $this->dbConn->getQueryBuilder(); |
|
226 | + $qb->delete('group_user') |
|
227 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
228 | + ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
229 | + ->execute(); |
|
230 | + |
|
231 | + return true; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Get all groups a user belongs to |
|
236 | + * @param string $uid Name of the user |
|
237 | + * @return array an array of group names |
|
238 | + * |
|
239 | + * This function fetches all groups a user belongs to. It does not check |
|
240 | + * if the user exists at all. |
|
241 | + */ |
|
242 | + public function getUserGroups($uid) { |
|
243 | + //guests has empty or null $uid |
|
244 | + if ($uid === null || $uid === '') { |
|
245 | + return []; |
|
246 | + } |
|
247 | + |
|
248 | + $this->fixDI(); |
|
249 | + |
|
250 | + // No magic! |
|
251 | + $qb = $this->dbConn->getQueryBuilder(); |
|
252 | + $cursor = $qb->select('gu.gid', 'g.displayname') |
|
253 | + ->from('group_user', 'gu') |
|
254 | + ->leftJoin('gu', 'groups', 'g', $qb->expr()->eq('gu.gid', 'g.gid')) |
|
255 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
256 | + ->execute(); |
|
257 | + |
|
258 | + $groups = []; |
|
259 | + while ($row = $cursor->fetch()) { |
|
260 | + $groups[] = $row['gid']; |
|
261 | + $this->groupCache[$row['gid']] = [ |
|
262 | + 'gid' => $row['gid'], |
|
263 | + 'displayname' => $row['displayname'], |
|
264 | + ]; |
|
265 | + } |
|
266 | + $cursor->closeCursor(); |
|
267 | + |
|
268 | + return $groups; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * get a list of all groups |
|
273 | + * @param string $search |
|
274 | + * @param int $limit |
|
275 | + * @param int $offset |
|
276 | + * @return array an array of group names |
|
277 | + * |
|
278 | + * Returns a list with all groups |
|
279 | + */ |
|
280 | + public function getGroups($search = '', $limit = null, $offset = null) { |
|
281 | + $this->fixDI(); |
|
282 | + |
|
283 | + $query = $this->dbConn->getQueryBuilder(); |
|
284 | + $query->select('gid') |
|
285 | + ->from('groups') |
|
286 | + ->orderBy('gid', 'ASC'); |
|
287 | + |
|
288 | + if ($search !== '') { |
|
289 | + $query->where($query->expr()->iLike('gid', $query->createNamedParameter( |
|
290 | + '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
291 | + ))); |
|
292 | + $query->orWhere($query->expr()->iLike('displayname', $query->createNamedParameter( |
|
293 | + '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
294 | + ))); |
|
295 | + } |
|
296 | + |
|
297 | + $query->setMaxResults($limit) |
|
298 | + ->setFirstResult($offset); |
|
299 | + $result = $query->execute(); |
|
300 | + |
|
301 | + $groups = []; |
|
302 | + while ($row = $result->fetch()) { |
|
303 | + $groups[] = $row['gid']; |
|
304 | + } |
|
305 | + $result->closeCursor(); |
|
306 | + |
|
307 | + return $groups; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * check if a group exists |
|
312 | + * @param string $gid |
|
313 | + * @return bool |
|
314 | + */ |
|
315 | + public function groupExists($gid) { |
|
316 | + $this->fixDI(); |
|
317 | + |
|
318 | + // Check cache first |
|
319 | + if (isset($this->groupCache[$gid])) { |
|
320 | + return true; |
|
321 | + } |
|
322 | + |
|
323 | + $qb = $this->dbConn->getQueryBuilder(); |
|
324 | + $cursor = $qb->select('gid', 'displayname') |
|
325 | + ->from('groups') |
|
326 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
327 | + ->execute(); |
|
328 | + $result = $cursor->fetch(); |
|
329 | + $cursor->closeCursor(); |
|
330 | + |
|
331 | + if ($result !== false) { |
|
332 | + $this->groupCache[$gid] = [ |
|
333 | + 'gid' => $gid, |
|
334 | + 'displayname' => $result['displayname'], |
|
335 | + ]; |
|
336 | + return true; |
|
337 | + } |
|
338 | + return false; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * get a list of all users in a group |
|
343 | + * @param string $gid |
|
344 | + * @param string $search |
|
345 | + * @param int $limit |
|
346 | + * @param int $offset |
|
347 | + * @return array an array of user ids |
|
348 | + */ |
|
349 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
350 | + $this->fixDI(); |
|
351 | + |
|
352 | + $query = $this->dbConn->getQueryBuilder(); |
|
353 | + $query->select('g.uid') |
|
354 | + ->from('group_user', 'g') |
|
355 | + ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))) |
|
356 | + ->orderBy('g.uid', 'ASC'); |
|
357 | + |
|
358 | + if ($search !== '') { |
|
359 | + $query->leftJoin('g', 'users', 'u', $query->expr()->eq('g.uid', 'u.uid')) |
|
360 | + ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( |
|
361 | + $query->expr()->eq('p.userid', 'u.uid'), |
|
362 | + $query->expr()->eq('p.appid', $query->expr()->literal('settings')), |
|
363 | + $query->expr()->eq('p.configkey', $query->expr()->literal('email'))) |
|
364 | + ) |
|
365 | + // sqlite doesn't like re-using a single named parameter here |
|
366 | + ->andWhere( |
|
367 | + $query->expr()->orX( |
|
368 | + $query->expr()->ilike('g.uid', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')), |
|
369 | + $query->expr()->ilike('u.displayname', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')), |
|
370 | + $query->expr()->ilike('p.configvalue', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')) |
|
371 | + ) |
|
372 | + ) |
|
373 | + ->orderBy('u.uid_lower', 'ASC'); |
|
374 | + } |
|
375 | + |
|
376 | + if ($limit !== -1) { |
|
377 | + $query->setMaxResults($limit); |
|
378 | + } |
|
379 | + if ($offset !== 0) { |
|
380 | + $query->setFirstResult($offset); |
|
381 | + } |
|
382 | + |
|
383 | + $result = $query->execute(); |
|
384 | + |
|
385 | + $users = []; |
|
386 | + while ($row = $result->fetch()) { |
|
387 | + $users[] = $row['uid']; |
|
388 | + } |
|
389 | + $result->closeCursor(); |
|
390 | + |
|
391 | + return $users; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * get the number of all users matching the search string in a group |
|
396 | + * @param string $gid |
|
397 | + * @param string $search |
|
398 | + * @return int |
|
399 | + */ |
|
400 | + public function countUsersInGroup(string $gid, string $search = ''): int { |
|
401 | + $this->fixDI(); |
|
402 | + |
|
403 | + $query = $this->dbConn->getQueryBuilder(); |
|
404 | + $query->select($query->func()->count('*', 'num_users')) |
|
405 | + ->from('group_user') |
|
406 | + ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))); |
|
407 | + |
|
408 | + if ($search !== '') { |
|
409 | + $query->andWhere($query->expr()->like('uid', $query->createNamedParameter( |
|
410 | + '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
411 | + ))); |
|
412 | + } |
|
413 | + |
|
414 | + $result = $query->execute(); |
|
415 | + $count = $result->fetchOne(); |
|
416 | + $result->closeCursor(); |
|
417 | + |
|
418 | + if ($count !== false) { |
|
419 | + $count = (int)$count; |
|
420 | + } else { |
|
421 | + $count = 0; |
|
422 | + } |
|
423 | + |
|
424 | + return $count; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * get the number of disabled users in a group |
|
429 | + * |
|
430 | + * @param string $search |
|
431 | + * |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function countDisabledInGroup(string $gid): int { |
|
435 | + $this->fixDI(); |
|
436 | + |
|
437 | + $query = $this->dbConn->getQueryBuilder(); |
|
438 | + $query->select($query->createFunction('COUNT(DISTINCT ' . $query->getColumnName('uid') . ')')) |
|
439 | + ->from('preferences', 'p') |
|
440 | + ->innerJoin('p', 'group_user', 'g', $query->expr()->eq('p.userid', 'g.uid')) |
|
441 | + ->where($query->expr()->eq('appid', $query->createNamedParameter('core'))) |
|
442 | + ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('enabled'))) |
|
443 | + ->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('false'), IQueryBuilder::PARAM_STR)) |
|
444 | + ->andWhere($query->expr()->eq('gid', $query->createNamedParameter($gid), IQueryBuilder::PARAM_STR)); |
|
445 | + |
|
446 | + $result = $query->execute(); |
|
447 | + $count = $result->fetchOne(); |
|
448 | + $result->closeCursor(); |
|
449 | + |
|
450 | + if ($count !== false) { |
|
451 | + $count = (int)$count; |
|
452 | + } else { |
|
453 | + $count = 0; |
|
454 | + } |
|
455 | + |
|
456 | + return $count; |
|
457 | + } |
|
458 | + |
|
459 | + public function getDisplayName(string $gid): string { |
|
460 | + if (isset($this->groupCache[$gid])) { |
|
461 | + return $this->groupCache[$gid]['displayname']; |
|
462 | + } |
|
463 | + |
|
464 | + $this->fixDI(); |
|
465 | + |
|
466 | + $query = $this->dbConn->getQueryBuilder(); |
|
467 | + $query->select('displayname') |
|
468 | + ->from('groups') |
|
469 | + ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))); |
|
470 | + |
|
471 | + $result = $query->execute(); |
|
472 | + $displayName = $result->fetchOne(); |
|
473 | + $result->closeCursor(); |
|
474 | + |
|
475 | + return (string) $displayName; |
|
476 | + } |
|
477 | + |
|
478 | + public function getGroupDetails(string $gid): array { |
|
479 | + $displayName = $this->getDisplayName($gid); |
|
480 | + if ($displayName !== '') { |
|
481 | + return ['displayName' => $displayName]; |
|
482 | + } |
|
483 | + |
|
484 | + return []; |
|
485 | + } |
|
486 | + |
|
487 | + public function setDisplayName(string $gid, string $displayName): bool { |
|
488 | + if (!$this->groupExists($gid)) { |
|
489 | + return false; |
|
490 | + } |
|
491 | + |
|
492 | + $this->fixDI(); |
|
493 | + |
|
494 | + $displayName = trim($displayName); |
|
495 | + if ($displayName === '') { |
|
496 | + $displayName = $gid; |
|
497 | + } |
|
498 | + |
|
499 | + $query = $this->dbConn->getQueryBuilder(); |
|
500 | + $query->update('groups') |
|
501 | + ->set('displayname', $query->createNamedParameter($displayName)) |
|
502 | + ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))); |
|
503 | + $query->execute(); |
|
504 | + |
|
505 | + return true; |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * Backend name to be shown in group management |
|
510 | + * @return string the name of the backend to be shown |
|
511 | + * @since 21.0.0 |
|
512 | + */ |
|
513 | + public function getBackendName(): string { |
|
514 | + return 'Database'; |
|
515 | + } |
|
516 | 516 | } |
@@ -27,10 +27,10 @@ |
||
27 | 27 | */ |
28 | 28 | interface INamedBackend { |
29 | 29 | |
30 | - /** |
|
31 | - * Backend name to be shown in group management |
|
32 | - * @return string the name of the backend to be shown |
|
33 | - * @since 22.0.0 |
|
34 | - */ |
|
35 | - public function getBackendName(): string; |
|
30 | + /** |
|
31 | + * Backend name to be shown in group management |
|
32 | + * @return string the name of the backend to be shown |
|
33 | + * @since 22.0.0 |
|
34 | + */ |
|
35 | + public function getBackendName(): string; |
|
36 | 36 | } |
@@ -34,132 +34,132 @@ |
||
34 | 34 | * @since 8.0.0 |
35 | 35 | */ |
36 | 36 | interface IGroup { |
37 | - /** |
|
38 | - * @return string |
|
39 | - * @since 8.0.0 |
|
40 | - */ |
|
41 | - public function getGID(); |
|
42 | - |
|
43 | - /** |
|
44 | - * Returns the group display name |
|
45 | - * |
|
46 | - * @return string |
|
47 | - * @since 12.0.0 |
|
48 | - */ |
|
49 | - public function getDisplayName(); |
|
50 | - |
|
51 | - /** |
|
52 | - * Set the group display name |
|
53 | - * |
|
54 | - * @param string $displayName |
|
55 | - * @return bool |
|
56 | - * @since 18.0.0 |
|
57 | - */ |
|
58 | - public function setDisplayName(string $displayName): bool; |
|
59 | - |
|
60 | - /** |
|
61 | - * get all users in the group |
|
62 | - * |
|
63 | - * @return \OCP\IUser[] |
|
64 | - * @since 8.0.0 |
|
65 | - */ |
|
66 | - public function getUsers(); |
|
67 | - |
|
68 | - /** |
|
69 | - * check if a user is in the group |
|
70 | - * |
|
71 | - * @param \OCP\IUser $user |
|
72 | - * @return bool |
|
73 | - * @since 8.0.0 |
|
74 | - */ |
|
75 | - public function inGroup(IUser $user); |
|
76 | - |
|
77 | - /** |
|
78 | - * add a user to the group |
|
79 | - * |
|
80 | - * @param \OCP\IUser $user |
|
81 | - * @since 8.0.0 |
|
82 | - */ |
|
83 | - public function addUser(IUser $user); |
|
84 | - |
|
85 | - /** |
|
86 | - * remove a user from the group |
|
87 | - * |
|
88 | - * @param \OCP\IUser $user |
|
89 | - * @since 8.0.0 |
|
90 | - */ |
|
91 | - public function removeUser($user); |
|
92 | - |
|
93 | - /** |
|
94 | - * search for users in the group by userid |
|
95 | - * |
|
96 | - * @param string $search |
|
97 | - * @param int $limit |
|
98 | - * @param int $offset |
|
99 | - * @return \OCP\IUser[] |
|
100 | - * @since 8.0.0 |
|
101 | - */ |
|
102 | - public function searchUsers($search, $limit = null, $offset = null); |
|
103 | - |
|
104 | - /** |
|
105 | - * returns the number of users matching the search string |
|
106 | - * |
|
107 | - * @param string $search |
|
108 | - * @return int|bool |
|
109 | - * @since 8.0.0 |
|
110 | - */ |
|
111 | - public function count($search = ''); |
|
112 | - |
|
113 | - /** |
|
114 | - * returns the number of disabled users |
|
115 | - * |
|
116 | - * @return int|bool |
|
117 | - * @since 14.0.0 |
|
118 | - */ |
|
119 | - public function countDisabled(); |
|
120 | - |
|
121 | - /** |
|
122 | - * search for users in the group by displayname |
|
123 | - * |
|
124 | - * @param string $search |
|
125 | - * @param int $limit |
|
126 | - * @param int $offset |
|
127 | - * @return \OCP\IUser[] |
|
128 | - * @since 8.0.0 |
|
129 | - */ |
|
130 | - public function searchDisplayName($search, $limit = null, $offset = null); |
|
131 | - |
|
132 | - /** |
|
133 | - * Get the names of the backends the group is connected to |
|
134 | - * |
|
135 | - * @return string[] |
|
136 | - * @since 22.0.0 |
|
137 | - */ |
|
138 | - public function getBackendNames(); |
|
139 | - |
|
140 | - /** |
|
141 | - * delete the group |
|
142 | - * |
|
143 | - * @return bool |
|
144 | - * @since 8.0.0 |
|
145 | - */ |
|
146 | - public function delete(); |
|
147 | - |
|
148 | - /** |
|
149 | - * @return bool |
|
150 | - * @since 14.0.0 |
|
151 | - */ |
|
152 | - public function canRemoveUser(); |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - * @since 14.0.0 |
|
157 | - */ |
|
158 | - public function canAddUser(); |
|
159 | - |
|
160 | - /** |
|
161 | - * @return bool |
|
162 | - * @since 16.0.0 |
|
163 | - */ |
|
164 | - public function hideFromCollaboration(): bool; |
|
37 | + /** |
|
38 | + * @return string |
|
39 | + * @since 8.0.0 |
|
40 | + */ |
|
41 | + public function getGID(); |
|
42 | + |
|
43 | + /** |
|
44 | + * Returns the group display name |
|
45 | + * |
|
46 | + * @return string |
|
47 | + * @since 12.0.0 |
|
48 | + */ |
|
49 | + public function getDisplayName(); |
|
50 | + |
|
51 | + /** |
|
52 | + * Set the group display name |
|
53 | + * |
|
54 | + * @param string $displayName |
|
55 | + * @return bool |
|
56 | + * @since 18.0.0 |
|
57 | + */ |
|
58 | + public function setDisplayName(string $displayName): bool; |
|
59 | + |
|
60 | + /** |
|
61 | + * get all users in the group |
|
62 | + * |
|
63 | + * @return \OCP\IUser[] |
|
64 | + * @since 8.0.0 |
|
65 | + */ |
|
66 | + public function getUsers(); |
|
67 | + |
|
68 | + /** |
|
69 | + * check if a user is in the group |
|
70 | + * |
|
71 | + * @param \OCP\IUser $user |
|
72 | + * @return bool |
|
73 | + * @since 8.0.0 |
|
74 | + */ |
|
75 | + public function inGroup(IUser $user); |
|
76 | + |
|
77 | + /** |
|
78 | + * add a user to the group |
|
79 | + * |
|
80 | + * @param \OCP\IUser $user |
|
81 | + * @since 8.0.0 |
|
82 | + */ |
|
83 | + public function addUser(IUser $user); |
|
84 | + |
|
85 | + /** |
|
86 | + * remove a user from the group |
|
87 | + * |
|
88 | + * @param \OCP\IUser $user |
|
89 | + * @since 8.0.0 |
|
90 | + */ |
|
91 | + public function removeUser($user); |
|
92 | + |
|
93 | + /** |
|
94 | + * search for users in the group by userid |
|
95 | + * |
|
96 | + * @param string $search |
|
97 | + * @param int $limit |
|
98 | + * @param int $offset |
|
99 | + * @return \OCP\IUser[] |
|
100 | + * @since 8.0.0 |
|
101 | + */ |
|
102 | + public function searchUsers($search, $limit = null, $offset = null); |
|
103 | + |
|
104 | + /** |
|
105 | + * returns the number of users matching the search string |
|
106 | + * |
|
107 | + * @param string $search |
|
108 | + * @return int|bool |
|
109 | + * @since 8.0.0 |
|
110 | + */ |
|
111 | + public function count($search = ''); |
|
112 | + |
|
113 | + /** |
|
114 | + * returns the number of disabled users |
|
115 | + * |
|
116 | + * @return int|bool |
|
117 | + * @since 14.0.0 |
|
118 | + */ |
|
119 | + public function countDisabled(); |
|
120 | + |
|
121 | + /** |
|
122 | + * search for users in the group by displayname |
|
123 | + * |
|
124 | + * @param string $search |
|
125 | + * @param int $limit |
|
126 | + * @param int $offset |
|
127 | + * @return \OCP\IUser[] |
|
128 | + * @since 8.0.0 |
|
129 | + */ |
|
130 | + public function searchDisplayName($search, $limit = null, $offset = null); |
|
131 | + |
|
132 | + /** |
|
133 | + * Get the names of the backends the group is connected to |
|
134 | + * |
|
135 | + * @return string[] |
|
136 | + * @since 22.0.0 |
|
137 | + */ |
|
138 | + public function getBackendNames(); |
|
139 | + |
|
140 | + /** |
|
141 | + * delete the group |
|
142 | + * |
|
143 | + * @return bool |
|
144 | + * @since 8.0.0 |
|
145 | + */ |
|
146 | + public function delete(); |
|
147 | + |
|
148 | + /** |
|
149 | + * @return bool |
|
150 | + * @since 14.0.0 |
|
151 | + */ |
|
152 | + public function canRemoveUser(); |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + * @since 14.0.0 |
|
157 | + */ |
|
158 | + public function canAddUser(); |
|
159 | + |
|
160 | + /** |
|
161 | + * @return bool |
|
162 | + * @since 16.0.0 |
|
163 | + */ |
|
164 | + public function hideFromCollaboration(): bool; |
|
165 | 165 | } |
@@ -52,146 +52,146 @@ |
||
52 | 52 | $application->add(new OC\Core\Command\App\CheckCode()); |
53 | 53 | $application->add(new OC\Core\Command\L10n\CreateJs()); |
54 | 54 | $application->add(new \OC\Core\Command\Integrity\SignApp( |
55 | - \OC::$server->getIntegrityCodeChecker(), |
|
56 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
57 | - \OC::$server->getURLGenerator() |
|
55 | + \OC::$server->getIntegrityCodeChecker(), |
|
56 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
57 | + \OC::$server->getURLGenerator() |
|
58 | 58 | )); |
59 | 59 | $application->add(new \OC\Core\Command\Integrity\SignCore( |
60 | - \OC::$server->getIntegrityCodeChecker(), |
|
61 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
60 | + \OC::$server->getIntegrityCodeChecker(), |
|
61 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
62 | 62 | )); |
63 | 63 | $application->add(new \OC\Core\Command\Integrity\CheckApp( |
64 | - \OC::$server->getIntegrityCodeChecker() |
|
64 | + \OC::$server->getIntegrityCodeChecker() |
|
65 | 65 | )); |
66 | 66 | $application->add(new \OC\Core\Command\Integrity\CheckCore( |
67 | - \OC::$server->getIntegrityCodeChecker() |
|
67 | + \OC::$server->getIntegrityCodeChecker() |
|
68 | 68 | )); |
69 | 69 | |
70 | 70 | |
71 | 71 | if (\OC::$server->getConfig()->getSystemValue('installed', false)) { |
72 | - $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
73 | - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager())); |
|
74 | - $application->add(new OC\Core\Command\App\Install()); |
|
75 | - $application->add(new OC\Core\Command\App\GetPath()); |
|
76 | - $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
77 | - $application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->getLogger())); |
|
78 | - $application->add(\OC::$server->query(\OC\Core\Command\App\Update::class)); |
|
79 | - |
|
80 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class)); |
|
81 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class)); |
|
82 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class)); |
|
83 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class)); |
|
84 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); |
|
85 | - |
|
86 | - $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
87 | - $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
88 | - $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
89 | - |
|
90 | - $application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class)); |
|
91 | - |
|
92 | - $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
93 | - $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
94 | - $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
95 | - $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
96 | - $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
97 | - $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
98 | - $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
99 | - $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
100 | - |
|
101 | - $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
102 | - $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
103 | - $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class))); |
|
104 | - $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); |
|
105 | - $application->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); |
|
106 | - $application->add(new OC\Core\Command\Db\AddMissingPrimaryKeys(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); |
|
107 | - $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class))); |
|
108 | - $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->get(\OC\DB\Connection::class))); |
|
109 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getAppManager())); |
|
110 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->get(\OC\DB\Connection::class))); |
|
111 | - $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getConfig())); |
|
112 | - |
|
113 | - $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
114 | - $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
115 | - $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); |
|
116 | - $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); |
|
117 | - $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
118 | - $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
119 | - $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
120 | - \OC::$server->getEncryptionManager(), |
|
121 | - \OC::$server->getAppManager(), |
|
122 | - \OC::$server->getConfig(), |
|
123 | - new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
124 | - new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
125 | - ); |
|
126 | - |
|
127 | - $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
128 | - $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
129 | - |
|
130 | - $view = new \OC\Files\View(); |
|
131 | - $util = new \OC\Encryption\Util( |
|
132 | - $view, |
|
133 | - \OC::$server->getUserManager(), |
|
134 | - \OC::$server->getGroupManager(), |
|
135 | - \OC::$server->getConfig() |
|
136 | - ); |
|
137 | - $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
138 | - $view, |
|
139 | - \OC::$server->getUserManager(), |
|
140 | - \OC::$server->getConfig(), |
|
141 | - $util, |
|
142 | - new \Symfony\Component\Console\Helper\QuestionHelper() |
|
143 | - ) |
|
144 | - ); |
|
145 | - $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
146 | - $application->add(new OC\Core\Command\Encryption\MigrateKeyStorage( |
|
147 | - $view, |
|
148 | - \OC::$server->getUserManager(), |
|
149 | - \OC::$server->getConfig(), |
|
150 | - $util, |
|
151 | - \OC::$server->getCrypto() |
|
152 | - ) |
|
153 | - ); |
|
154 | - |
|
155 | - $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
156 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
157 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
158 | - $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
159 | - $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
160 | - $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
161 | - |
|
162 | - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
163 | - $application->add(new OC\Core\Command\Maintenance\Repair( |
|
164 | - new \OC\Repair([], \OC::$server->getEventDispatcher()), |
|
165 | - \OC::$server->getConfig(), |
|
166 | - \OC::$server->getEventDispatcher(), |
|
167 | - \OC::$server->getAppManager() |
|
168 | - )); |
|
169 | - |
|
170 | - $application->add(\OC::$server->query(\OC\Core\Command\Preview\Repair::class)); |
|
171 | - |
|
172 | - $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
173 | - $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
174 | - $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
175 | - $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
176 | - $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
177 | - $application->add(\OC::$server->get(\OC\Core\Command\User\Report::class)); |
|
178 | - $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
179 | - $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
180 | - $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
181 | - $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
182 | - $application->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\Security\ICrypto::class))); |
|
183 | - |
|
184 | - $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); |
|
185 | - $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); |
|
186 | - $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
187 | - $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
188 | - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
189 | - $application->add(new OC\Core\Command\Group\Info(\OC::$server->get(\OCP\IGroupManager::class))); |
|
190 | - |
|
191 | - $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(), \OC::$server->getL10N('core'))); |
|
192 | - $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager())); |
|
193 | - $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager())); |
|
194 | - $application->add(new OC\Core\Command\Security\ResetBruteforceAttempts(\OC::$server->getBruteForceThrottler())); |
|
72 | + $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
73 | + $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager())); |
|
74 | + $application->add(new OC\Core\Command\App\Install()); |
|
75 | + $application->add(new OC\Core\Command\App\GetPath()); |
|
76 | + $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
77 | + $application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->getLogger())); |
|
78 | + $application->add(\OC::$server->query(\OC\Core\Command\App\Update::class)); |
|
79 | + |
|
80 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class)); |
|
81 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class)); |
|
82 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class)); |
|
83 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class)); |
|
84 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); |
|
85 | + |
|
86 | + $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
87 | + $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
88 | + $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
89 | + |
|
90 | + $application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class)); |
|
91 | + |
|
92 | + $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
93 | + $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
94 | + $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
95 | + $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
96 | + $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
97 | + $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
98 | + $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
99 | + $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
100 | + |
|
101 | + $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
102 | + $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
103 | + $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class))); |
|
104 | + $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); |
|
105 | + $application->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); |
|
106 | + $application->add(new OC\Core\Command\Db\AddMissingPrimaryKeys(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); |
|
107 | + $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class))); |
|
108 | + $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->get(\OC\DB\Connection::class))); |
|
109 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getAppManager())); |
|
110 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->get(\OC\DB\Connection::class))); |
|
111 | + $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getConfig())); |
|
112 | + |
|
113 | + $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
114 | + $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
115 | + $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); |
|
116 | + $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); |
|
117 | + $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
118 | + $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
119 | + $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
120 | + \OC::$server->getEncryptionManager(), |
|
121 | + \OC::$server->getAppManager(), |
|
122 | + \OC::$server->getConfig(), |
|
123 | + new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
124 | + new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
125 | + ); |
|
126 | + |
|
127 | + $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
128 | + $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
129 | + |
|
130 | + $view = new \OC\Files\View(); |
|
131 | + $util = new \OC\Encryption\Util( |
|
132 | + $view, |
|
133 | + \OC::$server->getUserManager(), |
|
134 | + \OC::$server->getGroupManager(), |
|
135 | + \OC::$server->getConfig() |
|
136 | + ); |
|
137 | + $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
138 | + $view, |
|
139 | + \OC::$server->getUserManager(), |
|
140 | + \OC::$server->getConfig(), |
|
141 | + $util, |
|
142 | + new \Symfony\Component\Console\Helper\QuestionHelper() |
|
143 | + ) |
|
144 | + ); |
|
145 | + $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
146 | + $application->add(new OC\Core\Command\Encryption\MigrateKeyStorage( |
|
147 | + $view, |
|
148 | + \OC::$server->getUserManager(), |
|
149 | + \OC::$server->getConfig(), |
|
150 | + $util, |
|
151 | + \OC::$server->getCrypto() |
|
152 | + ) |
|
153 | + ); |
|
154 | + |
|
155 | + $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
156 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
157 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
158 | + $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
159 | + $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
160 | + $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
161 | + |
|
162 | + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
163 | + $application->add(new OC\Core\Command\Maintenance\Repair( |
|
164 | + new \OC\Repair([], \OC::$server->getEventDispatcher()), |
|
165 | + \OC::$server->getConfig(), |
|
166 | + \OC::$server->getEventDispatcher(), |
|
167 | + \OC::$server->getAppManager() |
|
168 | + )); |
|
169 | + |
|
170 | + $application->add(\OC::$server->query(\OC\Core\Command\Preview\Repair::class)); |
|
171 | + |
|
172 | + $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
173 | + $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
174 | + $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
175 | + $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
176 | + $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
177 | + $application->add(\OC::$server->get(\OC\Core\Command\User\Report::class)); |
|
178 | + $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
179 | + $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
180 | + $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
181 | + $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
182 | + $application->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\Security\ICrypto::class))); |
|
183 | + |
|
184 | + $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); |
|
185 | + $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); |
|
186 | + $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
187 | + $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
188 | + $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
189 | + $application->add(new OC\Core\Command\Group\Info(\OC::$server->get(\OCP\IGroupManager::class))); |
|
190 | + |
|
191 | + $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(), \OC::$server->getL10N('core'))); |
|
192 | + $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager())); |
|
193 | + $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager())); |
|
194 | + $application->add(new OC\Core\Command\Security\ResetBruteforceAttempts(\OC::$server->getBruteForceThrottler())); |
|
195 | 195 | } else { |
196 | - $application->add(\OC::$server->get(\OC\Core\Command\Maintenance\Install::class)); |
|
196 | + $application->add(\OC::$server->get(\OC\Core\Command\Maintenance\Install::class)); |
|
197 | 197 | } |
@@ -32,74 +32,74 @@ |
||
32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
33 | 33 | |
34 | 34 | class ListCommand extends Base { |
35 | - /** @var IGroupManager */ |
|
36 | - protected $groupManager; |
|
35 | + /** @var IGroupManager */ |
|
36 | + protected $groupManager; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param IGroupManager $groupManager |
|
40 | - */ |
|
41 | - public function __construct(IGroupManager $groupManager) { |
|
42 | - $this->groupManager = $groupManager; |
|
43 | - parent::__construct(); |
|
44 | - } |
|
38 | + /** |
|
39 | + * @param IGroupManager $groupManager |
|
40 | + */ |
|
41 | + public function __construct(IGroupManager $groupManager) { |
|
42 | + $this->groupManager = $groupManager; |
|
43 | + parent::__construct(); |
|
44 | + } |
|
45 | 45 | |
46 | - protected function configure() { |
|
47 | - $this |
|
48 | - ->setName('group:list') |
|
49 | - ->setDescription('list configured groups') |
|
50 | - ->addOption( |
|
51 | - 'limit', |
|
52 | - 'l', |
|
53 | - InputOption::VALUE_OPTIONAL, |
|
54 | - 'Number of groups to retrieve', |
|
55 | - 500 |
|
56 | - )->addOption( |
|
57 | - 'offset', |
|
58 | - 'o', |
|
59 | - InputOption::VALUE_OPTIONAL, |
|
60 | - 'Offset for retrieving groups', |
|
61 | - 0 |
|
62 | - )->addOption( |
|
63 | - 'info', |
|
64 | - 'i', |
|
65 | - InputOption::VALUE_NONE, |
|
66 | - 'Show additional info (backend)' |
|
67 | - )->addOption( |
|
68 | - 'output', |
|
69 | - null, |
|
70 | - InputOption::VALUE_OPTIONAL, |
|
71 | - 'Output format (plain, json or json_pretty, default is plain)', |
|
72 | - $this->defaultOutputFormat |
|
73 | - ); |
|
74 | - } |
|
46 | + protected function configure() { |
|
47 | + $this |
|
48 | + ->setName('group:list') |
|
49 | + ->setDescription('list configured groups') |
|
50 | + ->addOption( |
|
51 | + 'limit', |
|
52 | + 'l', |
|
53 | + InputOption::VALUE_OPTIONAL, |
|
54 | + 'Number of groups to retrieve', |
|
55 | + 500 |
|
56 | + )->addOption( |
|
57 | + 'offset', |
|
58 | + 'o', |
|
59 | + InputOption::VALUE_OPTIONAL, |
|
60 | + 'Offset for retrieving groups', |
|
61 | + 0 |
|
62 | + )->addOption( |
|
63 | + 'info', |
|
64 | + 'i', |
|
65 | + InputOption::VALUE_NONE, |
|
66 | + 'Show additional info (backend)' |
|
67 | + )->addOption( |
|
68 | + 'output', |
|
69 | + null, |
|
70 | + InputOption::VALUE_OPTIONAL, |
|
71 | + 'Output format (plain, json or json_pretty, default is plain)', |
|
72 | + $this->defaultOutputFormat |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
77 | - $groups = $this->groupManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset')); |
|
78 | - $this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups, (bool)$input->getOption('info'))); |
|
79 | - return 0; |
|
80 | - } |
|
76 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
77 | + $groups = $this->groupManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset')); |
|
78 | + $this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups, (bool)$input->getOption('info'))); |
|
79 | + return 0; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param IGroup[] $groups |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - private function formatGroups(array $groups, bool $addInfo = false) { |
|
87 | - $keys = array_map(function (IGroup $group) { |
|
88 | - return $group->getGID(); |
|
89 | - }, $groups); |
|
82 | + /** |
|
83 | + * @param IGroup[] $groups |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + private function formatGroups(array $groups, bool $addInfo = false) { |
|
87 | + $keys = array_map(function (IGroup $group) { |
|
88 | + return $group->getGID(); |
|
89 | + }, $groups); |
|
90 | 90 | |
91 | - if ($addInfo) { |
|
92 | - $values = array_map(function (IGroup $group) { |
|
93 | - return [ |
|
94 | - 'backends' => $group->getBackendNames(), |
|
95 | - 'users' => array_keys($group->getUsers()), |
|
96 | - ]; |
|
97 | - }, $groups); |
|
98 | - } else { |
|
99 | - $values = array_map(function (IGroup $group) { |
|
100 | - return array_keys($group->getUsers()); |
|
101 | - }, $groups); |
|
102 | - } |
|
103 | - return array_combine($keys, $values); |
|
104 | - } |
|
91 | + if ($addInfo) { |
|
92 | + $values = array_map(function (IGroup $group) { |
|
93 | + return [ |
|
94 | + 'backends' => $group->getBackendNames(), |
|
95 | + 'users' => array_keys($group->getUsers()), |
|
96 | + ]; |
|
97 | + }, $groups); |
|
98 | + } else { |
|
99 | + $values = array_map(function (IGroup $group) { |
|
100 | + return array_keys($group->getUsers()); |
|
101 | + }, $groups); |
|
102 | + } |
|
103 | + return array_combine($keys, $values); |
|
104 | + } |
|
105 | 105 | } |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | protected function execute(InputInterface $input, OutputInterface $output): int { |
77 | - $groups = $this->groupManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset')); |
|
78 | - $this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups, (bool)$input->getOption('info'))); |
|
77 | + $groups = $this->groupManager->search('', (int) $input->getOption('limit'), (int) $input->getOption('offset')); |
|
78 | + $this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups, (bool) $input->getOption('info'))); |
|
79 | 79 | return 0; |
80 | 80 | } |
81 | 81 | |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | * @return array |
85 | 85 | */ |
86 | 86 | private function formatGroups(array $groups, bool $addInfo = false) { |
87 | - $keys = array_map(function (IGroup $group) { |
|
87 | + $keys = array_map(function(IGroup $group) { |
|
88 | 88 | return $group->getGID(); |
89 | 89 | }, $groups); |
90 | 90 | |
91 | 91 | if ($addInfo) { |
92 | - $values = array_map(function (IGroup $group) { |
|
92 | + $values = array_map(function(IGroup $group) { |
|
93 | 93 | return [ |
94 | 94 | 'backends' => $group->getBackendNames(), |
95 | 95 | 'users' => array_keys($group->getUsers()), |
96 | 96 | ]; |
97 | 97 | }, $groups); |
98 | 98 | } else { |
99 | - $values = array_map(function (IGroup $group) { |
|
99 | + $values = array_map(function(IGroup $group) { |
|
100 | 100 | return array_keys($group->getUsers()); |
101 | 101 | }, $groups); |
102 | 102 | } |
@@ -35,49 +35,49 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class Info extends Base { |
38 | - /** @var IGroupManager */ |
|
39 | - protected $groupManager; |
|
38 | + /** @var IGroupManager */ |
|
39 | + protected $groupManager; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IGroupManager $groupManager |
|
43 | - */ |
|
44 | - public function __construct(IGroupManager $groupManager) { |
|
45 | - $this->groupManager = $groupManager; |
|
46 | - parent::__construct(); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param IGroupManager $groupManager |
|
43 | + */ |
|
44 | + public function __construct(IGroupManager $groupManager) { |
|
45 | + $this->groupManager = $groupManager; |
|
46 | + parent::__construct(); |
|
47 | + } |
|
48 | 48 | |
49 | - protected function configure() { |
|
50 | - $this |
|
51 | - ->setName('group:info') |
|
52 | - ->setDescription('Show information about a group') |
|
53 | - ->addArgument( |
|
54 | - 'groupid', |
|
55 | - InputArgument::REQUIRED, |
|
56 | - 'Group id' |
|
57 | - )->addOption( |
|
58 | - 'output', |
|
59 | - null, |
|
60 | - InputOption::VALUE_OPTIONAL, |
|
61 | - 'Output format (plain, json or json_pretty, default is plain)', |
|
62 | - $this->defaultOutputFormat |
|
63 | - ); |
|
64 | - } |
|
49 | + protected function configure() { |
|
50 | + $this |
|
51 | + ->setName('group:info') |
|
52 | + ->setDescription('Show information about a group') |
|
53 | + ->addArgument( |
|
54 | + 'groupid', |
|
55 | + InputArgument::REQUIRED, |
|
56 | + 'Group id' |
|
57 | + )->addOption( |
|
58 | + 'output', |
|
59 | + null, |
|
60 | + InputOption::VALUE_OPTIONAL, |
|
61 | + 'Output format (plain, json or json_pretty, default is plain)', |
|
62 | + $this->defaultOutputFormat |
|
63 | + ); |
|
64 | + } |
|
65 | 65 | |
66 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | - $gid = $input->getArgument('groupid'); |
|
68 | - $group = $this->groupManager->get($gid); |
|
69 | - if (!$group instanceof IGroup) { |
|
70 | - $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
71 | - return 1; |
|
72 | - } else { |
|
73 | - $groupOutput = [ |
|
74 | - 'groupID' => $gid, |
|
75 | - 'displayName' => $group->getDisplayName(), |
|
76 | - 'backends' => $group->getBackendNames(), |
|
77 | - ]; |
|
66 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | + $gid = $input->getArgument('groupid'); |
|
68 | + $group = $this->groupManager->get($gid); |
|
69 | + if (!$group instanceof IGroup) { |
|
70 | + $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
71 | + return 1; |
|
72 | + } else { |
|
73 | + $groupOutput = [ |
|
74 | + 'groupID' => $gid, |
|
75 | + 'displayName' => $group->getDisplayName(), |
|
76 | + 'backends' => $group->getBackendNames(), |
|
77 | + ]; |
|
78 | 78 | |
79 | - $this->writeArrayInOutputFormat($input, $output, $groupOutput); |
|
80 | - return 0; |
|
81 | - } |
|
82 | - } |
|
79 | + $this->writeArrayInOutputFormat($input, $output, $groupOutput); |
|
80 | + return 0; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | $gid = $input->getArgument('groupid'); |
68 | 68 | $group = $this->groupManager->get($gid); |
69 | 69 | if (!$group instanceof IGroup) { |
70 | - $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
70 | + $output->writeln('<error>Group "'.$gid.'" does not exist.</error>'); |
|
71 | 71 | return 1; |
72 | 72 | } else { |
73 | 73 | $groupOutput = [ |
@@ -32,280 +32,280 @@ |
||
32 | 32 | use OCP\Group\Backend\IGetDisplayNameBackend; |
33 | 33 | |
34 | 34 | class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend { |
35 | - private $backends = []; |
|
36 | - private $refBackend = null; |
|
35 | + private $backends = []; |
|
36 | + private $refBackend = null; |
|
37 | 37 | |
38 | - public function __construct(Helper $helper, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) { |
|
39 | - parent::__construct($ldap); |
|
40 | - $serverConfigPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
41 | - foreach ($serverConfigPrefixes as $configPrefix) { |
|
42 | - $this->backends[$configPrefix] = |
|
43 | - new \OCA\User_LDAP\Group_LDAP($this->getAccess($configPrefix), $groupPluginManager); |
|
44 | - if (is_null($this->refBackend)) { |
|
45 | - $this->refBackend = &$this->backends[$configPrefix]; |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
38 | + public function __construct(Helper $helper, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) { |
|
39 | + parent::__construct($ldap); |
|
40 | + $serverConfigPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
41 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
42 | + $this->backends[$configPrefix] = |
|
43 | + new \OCA\User_LDAP\Group_LDAP($this->getAccess($configPrefix), $groupPluginManager); |
|
44 | + if (is_null($this->refBackend)) { |
|
45 | + $this->refBackend = &$this->backends[$configPrefix]; |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Tries the backends one after the other until a positive result is returned from the specified method |
|
52 | - * |
|
53 | - * @param string $id the gid connected to the request |
|
54 | - * @param string $method the method of the group backend that shall be called |
|
55 | - * @param array $parameters an array of parameters to be passed |
|
56 | - * @return mixed the result of the method or false |
|
57 | - */ |
|
58 | - protected function walkBackends($id, $method, $parameters) { |
|
59 | - $gid = $id; |
|
60 | - $cacheKey = $this->getGroupCacheKey($gid); |
|
61 | - foreach ($this->backends as $configPrefix => $backend) { |
|
62 | - if ($result = call_user_func_array([$backend, $method], $parameters)) { |
|
63 | - if (!$this->isSingleBackend()) { |
|
64 | - $this->writeToCache($cacheKey, $configPrefix); |
|
65 | - } |
|
66 | - return $result; |
|
67 | - } |
|
68 | - } |
|
69 | - return false; |
|
70 | - } |
|
50 | + /** |
|
51 | + * Tries the backends one after the other until a positive result is returned from the specified method |
|
52 | + * |
|
53 | + * @param string $id the gid connected to the request |
|
54 | + * @param string $method the method of the group backend that shall be called |
|
55 | + * @param array $parameters an array of parameters to be passed |
|
56 | + * @return mixed the result of the method or false |
|
57 | + */ |
|
58 | + protected function walkBackends($id, $method, $parameters) { |
|
59 | + $gid = $id; |
|
60 | + $cacheKey = $this->getGroupCacheKey($gid); |
|
61 | + foreach ($this->backends as $configPrefix => $backend) { |
|
62 | + if ($result = call_user_func_array([$backend, $method], $parameters)) { |
|
63 | + if (!$this->isSingleBackend()) { |
|
64 | + $this->writeToCache($cacheKey, $configPrefix); |
|
65 | + } |
|
66 | + return $result; |
|
67 | + } |
|
68 | + } |
|
69 | + return false; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Asks the backend connected to the server that supposely takes care of the gid from the request. |
|
74 | - * |
|
75 | - * @param string $id the gid connected to the request |
|
76 | - * @param string $method the method of the group backend that shall be called |
|
77 | - * @param array $parameters an array of parameters to be passed |
|
78 | - * @param mixed $passOnWhen the result matches this variable |
|
79 | - * @return mixed the result of the method or false |
|
80 | - */ |
|
81 | - protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen) { |
|
82 | - $gid = $id; |
|
83 | - $cacheKey = $this->getGroupCacheKey($gid); |
|
84 | - $prefix = $this->getFromCache($cacheKey); |
|
85 | - //in case the uid has been found in the past, try this stored connection first |
|
86 | - if (!is_null($prefix)) { |
|
87 | - if (isset($this->backends[$prefix])) { |
|
88 | - $result = call_user_func_array([$this->backends[$prefix], $method], $parameters); |
|
89 | - if ($result === $passOnWhen) { |
|
90 | - //not found here, reset cache to null if group vanished |
|
91 | - //because sometimes methods return false with a reason |
|
92 | - $groupExists = call_user_func_array( |
|
93 | - [$this->backends[$prefix], 'groupExists'], |
|
94 | - [$gid] |
|
95 | - ); |
|
96 | - if (!$groupExists) { |
|
97 | - $this->writeToCache($cacheKey, null); |
|
98 | - } |
|
99 | - } |
|
100 | - return $result; |
|
101 | - } |
|
102 | - } |
|
103 | - return false; |
|
104 | - } |
|
72 | + /** |
|
73 | + * Asks the backend connected to the server that supposely takes care of the gid from the request. |
|
74 | + * |
|
75 | + * @param string $id the gid connected to the request |
|
76 | + * @param string $method the method of the group backend that shall be called |
|
77 | + * @param array $parameters an array of parameters to be passed |
|
78 | + * @param mixed $passOnWhen the result matches this variable |
|
79 | + * @return mixed the result of the method or false |
|
80 | + */ |
|
81 | + protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen) { |
|
82 | + $gid = $id; |
|
83 | + $cacheKey = $this->getGroupCacheKey($gid); |
|
84 | + $prefix = $this->getFromCache($cacheKey); |
|
85 | + //in case the uid has been found in the past, try this stored connection first |
|
86 | + if (!is_null($prefix)) { |
|
87 | + if (isset($this->backends[$prefix])) { |
|
88 | + $result = call_user_func_array([$this->backends[$prefix], $method], $parameters); |
|
89 | + if ($result === $passOnWhen) { |
|
90 | + //not found here, reset cache to null if group vanished |
|
91 | + //because sometimes methods return false with a reason |
|
92 | + $groupExists = call_user_func_array( |
|
93 | + [$this->backends[$prefix], 'groupExists'], |
|
94 | + [$gid] |
|
95 | + ); |
|
96 | + if (!$groupExists) { |
|
97 | + $this->writeToCache($cacheKey, null); |
|
98 | + } |
|
99 | + } |
|
100 | + return $result; |
|
101 | + } |
|
102 | + } |
|
103 | + return false; |
|
104 | + } |
|
105 | 105 | |
106 | - protected function activeBackends(): int { |
|
107 | - return count($this->backends); |
|
108 | - } |
|
106 | + protected function activeBackends(): int { |
|
107 | + return count($this->backends); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * is user in group? |
|
112 | - * |
|
113 | - * @param string $uid uid of the user |
|
114 | - * @param string $gid gid of the group |
|
115 | - * @return bool |
|
116 | - * |
|
117 | - * Checks whether the user is member of a group or not. |
|
118 | - */ |
|
119 | - public function inGroup($uid, $gid) { |
|
120 | - return $this->handleRequest($gid, 'inGroup', [$uid, $gid]); |
|
121 | - } |
|
110 | + /** |
|
111 | + * is user in group? |
|
112 | + * |
|
113 | + * @param string $uid uid of the user |
|
114 | + * @param string $gid gid of the group |
|
115 | + * @return bool |
|
116 | + * |
|
117 | + * Checks whether the user is member of a group or not. |
|
118 | + */ |
|
119 | + public function inGroup($uid, $gid) { |
|
120 | + return $this->handleRequest($gid, 'inGroup', [$uid, $gid]); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Get all groups a user belongs to |
|
125 | - * |
|
126 | - * @param string $uid Name of the user |
|
127 | - * @return string[] with group names |
|
128 | - * |
|
129 | - * This function fetches all groups a user belongs to. It does not check |
|
130 | - * if the user exists at all. |
|
131 | - */ |
|
132 | - public function getUserGroups($uid) { |
|
133 | - $groups = []; |
|
123 | + /** |
|
124 | + * Get all groups a user belongs to |
|
125 | + * |
|
126 | + * @param string $uid Name of the user |
|
127 | + * @return string[] with group names |
|
128 | + * |
|
129 | + * This function fetches all groups a user belongs to. It does not check |
|
130 | + * if the user exists at all. |
|
131 | + */ |
|
132 | + public function getUserGroups($uid) { |
|
133 | + $groups = []; |
|
134 | 134 | |
135 | - foreach ($this->backends as $backend) { |
|
136 | - $backendGroups = $backend->getUserGroups($uid); |
|
137 | - if (is_array($backendGroups)) { |
|
138 | - $groups = array_merge($groups, $backendGroups); |
|
139 | - } |
|
140 | - } |
|
135 | + foreach ($this->backends as $backend) { |
|
136 | + $backendGroups = $backend->getUserGroups($uid); |
|
137 | + if (is_array($backendGroups)) { |
|
138 | + $groups = array_merge($groups, $backendGroups); |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | - return $groups; |
|
143 | - } |
|
142 | + return $groups; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * get a list of all users in a group |
|
147 | - * |
|
148 | - * @return string[] with user ids |
|
149 | - */ |
|
150 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
151 | - $users = []; |
|
145 | + /** |
|
146 | + * get a list of all users in a group |
|
147 | + * |
|
148 | + * @return string[] with user ids |
|
149 | + */ |
|
150 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
151 | + $users = []; |
|
152 | 152 | |
153 | - foreach ($this->backends as $backend) { |
|
154 | - $backendUsers = $backend->usersInGroup($gid, $search, $limit, $offset); |
|
155 | - if (is_array($backendUsers)) { |
|
156 | - $users = array_merge($users, $backendUsers); |
|
157 | - } |
|
158 | - } |
|
153 | + foreach ($this->backends as $backend) { |
|
154 | + $backendUsers = $backend->usersInGroup($gid, $search, $limit, $offset); |
|
155 | + if (is_array($backendUsers)) { |
|
156 | + $users = array_merge($users, $backendUsers); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - return $users; |
|
161 | - } |
|
160 | + return $users; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @param string $gid |
|
165 | - * @return bool |
|
166 | - */ |
|
167 | - public function createGroup($gid) { |
|
168 | - return $this->handleRequest( |
|
169 | - $gid, 'createGroup', [$gid]); |
|
170 | - } |
|
163 | + /** |
|
164 | + * @param string $gid |
|
165 | + * @return bool |
|
166 | + */ |
|
167 | + public function createGroup($gid) { |
|
168 | + return $this->handleRequest( |
|
169 | + $gid, 'createGroup', [$gid]); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * delete a group |
|
174 | - * |
|
175 | - * @param string $gid gid of the group to delete |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - public function deleteGroup($gid) { |
|
179 | - return $this->handleRequest( |
|
180 | - $gid, 'deleteGroup', [$gid]); |
|
181 | - } |
|
172 | + /** |
|
173 | + * delete a group |
|
174 | + * |
|
175 | + * @param string $gid gid of the group to delete |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + public function deleteGroup($gid) { |
|
179 | + return $this->handleRequest( |
|
180 | + $gid, 'deleteGroup', [$gid]); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Add a user to a group |
|
185 | - * |
|
186 | - * @param string $uid Name of the user to add to group |
|
187 | - * @param string $gid Name of the group in which add the user |
|
188 | - * @return bool |
|
189 | - * |
|
190 | - * Adds a user to a group. |
|
191 | - */ |
|
192 | - public function addToGroup($uid, $gid) { |
|
193 | - return $this->handleRequest( |
|
194 | - $gid, 'addToGroup', [$uid, $gid]); |
|
195 | - } |
|
183 | + /** |
|
184 | + * Add a user to a group |
|
185 | + * |
|
186 | + * @param string $uid Name of the user to add to group |
|
187 | + * @param string $gid Name of the group in which add the user |
|
188 | + * @return bool |
|
189 | + * |
|
190 | + * Adds a user to a group. |
|
191 | + */ |
|
192 | + public function addToGroup($uid, $gid) { |
|
193 | + return $this->handleRequest( |
|
194 | + $gid, 'addToGroup', [$uid, $gid]); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Removes a user from a group |
|
199 | - * |
|
200 | - * @param string $uid Name of the user to remove from group |
|
201 | - * @param string $gid Name of the group from which remove the user |
|
202 | - * @return bool |
|
203 | - * |
|
204 | - * removes the user from a group. |
|
205 | - */ |
|
206 | - public function removeFromGroup($uid, $gid) { |
|
207 | - return $this->handleRequest( |
|
208 | - $gid, 'removeFromGroup', [$uid, $gid]); |
|
209 | - } |
|
197 | + /** |
|
198 | + * Removes a user from a group |
|
199 | + * |
|
200 | + * @param string $uid Name of the user to remove from group |
|
201 | + * @param string $gid Name of the group from which remove the user |
|
202 | + * @return bool |
|
203 | + * |
|
204 | + * removes the user from a group. |
|
205 | + */ |
|
206 | + public function removeFromGroup($uid, $gid) { |
|
207 | + return $this->handleRequest( |
|
208 | + $gid, 'removeFromGroup', [$uid, $gid]); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * returns the number of users in a group, who match the search term |
|
213 | - * |
|
214 | - * @param string $gid the internal group name |
|
215 | - * @param string $search optional, a search string |
|
216 | - * @return int|bool |
|
217 | - */ |
|
218 | - public function countUsersInGroup($gid, $search = '') { |
|
219 | - return $this->handleRequest( |
|
220 | - $gid, 'countUsersInGroup', [$gid, $search]); |
|
221 | - } |
|
211 | + /** |
|
212 | + * returns the number of users in a group, who match the search term |
|
213 | + * |
|
214 | + * @param string $gid the internal group name |
|
215 | + * @param string $search optional, a search string |
|
216 | + * @return int|bool |
|
217 | + */ |
|
218 | + public function countUsersInGroup($gid, $search = '') { |
|
219 | + return $this->handleRequest( |
|
220 | + $gid, 'countUsersInGroup', [$gid, $search]); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * get an array with group details |
|
225 | - * |
|
226 | - * @param string $gid |
|
227 | - * @return array|false |
|
228 | - */ |
|
229 | - public function getGroupDetails($gid) { |
|
230 | - return $this->handleRequest( |
|
231 | - $gid, 'getGroupDetails', [$gid]); |
|
232 | - } |
|
223 | + /** |
|
224 | + * get an array with group details |
|
225 | + * |
|
226 | + * @param string $gid |
|
227 | + * @return array|false |
|
228 | + */ |
|
229 | + public function getGroupDetails($gid) { |
|
230 | + return $this->handleRequest( |
|
231 | + $gid, 'getGroupDetails', [$gid]); |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * get a list of all groups |
|
236 | - * |
|
237 | - * @return string[] with group names |
|
238 | - * |
|
239 | - * Returns a list with all groups |
|
240 | - */ |
|
241 | - public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
242 | - $groups = []; |
|
234 | + /** |
|
235 | + * get a list of all groups |
|
236 | + * |
|
237 | + * @return string[] with group names |
|
238 | + * |
|
239 | + * Returns a list with all groups |
|
240 | + */ |
|
241 | + public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
242 | + $groups = []; |
|
243 | 243 | |
244 | - foreach ($this->backends as $backend) { |
|
245 | - $backendGroups = $backend->getGroups($search, $limit, $offset); |
|
246 | - if (is_array($backendGroups)) { |
|
247 | - $groups = array_merge($groups, $backendGroups); |
|
248 | - } |
|
249 | - } |
|
244 | + foreach ($this->backends as $backend) { |
|
245 | + $backendGroups = $backend->getGroups($search, $limit, $offset); |
|
246 | + if (is_array($backendGroups)) { |
|
247 | + $groups = array_merge($groups, $backendGroups); |
|
248 | + } |
|
249 | + } |
|
250 | 250 | |
251 | - return $groups; |
|
252 | - } |
|
251 | + return $groups; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * check if a group exists |
|
256 | - * |
|
257 | - * @param string $gid |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public function groupExists($gid) { |
|
261 | - return $this->handleRequest($gid, 'groupExists', [$gid]); |
|
262 | - } |
|
254 | + /** |
|
255 | + * check if a group exists |
|
256 | + * |
|
257 | + * @param string $gid |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public function groupExists($gid) { |
|
261 | + return $this->handleRequest($gid, 'groupExists', [$gid]); |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * Check if backend implements actions |
|
266 | - * |
|
267 | - * @param int $actions bitwise-or'ed actions |
|
268 | - * @return boolean |
|
269 | - * |
|
270 | - * Returns the supported actions as int to be |
|
271 | - * compared with \OCP\GroupInterface::CREATE_GROUP etc. |
|
272 | - */ |
|
273 | - public function implementsActions($actions) { |
|
274 | - //it's the same across all our user backends obviously |
|
275 | - return $this->refBackend->implementsActions($actions); |
|
276 | - } |
|
264 | + /** |
|
265 | + * Check if backend implements actions |
|
266 | + * |
|
267 | + * @param int $actions bitwise-or'ed actions |
|
268 | + * @return boolean |
|
269 | + * |
|
270 | + * Returns the supported actions as int to be |
|
271 | + * compared with \OCP\GroupInterface::CREATE_GROUP etc. |
|
272 | + */ |
|
273 | + public function implementsActions($actions) { |
|
274 | + //it's the same across all our user backends obviously |
|
275 | + return $this->refBackend->implementsActions($actions); |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Return access for LDAP interaction. |
|
280 | - * |
|
281 | - * @param string $gid |
|
282 | - * @return Access instance of Access for LDAP interaction |
|
283 | - */ |
|
284 | - public function getLDAPAccess($gid) { |
|
285 | - return $this->handleRequest($gid, 'getLDAPAccess', [$gid]); |
|
286 | - } |
|
278 | + /** |
|
279 | + * Return access for LDAP interaction. |
|
280 | + * |
|
281 | + * @param string $gid |
|
282 | + * @return Access instance of Access for LDAP interaction |
|
283 | + */ |
|
284 | + public function getLDAPAccess($gid) { |
|
285 | + return $this->handleRequest($gid, 'getLDAPAccess', [$gid]); |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * Return a new LDAP connection for the specified group. |
|
290 | - * The connection needs to be closed manually. |
|
291 | - * |
|
292 | - * @param string $gid |
|
293 | - * @return resource of the LDAP connection |
|
294 | - */ |
|
295 | - public function getNewLDAPConnection($gid) { |
|
296 | - return $this->handleRequest($gid, 'getNewLDAPConnection', [$gid]); |
|
297 | - } |
|
288 | + /** |
|
289 | + * Return a new LDAP connection for the specified group. |
|
290 | + * The connection needs to be closed manually. |
|
291 | + * |
|
292 | + * @param string $gid |
|
293 | + * @return resource of the LDAP connection |
|
294 | + */ |
|
295 | + public function getNewLDAPConnection($gid) { |
|
296 | + return $this->handleRequest($gid, 'getNewLDAPConnection', [$gid]); |
|
297 | + } |
|
298 | 298 | |
299 | - public function getDisplayName(string $gid): string { |
|
300 | - return $this->handleRequest($gid, 'getDisplayName', [$gid]); |
|
301 | - } |
|
299 | + public function getDisplayName(string $gid): string { |
|
300 | + return $this->handleRequest($gid, 'getDisplayName', [$gid]); |
|
301 | + } |
|
302 | 302 | |
303 | - /** |
|
304 | - * Backend name to be shown in group management |
|
305 | - * @return string the name of the backend to be shown |
|
306 | - * @since 22.0.0 |
|
307 | - */ |
|
308 | - public function getBackendName(): string { |
|
309 | - return 'LDAP'; |
|
310 | - } |
|
303 | + /** |
|
304 | + * Backend name to be shown in group management |
|
305 | + * @return string the name of the backend to be shown |
|
306 | + * @since 22.0.0 |
|
307 | + */ |
|
308 | + public function getBackendName(): string { |
|
309 | + return 'LDAP'; |
|
310 | + } |
|
311 | 311 | } |