@@ -32,236 +32,236 @@ |
||
| 32 | 32 | use OCP\Share\IShare; |
| 33 | 33 | |
| 34 | 34 | class OfflineUser { |
| 35 | - /** |
|
| 36 | - * @var string $ocName |
|
| 37 | - */ |
|
| 38 | - protected $ocName; |
|
| 39 | - /** |
|
| 40 | - * @var string $dn |
|
| 41 | - */ |
|
| 42 | - protected $dn; |
|
| 43 | - /** |
|
| 44 | - * @var string $uid the UID as provided by LDAP |
|
| 45 | - */ |
|
| 46 | - protected $uid; |
|
| 47 | - /** |
|
| 48 | - * @var string $displayName |
|
| 49 | - */ |
|
| 50 | - protected $displayName; |
|
| 51 | - /** |
|
| 52 | - * @var string $homePath |
|
| 53 | - */ |
|
| 54 | - protected $homePath; |
|
| 55 | - /** |
|
| 56 | - * @var string $lastLogin the timestamp of the last login |
|
| 57 | - */ |
|
| 58 | - protected $lastLogin; |
|
| 59 | - /** |
|
| 60 | - * @var string $foundDeleted the timestamp when the user was detected as unavailable |
|
| 61 | - */ |
|
| 62 | - protected $foundDeleted; |
|
| 63 | - /** |
|
| 64 | - * @var string $email |
|
| 65 | - */ |
|
| 66 | - protected $email; |
|
| 67 | - /** |
|
| 68 | - * @var bool $hasActiveShares |
|
| 69 | - */ |
|
| 70 | - protected $hasActiveShares; |
|
| 71 | - /** |
|
| 72 | - * @var IConfig $config |
|
| 73 | - */ |
|
| 74 | - protected $config; |
|
| 75 | - /** |
|
| 76 | - * @var IDBConnection $db |
|
| 77 | - */ |
|
| 78 | - protected $db; |
|
| 79 | - /** |
|
| 80 | - * @var \OCA\User_LDAP\Mapping\UserMapping |
|
| 81 | - */ |
|
| 82 | - protected $mapping; |
|
| 83 | - /** @var IManager */ |
|
| 84 | - private $shareManager; |
|
| 35 | + /** |
|
| 36 | + * @var string $ocName |
|
| 37 | + */ |
|
| 38 | + protected $ocName; |
|
| 39 | + /** |
|
| 40 | + * @var string $dn |
|
| 41 | + */ |
|
| 42 | + protected $dn; |
|
| 43 | + /** |
|
| 44 | + * @var string $uid the UID as provided by LDAP |
|
| 45 | + */ |
|
| 46 | + protected $uid; |
|
| 47 | + /** |
|
| 48 | + * @var string $displayName |
|
| 49 | + */ |
|
| 50 | + protected $displayName; |
|
| 51 | + /** |
|
| 52 | + * @var string $homePath |
|
| 53 | + */ |
|
| 54 | + protected $homePath; |
|
| 55 | + /** |
|
| 56 | + * @var string $lastLogin the timestamp of the last login |
|
| 57 | + */ |
|
| 58 | + protected $lastLogin; |
|
| 59 | + /** |
|
| 60 | + * @var string $foundDeleted the timestamp when the user was detected as unavailable |
|
| 61 | + */ |
|
| 62 | + protected $foundDeleted; |
|
| 63 | + /** |
|
| 64 | + * @var string $email |
|
| 65 | + */ |
|
| 66 | + protected $email; |
|
| 67 | + /** |
|
| 68 | + * @var bool $hasActiveShares |
|
| 69 | + */ |
|
| 70 | + protected $hasActiveShares; |
|
| 71 | + /** |
|
| 72 | + * @var IConfig $config |
|
| 73 | + */ |
|
| 74 | + protected $config; |
|
| 75 | + /** |
|
| 76 | + * @var IDBConnection $db |
|
| 77 | + */ |
|
| 78 | + protected $db; |
|
| 79 | + /** |
|
| 80 | + * @var \OCA\User_LDAP\Mapping\UserMapping |
|
| 81 | + */ |
|
| 82 | + protected $mapping; |
|
| 83 | + /** @var IManager */ |
|
| 84 | + private $shareManager; |
|
| 85 | 85 | |
| 86 | - public function __construct( |
|
| 87 | - $ocName, |
|
| 88 | - IConfig $config, |
|
| 89 | - UserMapping $mapping, |
|
| 90 | - IManager $shareManager |
|
| 91 | - ) { |
|
| 92 | - $this->ocName = $ocName; |
|
| 93 | - $this->config = $config; |
|
| 94 | - $this->mapping = $mapping; |
|
| 95 | - $this->shareManager = $shareManager; |
|
| 96 | - } |
|
| 86 | + public function __construct( |
|
| 87 | + $ocName, |
|
| 88 | + IConfig $config, |
|
| 89 | + UserMapping $mapping, |
|
| 90 | + IManager $shareManager |
|
| 91 | + ) { |
|
| 92 | + $this->ocName = $ocName; |
|
| 93 | + $this->config = $config; |
|
| 94 | + $this->mapping = $mapping; |
|
| 95 | + $this->shareManager = $shareManager; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * remove the Delete-flag from the user. |
|
| 100 | - */ |
|
| 101 | - public function unmark() { |
|
| 102 | - $this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted'); |
|
| 103 | - $this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted'); |
|
| 104 | - } |
|
| 98 | + /** |
|
| 99 | + * remove the Delete-flag from the user. |
|
| 100 | + */ |
|
| 101 | + public function unmark() { |
|
| 102 | + $this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted'); |
|
| 103 | + $this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted'); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * exports the user details in an assoc array |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - public function export() { |
|
| 111 | - $data = []; |
|
| 112 | - $data['ocName'] = $this->getOCName(); |
|
| 113 | - $data['dn'] = $this->getDN(); |
|
| 114 | - $data['uid'] = $this->getUID(); |
|
| 115 | - $data['displayName'] = $this->getDisplayName(); |
|
| 116 | - $data['homePath'] = $this->getHomePath(); |
|
| 117 | - $data['lastLogin'] = $this->getLastLogin(); |
|
| 118 | - $data['email'] = $this->getEmail(); |
|
| 119 | - $data['hasActiveShares'] = $this->getHasActiveShares(); |
|
| 106 | + /** |
|
| 107 | + * exports the user details in an assoc array |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + public function export() { |
|
| 111 | + $data = []; |
|
| 112 | + $data['ocName'] = $this->getOCName(); |
|
| 113 | + $data['dn'] = $this->getDN(); |
|
| 114 | + $data['uid'] = $this->getUID(); |
|
| 115 | + $data['displayName'] = $this->getDisplayName(); |
|
| 116 | + $data['homePath'] = $this->getHomePath(); |
|
| 117 | + $data['lastLogin'] = $this->getLastLogin(); |
|
| 118 | + $data['email'] = $this->getEmail(); |
|
| 119 | + $data['hasActiveShares'] = $this->getHasActiveShares(); |
|
| 120 | 120 | |
| 121 | - return $data; |
|
| 122 | - } |
|
| 121 | + return $data; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * getter for Nextcloud internal name |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function getOCName() { |
|
| 129 | - return $this->ocName; |
|
| 130 | - } |
|
| 124 | + /** |
|
| 125 | + * getter for Nextcloud internal name |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function getOCName() { |
|
| 129 | + return $this->ocName; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * getter for LDAP uid |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function getUID() { |
|
| 137 | - if ($this->uid === null) { |
|
| 138 | - $this->fetchDetails(); |
|
| 139 | - } |
|
| 140 | - return $this->uid; |
|
| 141 | - } |
|
| 132 | + /** |
|
| 133 | + * getter for LDAP uid |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function getUID() { |
|
| 137 | + if ($this->uid === null) { |
|
| 138 | + $this->fetchDetails(); |
|
| 139 | + } |
|
| 140 | + return $this->uid; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * getter for LDAP DN |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public function getDN() { |
|
| 148 | - if ($this->dn === null) { |
|
| 149 | - $dn = $this->mapping->getDNByName($this->ocName); |
|
| 150 | - $this->dn = ($dn !== false) ? $dn : ''; |
|
| 151 | - } |
|
| 152 | - return $this->dn; |
|
| 153 | - } |
|
| 143 | + /** |
|
| 144 | + * getter for LDAP DN |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public function getDN() { |
|
| 148 | + if ($this->dn === null) { |
|
| 149 | + $dn = $this->mapping->getDNByName($this->ocName); |
|
| 150 | + $this->dn = ($dn !== false) ? $dn : ''; |
|
| 151 | + } |
|
| 152 | + return $this->dn; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * getter for display name |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function getDisplayName() { |
|
| 160 | - if ($this->displayName === null) { |
|
| 161 | - $this->fetchDetails(); |
|
| 162 | - } |
|
| 163 | - return $this->displayName; |
|
| 164 | - } |
|
| 155 | + /** |
|
| 156 | + * getter for display name |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function getDisplayName() { |
|
| 160 | + if ($this->displayName === null) { |
|
| 161 | + $this->fetchDetails(); |
|
| 162 | + } |
|
| 163 | + return $this->displayName; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * getter for email |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function getEmail() { |
|
| 171 | - if ($this->email === null) { |
|
| 172 | - $this->fetchDetails(); |
|
| 173 | - } |
|
| 174 | - return $this->email; |
|
| 175 | - } |
|
| 166 | + /** |
|
| 167 | + * getter for email |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function getEmail() { |
|
| 171 | + if ($this->email === null) { |
|
| 172 | + $this->fetchDetails(); |
|
| 173 | + } |
|
| 174 | + return $this->email; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * getter for home directory path |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function getHomePath() { |
|
| 182 | - if ($this->homePath === null) { |
|
| 183 | - $this->fetchDetails(); |
|
| 184 | - } |
|
| 185 | - return $this->homePath; |
|
| 186 | - } |
|
| 177 | + /** |
|
| 178 | + * getter for home directory path |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function getHomePath() { |
|
| 182 | + if ($this->homePath === null) { |
|
| 183 | + $this->fetchDetails(); |
|
| 184 | + } |
|
| 185 | + return $this->homePath; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * getter for the last login timestamp |
|
| 190 | - * @return int |
|
| 191 | - */ |
|
| 192 | - public function getLastLogin() { |
|
| 193 | - if ($this->lastLogin === null) { |
|
| 194 | - $this->fetchDetails(); |
|
| 195 | - } |
|
| 196 | - return (int)$this->lastLogin; |
|
| 197 | - } |
|
| 188 | + /** |
|
| 189 | + * getter for the last login timestamp |
|
| 190 | + * @return int |
|
| 191 | + */ |
|
| 192 | + public function getLastLogin() { |
|
| 193 | + if ($this->lastLogin === null) { |
|
| 194 | + $this->fetchDetails(); |
|
| 195 | + } |
|
| 196 | + return (int)$this->lastLogin; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * getter for the detection timestamp |
|
| 201 | - * @return int |
|
| 202 | - */ |
|
| 203 | - public function getDetectedOn() { |
|
| 204 | - if ($this->foundDeleted === null) { |
|
| 205 | - $this->fetchDetails(); |
|
| 206 | - } |
|
| 207 | - return (int)$this->foundDeleted; |
|
| 208 | - } |
|
| 199 | + /** |
|
| 200 | + * getter for the detection timestamp |
|
| 201 | + * @return int |
|
| 202 | + */ |
|
| 203 | + public function getDetectedOn() { |
|
| 204 | + if ($this->foundDeleted === null) { |
|
| 205 | + $this->fetchDetails(); |
|
| 206 | + } |
|
| 207 | + return (int)$this->foundDeleted; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * getter for having active shares |
|
| 212 | - * @return bool |
|
| 213 | - */ |
|
| 214 | - public function getHasActiveShares() { |
|
| 215 | - if ($this->hasActiveShares === null) { |
|
| 216 | - $this->determineShares(); |
|
| 217 | - } |
|
| 218 | - return $this->hasActiveShares; |
|
| 219 | - } |
|
| 210 | + /** |
|
| 211 | + * getter for having active shares |
|
| 212 | + * @return bool |
|
| 213 | + */ |
|
| 214 | + public function getHasActiveShares() { |
|
| 215 | + if ($this->hasActiveShares === null) { |
|
| 216 | + $this->determineShares(); |
|
| 217 | + } |
|
| 218 | + return $this->hasActiveShares; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * reads the user details |
|
| 223 | - */ |
|
| 224 | - protected function fetchDetails() { |
|
| 225 | - $properties = [ |
|
| 226 | - 'displayName' => 'user_ldap', |
|
| 227 | - 'uid' => 'user_ldap', |
|
| 228 | - 'homePath' => 'user_ldap', |
|
| 229 | - 'foundDeleted' => 'user_ldap', |
|
| 230 | - 'email' => 'settings', |
|
| 231 | - 'lastLogin' => 'login', |
|
| 232 | - ]; |
|
| 233 | - foreach ($properties as $property => $app) { |
|
| 234 | - $this->$property = $this->config->getUserValue($this->ocName, $app, $property, ''); |
|
| 235 | - } |
|
| 236 | - } |
|
| 221 | + /** |
|
| 222 | + * reads the user details |
|
| 223 | + */ |
|
| 224 | + protected function fetchDetails() { |
|
| 225 | + $properties = [ |
|
| 226 | + 'displayName' => 'user_ldap', |
|
| 227 | + 'uid' => 'user_ldap', |
|
| 228 | + 'homePath' => 'user_ldap', |
|
| 229 | + 'foundDeleted' => 'user_ldap', |
|
| 230 | + 'email' => 'settings', |
|
| 231 | + 'lastLogin' => 'login', |
|
| 232 | + ]; |
|
| 233 | + foreach ($properties as $property => $app) { |
|
| 234 | + $this->$property = $this->config->getUserValue($this->ocName, $app, $property, ''); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * finds out whether the user has active shares. The result is stored in |
|
| 240 | - * $this->hasActiveShares |
|
| 241 | - */ |
|
| 242 | - protected function determineShares() { |
|
| 243 | - $shareInterface = new \ReflectionClass(IShare::class); |
|
| 244 | - $shareConstants = $shareInterface->getConstants(); |
|
| 238 | + /** |
|
| 239 | + * finds out whether the user has active shares. The result is stored in |
|
| 240 | + * $this->hasActiveShares |
|
| 241 | + */ |
|
| 242 | + protected function determineShares() { |
|
| 243 | + $shareInterface = new \ReflectionClass(IShare::class); |
|
| 244 | + $shareConstants = $shareInterface->getConstants(); |
|
| 245 | 245 | |
| 246 | - foreach ($shareConstants as $constantName => $constantValue) { |
|
| 247 | - if (strpos($constantName, 'TYPE_') !== 0 |
|
| 248 | - || $constantValue === IShare::TYPE_USERGROUP |
|
| 249 | - ) { |
|
| 250 | - continue; |
|
| 251 | - } |
|
| 252 | - $shares = $this->shareManager->getSharesBy( |
|
| 253 | - $this->ocName, |
|
| 254 | - $constantValue, |
|
| 255 | - null, |
|
| 256 | - false, |
|
| 257 | - 1 |
|
| 258 | - ); |
|
| 259 | - if (!empty($shares)) { |
|
| 260 | - $this->hasActiveShares = true; |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - } |
|
| 246 | + foreach ($shareConstants as $constantName => $constantValue) { |
|
| 247 | + if (strpos($constantName, 'TYPE_') !== 0 |
|
| 248 | + || $constantValue === IShare::TYPE_USERGROUP |
|
| 249 | + ) { |
|
| 250 | + continue; |
|
| 251 | + } |
|
| 252 | + $shares = $this->shareManager->getSharesBy( |
|
| 253 | + $this->ocName, |
|
| 254 | + $constantValue, |
|
| 255 | + null, |
|
| 256 | + false, |
|
| 257 | + 1 |
|
| 258 | + ); |
|
| 259 | + if (!empty($shares)) { |
|
| 260 | + $this->hasActiveShares = true; |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - $this->hasActiveShares = false; |
|
| 266 | - } |
|
| 265 | + $this->hasActiveShares = false; |
|
| 266 | + } |
|
| 267 | 267 | } |