-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathDeletedUsersIndex.php
More file actions
91 lines (79 loc) · 2.18 KB
/
Copy pathDeletedUsersIndex.php
File metadata and controls
91 lines (79 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\Config\IUserConfig;
use OCP\PreConditionNotMetException;
use OCP\Share\IManager;
/**
* Class DeletedUsersIndex
* @package OCA\User_LDAP
*/
class DeletedUsersIndex {
protected ?array $deletedUsers = null;
public function __construct(
protected IUserConfig $userConfig,
protected UserMapping $mapping,
private IManager $shareManager,
) {
}
/**
* Reads LDAP users marked as deleted from the database.
*
* @return OfflineUser[]
*/
private function fetchDeletedUsers(): array {
$deletedUsers = $this->userConfig->searchUsersByValueBool('user_ldap', 'isDeleted', true);
$userObjects = [];
foreach ($deletedUsers as $user) {
$userObject = new OfflineUser($user, $this->userConfig, $this->mapping, $this->shareManager);
if ($userObject->getLastLogin() > $userObject->getDetectedOn()) {
$userObject->unmark();
} else {
$userObjects[] = $userObject;
}
}
$this->deletedUsers = $userObjects;
return $this->deletedUsers;
}
/**
* Returns all LDAP users that are marked as deleted.
*
* @return OfflineUser[]
*/
public function getUsers(): array {
if (is_array($this->deletedUsers)) {
return $this->deletedUsers;
}
return $this->fetchDeletedUsers();
}
/**
* Whether at least one user was detected as deleted.
*/
public function hasUsers(): bool {
if (!is_array($this->deletedUsers)) {
$this->fetchDeletedUsers();
}
return is_array($this->deletedUsers) && (count($this->deletedUsers) > 0);
}
/**
* Marks a user as deleted.
*
* @throws PreConditionNotMetException
*/
public function markUser(string $ocName): void {
if ($this->isUserMarked($ocName)) {
// the user is already marked, do not write to DB again
return;
}
$this->userConfig->setValueBool($ocName, 'user_ldap', 'isDeleted', true);
$this->userConfig->setValueInt($ocName, 'user_ldap', 'foundDeleted', time());
$this->deletedUsers = null;
}
public function isUserMarked(string $ocName): bool {
return $this->userConfig->getValueBool($ocName, 'user_ldap', 'isDeleted');
}
}