@@ -42,407 +42,407 @@ |
||
| 42 | 42 | use \OCP\IUserBackend; |
| 43 | 43 | |
| 44 | 44 | class User implements IUser { |
| 45 | - /** @var string $uid */ |
|
| 46 | - private $uid; |
|
| 47 | - |
|
| 48 | - /** @var string $displayName */ |
|
| 49 | - private $displayName; |
|
| 50 | - |
|
| 51 | - /** @var UserInterface $backend */ |
|
| 52 | - private $backend; |
|
| 53 | - |
|
| 54 | - /** @var bool $enabled */ |
|
| 55 | - private $enabled; |
|
| 56 | - |
|
| 57 | - /** @var Emitter|Manager $emitter */ |
|
| 58 | - private $emitter; |
|
| 59 | - |
|
| 60 | - /** @var string $home */ |
|
| 61 | - private $home; |
|
| 62 | - |
|
| 63 | - /** @var int $lastLogin */ |
|
| 64 | - private $lastLogin; |
|
| 65 | - |
|
| 66 | - /** @var \OCP\IConfig $config */ |
|
| 67 | - private $config; |
|
| 68 | - |
|
| 69 | - /** @var IAvatarManager */ |
|
| 70 | - private $avatarManager; |
|
| 71 | - |
|
| 72 | - /** @var IURLGenerator */ |
|
| 73 | - private $urlGenerator; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $uid |
|
| 77 | - * @param UserInterface $backend |
|
| 78 | - * @param \OC\Hooks\Emitter $emitter |
|
| 79 | - * @param IConfig|null $config |
|
| 80 | - * @param IURLGenerator $urlGenerator |
|
| 81 | - */ |
|
| 82 | - public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
| 83 | - $this->uid = $uid; |
|
| 84 | - $this->backend = $backend; |
|
| 85 | - $this->emitter = $emitter; |
|
| 86 | - if(is_null($config)) { |
|
| 87 | - $config = \OC::$server->getConfig(); |
|
| 88 | - } |
|
| 89 | - $this->config = $config; |
|
| 90 | - $this->urlGenerator = $urlGenerator; |
|
| 91 | - $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
| 92 | - $this->enabled = ($enabled === 'true'); |
|
| 93 | - $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
| 94 | - if (is_null($this->urlGenerator)) { |
|
| 95 | - $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * get the user id |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public function getUID() { |
|
| 105 | - return $this->uid; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function getDisplayName() { |
|
| 114 | - if (!isset($this->displayName)) { |
|
| 115 | - $displayName = ''; |
|
| 116 | - if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
| 117 | - // get display name and strip whitespace from the beginning and end of it |
|
| 118 | - $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
| 119 | - if (is_string($backendDisplayName)) { |
|
| 120 | - $displayName = trim($backendDisplayName); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (!empty($displayName)) { |
|
| 125 | - $this->displayName = $displayName; |
|
| 126 | - } else { |
|
| 127 | - $this->displayName = $this->uid; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return $this->displayName; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * set the displayname for the user |
|
| 135 | - * |
|
| 136 | - * @param string $displayName |
|
| 137 | - * @return bool |
|
| 138 | - */ |
|
| 139 | - public function setDisplayName($displayName) { |
|
| 140 | - $displayName = trim($displayName); |
|
| 141 | - if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
| 142 | - $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
| 143 | - if ($result) { |
|
| 144 | - $this->displayName = $displayName; |
|
| 145 | - $this->triggerChange('displayName', $displayName); |
|
| 146 | - } |
|
| 147 | - return $result !== false; |
|
| 148 | - } else { |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * set the email address of the user |
|
| 155 | - * |
|
| 156 | - * @param string|null $mailAddress |
|
| 157 | - * @return void |
|
| 158 | - * @since 9.0.0 |
|
| 159 | - */ |
|
| 160 | - public function setEMailAddress($mailAddress) { |
|
| 161 | - $oldMailAddress = $this->getEMailAddress(); |
|
| 162 | - if($mailAddress === '') { |
|
| 163 | - $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
| 164 | - } else { |
|
| 165 | - $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
| 166 | - } |
|
| 167 | - $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
| 172 | - * login |
|
| 173 | - * |
|
| 174 | - * @return int |
|
| 175 | - */ |
|
| 176 | - public function getLastLogin() { |
|
| 177 | - return $this->lastLogin; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * updates the timestamp of the most recent login of this user |
|
| 182 | - */ |
|
| 183 | - public function updateLastLoginTimestamp() { |
|
| 184 | - $firstTimeLogin = ($this->lastLogin === 0); |
|
| 185 | - $this->lastLogin = time(); |
|
| 186 | - $this->config->setUserValue( |
|
| 187 | - $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 188 | - |
|
| 189 | - return $firstTimeLogin; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Delete the user |
|
| 194 | - * |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function delete() { |
|
| 198 | - if ($this->emitter) { |
|
| 199 | - $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 200 | - } |
|
| 201 | - // get the home now because it won't return it after user deletion |
|
| 202 | - $homePath = $this->getHome(); |
|
| 203 | - $result = $this->backend->deleteUser($this->uid); |
|
| 204 | - if ($result) { |
|
| 205 | - |
|
| 206 | - // FIXME: Feels like an hack - suggestions? |
|
| 207 | - |
|
| 208 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 209 | - // We have to delete the user from all groups |
|
| 210 | - foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 211 | - $group = $groupManager->get($groupId); |
|
| 212 | - if ($group) { |
|
| 213 | - \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 214 | - $group->removeUser($this); |
|
| 215 | - \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - // Delete the user's keys in preferences |
|
| 219 | - \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 220 | - |
|
| 221 | - // Delete user files in /data/ |
|
| 222 | - if ($homePath !== false) { |
|
| 223 | - // FIXME: this operates directly on FS, should use View instead... |
|
| 224 | - // also this is not testable/mockable... |
|
| 225 | - \OC_Helper::rmdirr($homePath); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Delete the users entry in the storage table |
|
| 229 | - Storage::remove('home::' . $this->uid); |
|
| 230 | - |
|
| 231 | - \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 232 | - \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 233 | - |
|
| 234 | - $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 235 | - $notification->setUser($this->uid); |
|
| 236 | - \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 237 | - |
|
| 238 | - if ($this->emitter) { |
|
| 239 | - $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - return !($result === false); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Set the password of the user |
|
| 247 | - * |
|
| 248 | - * @param string $password |
|
| 249 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 250 | - * @return bool |
|
| 251 | - */ |
|
| 252 | - public function setPassword($password, $recoveryPassword = null) { |
|
| 253 | - if ($this->emitter) { |
|
| 254 | - $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 255 | - } |
|
| 256 | - if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 257 | - $result = $this->backend->setPassword($this->uid, $password); |
|
| 258 | - if ($this->emitter) { |
|
| 259 | - $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 260 | - } |
|
| 261 | - return !($result === false); |
|
| 262 | - } else { |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * get the users home folder to mount |
|
| 269 | - * |
|
| 270 | - * @return string |
|
| 271 | - */ |
|
| 272 | - public function getHome() { |
|
| 273 | - if (!$this->home) { |
|
| 274 | - if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 275 | - $this->home = $home; |
|
| 276 | - } elseif ($this->config) { |
|
| 277 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 278 | - } else { |
|
| 279 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - return $this->home; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Get the name of the backend class the user is connected with |
|
| 287 | - * |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public function getBackendClassName() { |
|
| 291 | - if($this->backend instanceof IUserBackend) { |
|
| 292 | - return $this->backend->getBackendName(); |
|
| 293 | - } |
|
| 294 | - return get_class($this->backend); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * check if the backend allows the user to change his avatar on Personal page |
|
| 299 | - * |
|
| 300 | - * @return bool |
|
| 301 | - */ |
|
| 302 | - public function canChangeAvatar() { |
|
| 303 | - if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 304 | - return $this->backend->canChangeAvatar($this->uid); |
|
| 305 | - } |
|
| 306 | - return true; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * check if the backend supports changing passwords |
|
| 311 | - * |
|
| 312 | - * @return bool |
|
| 313 | - */ |
|
| 314 | - public function canChangePassword() { |
|
| 315 | - return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * check if the backend supports changing display names |
|
| 320 | - * |
|
| 321 | - * @return bool |
|
| 322 | - */ |
|
| 323 | - public function canChangeDisplayName() { |
|
| 324 | - if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 327 | - return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * check if the user is enabled |
|
| 332 | - * |
|
| 333 | - * @return bool |
|
| 334 | - */ |
|
| 335 | - public function isEnabled() { |
|
| 336 | - return $this->enabled; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * set the enabled status for the user |
|
| 341 | - * |
|
| 342 | - * @param bool $enabled |
|
| 343 | - */ |
|
| 344 | - public function setEnabled($enabled) { |
|
| 345 | - $oldStatus = $this->isEnabled(); |
|
| 346 | - $this->enabled = $enabled; |
|
| 347 | - $enabled = ($enabled) ? 'true' : 'false'; |
|
| 348 | - if ($oldStatus !== $this->enabled) { |
|
| 349 | - $this->triggerChange('enabled', $enabled); |
|
| 350 | - $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * get the users email address |
|
| 356 | - * |
|
| 357 | - * @return string|null |
|
| 358 | - * @since 9.0.0 |
|
| 359 | - */ |
|
| 360 | - public function getEMailAddress() { |
|
| 361 | - return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get the users' quota |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - * @since 9.0.0 |
|
| 369 | - */ |
|
| 370 | - public function getQuota() { |
|
| 371 | - $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 372 | - if($quota === 'default') { |
|
| 373 | - $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 374 | - } |
|
| 375 | - return $quota; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * set the users' quota |
|
| 380 | - * |
|
| 381 | - * @param string $quota |
|
| 382 | - * @return void |
|
| 383 | - * @since 9.0.0 |
|
| 384 | - */ |
|
| 385 | - public function setQuota($quota) { |
|
| 386 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 387 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 388 | - $quota = OC_Helper::humanFileSize($quota); |
|
| 389 | - } |
|
| 390 | - $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 391 | - $this->triggerChange('quota', $quota); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * get the avatar image if it exists |
|
| 396 | - * |
|
| 397 | - * @param int $size |
|
| 398 | - * @return IImage|null |
|
| 399 | - * @since 9.0.0 |
|
| 400 | - */ |
|
| 401 | - public function getAvatarImage($size) { |
|
| 402 | - // delay the initialization |
|
| 403 | - if (is_null($this->avatarManager)) { |
|
| 404 | - $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 408 | - $image = $avatar->get(-1); |
|
| 409 | - if ($image) { |
|
| 410 | - return $image; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - return null; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * get the federation cloud id |
|
| 418 | - * |
|
| 419 | - * @return string |
|
| 420 | - * @since 9.0.0 |
|
| 421 | - */ |
|
| 422 | - public function getCloudId() { |
|
| 423 | - $uid = $this->getUID(); |
|
| 424 | - $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 425 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 426 | - return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * @param string $url |
|
| 431 | - * @return string |
|
| 432 | - */ |
|
| 433 | - private function removeProtocolFromUrl($url) { |
|
| 434 | - if (strpos($url, 'https://') === 0) { |
|
| 435 | - return substr($url, strlen('https://')); |
|
| 436 | - } else if (strpos($url, 'http://') === 0) { |
|
| 437 | - return substr($url, strlen('http://')); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - return $url; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 444 | - if ($this->emitter) { |
|
| 445 | - $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 446 | - } |
|
| 447 | - } |
|
| 45 | + /** @var string $uid */ |
|
| 46 | + private $uid; |
|
| 47 | + |
|
| 48 | + /** @var string $displayName */ |
|
| 49 | + private $displayName; |
|
| 50 | + |
|
| 51 | + /** @var UserInterface $backend */ |
|
| 52 | + private $backend; |
|
| 53 | + |
|
| 54 | + /** @var bool $enabled */ |
|
| 55 | + private $enabled; |
|
| 56 | + |
|
| 57 | + /** @var Emitter|Manager $emitter */ |
|
| 58 | + private $emitter; |
|
| 59 | + |
|
| 60 | + /** @var string $home */ |
|
| 61 | + private $home; |
|
| 62 | + |
|
| 63 | + /** @var int $lastLogin */ |
|
| 64 | + private $lastLogin; |
|
| 65 | + |
|
| 66 | + /** @var \OCP\IConfig $config */ |
|
| 67 | + private $config; |
|
| 68 | + |
|
| 69 | + /** @var IAvatarManager */ |
|
| 70 | + private $avatarManager; |
|
| 71 | + |
|
| 72 | + /** @var IURLGenerator */ |
|
| 73 | + private $urlGenerator; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $uid |
|
| 77 | + * @param UserInterface $backend |
|
| 78 | + * @param \OC\Hooks\Emitter $emitter |
|
| 79 | + * @param IConfig|null $config |
|
| 80 | + * @param IURLGenerator $urlGenerator |
|
| 81 | + */ |
|
| 82 | + public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
| 83 | + $this->uid = $uid; |
|
| 84 | + $this->backend = $backend; |
|
| 85 | + $this->emitter = $emitter; |
|
| 86 | + if(is_null($config)) { |
|
| 87 | + $config = \OC::$server->getConfig(); |
|
| 88 | + } |
|
| 89 | + $this->config = $config; |
|
| 90 | + $this->urlGenerator = $urlGenerator; |
|
| 91 | + $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
| 92 | + $this->enabled = ($enabled === 'true'); |
|
| 93 | + $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
| 94 | + if (is_null($this->urlGenerator)) { |
|
| 95 | + $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * get the user id |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public function getUID() { |
|
| 105 | + return $this->uid; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function getDisplayName() { |
|
| 114 | + if (!isset($this->displayName)) { |
|
| 115 | + $displayName = ''; |
|
| 116 | + if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
| 117 | + // get display name and strip whitespace from the beginning and end of it |
|
| 118 | + $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
| 119 | + if (is_string($backendDisplayName)) { |
|
| 120 | + $displayName = trim($backendDisplayName); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (!empty($displayName)) { |
|
| 125 | + $this->displayName = $displayName; |
|
| 126 | + } else { |
|
| 127 | + $this->displayName = $this->uid; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return $this->displayName; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * set the displayname for the user |
|
| 135 | + * |
|
| 136 | + * @param string $displayName |
|
| 137 | + * @return bool |
|
| 138 | + */ |
|
| 139 | + public function setDisplayName($displayName) { |
|
| 140 | + $displayName = trim($displayName); |
|
| 141 | + if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
| 142 | + $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
| 143 | + if ($result) { |
|
| 144 | + $this->displayName = $displayName; |
|
| 145 | + $this->triggerChange('displayName', $displayName); |
|
| 146 | + } |
|
| 147 | + return $result !== false; |
|
| 148 | + } else { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * set the email address of the user |
|
| 155 | + * |
|
| 156 | + * @param string|null $mailAddress |
|
| 157 | + * @return void |
|
| 158 | + * @since 9.0.0 |
|
| 159 | + */ |
|
| 160 | + public function setEMailAddress($mailAddress) { |
|
| 161 | + $oldMailAddress = $this->getEMailAddress(); |
|
| 162 | + if($mailAddress === '') { |
|
| 163 | + $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
| 164 | + } else { |
|
| 165 | + $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
| 166 | + } |
|
| 167 | + $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
| 172 | + * login |
|
| 173 | + * |
|
| 174 | + * @return int |
|
| 175 | + */ |
|
| 176 | + public function getLastLogin() { |
|
| 177 | + return $this->lastLogin; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * updates the timestamp of the most recent login of this user |
|
| 182 | + */ |
|
| 183 | + public function updateLastLoginTimestamp() { |
|
| 184 | + $firstTimeLogin = ($this->lastLogin === 0); |
|
| 185 | + $this->lastLogin = time(); |
|
| 186 | + $this->config->setUserValue( |
|
| 187 | + $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 188 | + |
|
| 189 | + return $firstTimeLogin; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Delete the user |
|
| 194 | + * |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function delete() { |
|
| 198 | + if ($this->emitter) { |
|
| 199 | + $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 200 | + } |
|
| 201 | + // get the home now because it won't return it after user deletion |
|
| 202 | + $homePath = $this->getHome(); |
|
| 203 | + $result = $this->backend->deleteUser($this->uid); |
|
| 204 | + if ($result) { |
|
| 205 | + |
|
| 206 | + // FIXME: Feels like an hack - suggestions? |
|
| 207 | + |
|
| 208 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 209 | + // We have to delete the user from all groups |
|
| 210 | + foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 211 | + $group = $groupManager->get($groupId); |
|
| 212 | + if ($group) { |
|
| 213 | + \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 214 | + $group->removeUser($this); |
|
| 215 | + \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + // Delete the user's keys in preferences |
|
| 219 | + \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 220 | + |
|
| 221 | + // Delete user files in /data/ |
|
| 222 | + if ($homePath !== false) { |
|
| 223 | + // FIXME: this operates directly on FS, should use View instead... |
|
| 224 | + // also this is not testable/mockable... |
|
| 225 | + \OC_Helper::rmdirr($homePath); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Delete the users entry in the storage table |
|
| 229 | + Storage::remove('home::' . $this->uid); |
|
| 230 | + |
|
| 231 | + \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 232 | + \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 233 | + |
|
| 234 | + $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 235 | + $notification->setUser($this->uid); |
|
| 236 | + \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 237 | + |
|
| 238 | + if ($this->emitter) { |
|
| 239 | + $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + return !($result === false); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Set the password of the user |
|
| 247 | + * |
|
| 248 | + * @param string $password |
|
| 249 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 250 | + * @return bool |
|
| 251 | + */ |
|
| 252 | + public function setPassword($password, $recoveryPassword = null) { |
|
| 253 | + if ($this->emitter) { |
|
| 254 | + $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 255 | + } |
|
| 256 | + if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 257 | + $result = $this->backend->setPassword($this->uid, $password); |
|
| 258 | + if ($this->emitter) { |
|
| 259 | + $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 260 | + } |
|
| 261 | + return !($result === false); |
|
| 262 | + } else { |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * get the users home folder to mount |
|
| 269 | + * |
|
| 270 | + * @return string |
|
| 271 | + */ |
|
| 272 | + public function getHome() { |
|
| 273 | + if (!$this->home) { |
|
| 274 | + if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 275 | + $this->home = $home; |
|
| 276 | + } elseif ($this->config) { |
|
| 277 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 278 | + } else { |
|
| 279 | + $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + return $this->home; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Get the name of the backend class the user is connected with |
|
| 287 | + * |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public function getBackendClassName() { |
|
| 291 | + if($this->backend instanceof IUserBackend) { |
|
| 292 | + return $this->backend->getBackendName(); |
|
| 293 | + } |
|
| 294 | + return get_class($this->backend); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * check if the backend allows the user to change his avatar on Personal page |
|
| 299 | + * |
|
| 300 | + * @return bool |
|
| 301 | + */ |
|
| 302 | + public function canChangeAvatar() { |
|
| 303 | + if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 304 | + return $this->backend->canChangeAvatar($this->uid); |
|
| 305 | + } |
|
| 306 | + return true; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * check if the backend supports changing passwords |
|
| 311 | + * |
|
| 312 | + * @return bool |
|
| 313 | + */ |
|
| 314 | + public function canChangePassword() { |
|
| 315 | + return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * check if the backend supports changing display names |
|
| 320 | + * |
|
| 321 | + * @return bool |
|
| 322 | + */ |
|
| 323 | + public function canChangeDisplayName() { |
|
| 324 | + if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | + return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * check if the user is enabled |
|
| 332 | + * |
|
| 333 | + * @return bool |
|
| 334 | + */ |
|
| 335 | + public function isEnabled() { |
|
| 336 | + return $this->enabled; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * set the enabled status for the user |
|
| 341 | + * |
|
| 342 | + * @param bool $enabled |
|
| 343 | + */ |
|
| 344 | + public function setEnabled($enabled) { |
|
| 345 | + $oldStatus = $this->isEnabled(); |
|
| 346 | + $this->enabled = $enabled; |
|
| 347 | + $enabled = ($enabled) ? 'true' : 'false'; |
|
| 348 | + if ($oldStatus !== $this->enabled) { |
|
| 349 | + $this->triggerChange('enabled', $enabled); |
|
| 350 | + $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * get the users email address |
|
| 356 | + * |
|
| 357 | + * @return string|null |
|
| 358 | + * @since 9.0.0 |
|
| 359 | + */ |
|
| 360 | + public function getEMailAddress() { |
|
| 361 | + return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get the users' quota |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + * @since 9.0.0 |
|
| 369 | + */ |
|
| 370 | + public function getQuota() { |
|
| 371 | + $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 372 | + if($quota === 'default') { |
|
| 373 | + $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 374 | + } |
|
| 375 | + return $quota; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * set the users' quota |
|
| 380 | + * |
|
| 381 | + * @param string $quota |
|
| 382 | + * @return void |
|
| 383 | + * @since 9.0.0 |
|
| 384 | + */ |
|
| 385 | + public function setQuota($quota) { |
|
| 386 | + if($quota !== 'none' and $quota !== 'default') { |
|
| 387 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 388 | + $quota = OC_Helper::humanFileSize($quota); |
|
| 389 | + } |
|
| 390 | + $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 391 | + $this->triggerChange('quota', $quota); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * get the avatar image if it exists |
|
| 396 | + * |
|
| 397 | + * @param int $size |
|
| 398 | + * @return IImage|null |
|
| 399 | + * @since 9.0.0 |
|
| 400 | + */ |
|
| 401 | + public function getAvatarImage($size) { |
|
| 402 | + // delay the initialization |
|
| 403 | + if (is_null($this->avatarManager)) { |
|
| 404 | + $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 408 | + $image = $avatar->get(-1); |
|
| 409 | + if ($image) { |
|
| 410 | + return $image; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + return null; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * get the federation cloud id |
|
| 418 | + * |
|
| 419 | + * @return string |
|
| 420 | + * @since 9.0.0 |
|
| 421 | + */ |
|
| 422 | + public function getCloudId() { |
|
| 423 | + $uid = $this->getUID(); |
|
| 424 | + $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 425 | + $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 426 | + return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * @param string $url |
|
| 431 | + * @return string |
|
| 432 | + */ |
|
| 433 | + private function removeProtocolFromUrl($url) { |
|
| 434 | + if (strpos($url, 'https://') === 0) { |
|
| 435 | + return substr($url, strlen('https://')); |
|
| 436 | + } else if (strpos($url, 'http://') === 0) { |
|
| 437 | + return substr($url, strlen('http://')); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + return $url; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 444 | + if ($this->emitter) { |
|
| 445 | + $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | 448 | } |
@@ -44,166 +44,166 @@ |
||
| 44 | 44 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 45 | 45 | |
| 46 | 46 | class AuditLogger { |
| 47 | - /** @var ILogger */ |
|
| 48 | - private $logger; |
|
| 49 | - /** @var IUserSession */ |
|
| 50 | - private $userSession; |
|
| 51 | - /** @var IGroupManager */ |
|
| 52 | - private $groupManager; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * AuditLogger constructor. |
|
| 56 | - * |
|
| 57 | - * @param ILogger $logger |
|
| 58 | - * @param IUserSession $userSession |
|
| 59 | - * @param IGroupManager $groupManager |
|
| 60 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 61 | - */ |
|
| 62 | - public function __construct(ILogger $logger, |
|
| 63 | - IUserSession $userSession, |
|
| 64 | - IGroupManager $groupManager, |
|
| 65 | - EventDispatcherInterface $eventDispatcher) { |
|
| 66 | - $this->logger = $logger; |
|
| 67 | - $this->userSession = $userSession; |
|
| 68 | - $this->groupManager = $groupManager; |
|
| 69 | - $this->eventDispatcher = $eventDispatcher; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Register hooks in order to log them |
|
| 74 | - */ |
|
| 75 | - public function registerHooks() { |
|
| 76 | - $this->userManagementHooks(); |
|
| 77 | - $this->groupHooks(); |
|
| 78 | - $this->sharingHooks(); |
|
| 79 | - $this->authHooks(); |
|
| 80 | - $this->fileHooks(); |
|
| 81 | - $this->trashbinHooks(); |
|
| 82 | - $this->versionsHooks(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Connect to user management hooks |
|
| 87 | - */ |
|
| 88 | - private function userManagementHooks() { |
|
| 89 | - $userActions = new UserManagement($this->logger); |
|
| 90 | - |
|
| 91 | - Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 92 | - Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 93 | - Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 94 | - $this->userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
| 95 | - } |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + private $logger; |
|
| 49 | + /** @var IUserSession */ |
|
| 50 | + private $userSession; |
|
| 51 | + /** @var IGroupManager */ |
|
| 52 | + private $groupManager; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * AuditLogger constructor. |
|
| 56 | + * |
|
| 57 | + * @param ILogger $logger |
|
| 58 | + * @param IUserSession $userSession |
|
| 59 | + * @param IGroupManager $groupManager |
|
| 60 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 61 | + */ |
|
| 62 | + public function __construct(ILogger $logger, |
|
| 63 | + IUserSession $userSession, |
|
| 64 | + IGroupManager $groupManager, |
|
| 65 | + EventDispatcherInterface $eventDispatcher) { |
|
| 66 | + $this->logger = $logger; |
|
| 67 | + $this->userSession = $userSession; |
|
| 68 | + $this->groupManager = $groupManager; |
|
| 69 | + $this->eventDispatcher = $eventDispatcher; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Register hooks in order to log them |
|
| 74 | + */ |
|
| 75 | + public function registerHooks() { |
|
| 76 | + $this->userManagementHooks(); |
|
| 77 | + $this->groupHooks(); |
|
| 78 | + $this->sharingHooks(); |
|
| 79 | + $this->authHooks(); |
|
| 80 | + $this->fileHooks(); |
|
| 81 | + $this->trashbinHooks(); |
|
| 82 | + $this->versionsHooks(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Connect to user management hooks |
|
| 87 | + */ |
|
| 88 | + private function userManagementHooks() { |
|
| 89 | + $userActions = new UserManagement($this->logger); |
|
| 90 | + |
|
| 91 | + Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 92 | + Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 93 | + Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 94 | + $this->userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - private function groupHooks() { |
|
| 98 | - $groupActions = new GroupManagement($this->logger); |
|
| 99 | - $this->groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 100 | - $this->groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 101 | - $this->groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 102 | - $this->groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * connect to sharing events |
|
| 107 | - */ |
|
| 108 | - private function sharingHooks() { |
|
| 109 | - $shareActions = new Sharing($this->logger); |
|
| 110 | - |
|
| 111 | - Util::connectHook('OCP\Share', 'post_shared', $shareActions, 'shared'); |
|
| 112 | - Util::connectHook('OCP\Share', 'post_unshare', $shareActions, 'unshare'); |
|
| 113 | - Util::connectHook('OCP\Share', 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 114 | - Util::connectHook('OCP\Share', 'post_update_password', $shareActions, 'updatePassword'); |
|
| 115 | - Util::connectHook('OCP\Share', 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 116 | - Util::connectHook('OCP\Share', 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * connect to authentication event and related actions |
|
| 121 | - */ |
|
| 122 | - private function authHooks() { |
|
| 123 | - $authActions = new Auth($this->logger); |
|
| 124 | - |
|
| 125 | - Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
| 126 | - Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
| 127 | - Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Connect to file hooks |
|
| 132 | - */ |
|
| 133 | - private function fileHooks() { |
|
| 134 | - $fileActions = new Files($this->logger); |
|
| 135 | - $this->eventDispatcher->addListener( |
|
| 136 | - IPreview::EVENT, |
|
| 137 | - function(GenericEvent $event) use ($fileActions) { |
|
| 138 | - /** @var File $file */ |
|
| 139 | - $file = $event->getSubject(); |
|
| 140 | - $fileActions->preview([ |
|
| 141 | - 'path' => substr($file->getInternalPath(), 5), |
|
| 142 | - 'width' => $event->getArguments()['width'], |
|
| 143 | - 'height' => $event->getArguments()['height'], |
|
| 144 | - 'crop' => $event->getArguments()['crop'], |
|
| 145 | - 'mode' => $event->getArguments()['mode'] |
|
| 146 | - ]); |
|
| 147 | - } |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - Util::connectHook( |
|
| 151 | - Filesystem::CLASSNAME, |
|
| 152 | - Filesystem::signal_post_rename, |
|
| 153 | - $fileActions, |
|
| 154 | - 'rename' |
|
| 155 | - ); |
|
| 156 | - Util::connectHook( |
|
| 157 | - Filesystem::CLASSNAME, |
|
| 158 | - Filesystem::signal_post_create, |
|
| 159 | - $fileActions, |
|
| 160 | - 'create' |
|
| 161 | - ); |
|
| 162 | - Util::connectHook( |
|
| 163 | - Filesystem::CLASSNAME, |
|
| 164 | - Filesystem::signal_post_copy, |
|
| 165 | - $fileActions, |
|
| 166 | - 'copy' |
|
| 167 | - ); |
|
| 168 | - Util::connectHook( |
|
| 169 | - Filesystem::CLASSNAME, |
|
| 170 | - Filesystem::signal_post_write, |
|
| 171 | - $fileActions, |
|
| 172 | - 'write' |
|
| 173 | - ); |
|
| 174 | - Util::connectHook( |
|
| 175 | - Filesystem::CLASSNAME, |
|
| 176 | - Filesystem::signal_post_update, |
|
| 177 | - $fileActions, |
|
| 178 | - 'update' |
|
| 179 | - ); |
|
| 180 | - Util::connectHook( |
|
| 181 | - Filesystem::CLASSNAME, |
|
| 182 | - Filesystem::signal_read, |
|
| 183 | - $fileActions, |
|
| 184 | - 'read' |
|
| 185 | - ); |
|
| 186 | - Util::connectHook( |
|
| 187 | - Filesystem::CLASSNAME, |
|
| 188 | - Filesystem::signal_delete, |
|
| 189 | - $fileActions, |
|
| 190 | - 'delete' |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - public function versionsHooks() { |
|
| 195 | - $versionsActions = new Versions($this->logger); |
|
| 196 | - Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
| 197 | - Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Connect to trash bin hooks |
|
| 202 | - */ |
|
| 203 | - private function trashbinHooks() { |
|
| 204 | - $trashActions = new Trashbin($this->logger); |
|
| 205 | - Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 206 | - Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 207 | - } |
|
| 97 | + private function groupHooks() { |
|
| 98 | + $groupActions = new GroupManagement($this->logger); |
|
| 99 | + $this->groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 100 | + $this->groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 101 | + $this->groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 102 | + $this->groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * connect to sharing events |
|
| 107 | + */ |
|
| 108 | + private function sharingHooks() { |
|
| 109 | + $shareActions = new Sharing($this->logger); |
|
| 110 | + |
|
| 111 | + Util::connectHook('OCP\Share', 'post_shared', $shareActions, 'shared'); |
|
| 112 | + Util::connectHook('OCP\Share', 'post_unshare', $shareActions, 'unshare'); |
|
| 113 | + Util::connectHook('OCP\Share', 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 114 | + Util::connectHook('OCP\Share', 'post_update_password', $shareActions, 'updatePassword'); |
|
| 115 | + Util::connectHook('OCP\Share', 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 116 | + Util::connectHook('OCP\Share', 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * connect to authentication event and related actions |
|
| 121 | + */ |
|
| 122 | + private function authHooks() { |
|
| 123 | + $authActions = new Auth($this->logger); |
|
| 124 | + |
|
| 125 | + Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
| 126 | + Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
| 127 | + Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Connect to file hooks |
|
| 132 | + */ |
|
| 133 | + private function fileHooks() { |
|
| 134 | + $fileActions = new Files($this->logger); |
|
| 135 | + $this->eventDispatcher->addListener( |
|
| 136 | + IPreview::EVENT, |
|
| 137 | + function(GenericEvent $event) use ($fileActions) { |
|
| 138 | + /** @var File $file */ |
|
| 139 | + $file = $event->getSubject(); |
|
| 140 | + $fileActions->preview([ |
|
| 141 | + 'path' => substr($file->getInternalPath(), 5), |
|
| 142 | + 'width' => $event->getArguments()['width'], |
|
| 143 | + 'height' => $event->getArguments()['height'], |
|
| 144 | + 'crop' => $event->getArguments()['crop'], |
|
| 145 | + 'mode' => $event->getArguments()['mode'] |
|
| 146 | + ]); |
|
| 147 | + } |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + Util::connectHook( |
|
| 151 | + Filesystem::CLASSNAME, |
|
| 152 | + Filesystem::signal_post_rename, |
|
| 153 | + $fileActions, |
|
| 154 | + 'rename' |
|
| 155 | + ); |
|
| 156 | + Util::connectHook( |
|
| 157 | + Filesystem::CLASSNAME, |
|
| 158 | + Filesystem::signal_post_create, |
|
| 159 | + $fileActions, |
|
| 160 | + 'create' |
|
| 161 | + ); |
|
| 162 | + Util::connectHook( |
|
| 163 | + Filesystem::CLASSNAME, |
|
| 164 | + Filesystem::signal_post_copy, |
|
| 165 | + $fileActions, |
|
| 166 | + 'copy' |
|
| 167 | + ); |
|
| 168 | + Util::connectHook( |
|
| 169 | + Filesystem::CLASSNAME, |
|
| 170 | + Filesystem::signal_post_write, |
|
| 171 | + $fileActions, |
|
| 172 | + 'write' |
|
| 173 | + ); |
|
| 174 | + Util::connectHook( |
|
| 175 | + Filesystem::CLASSNAME, |
|
| 176 | + Filesystem::signal_post_update, |
|
| 177 | + $fileActions, |
|
| 178 | + 'update' |
|
| 179 | + ); |
|
| 180 | + Util::connectHook( |
|
| 181 | + Filesystem::CLASSNAME, |
|
| 182 | + Filesystem::signal_read, |
|
| 183 | + $fileActions, |
|
| 184 | + 'read' |
|
| 185 | + ); |
|
| 186 | + Util::connectHook( |
|
| 187 | + Filesystem::CLASSNAME, |
|
| 188 | + Filesystem::signal_delete, |
|
| 189 | + $fileActions, |
|
| 190 | + 'delete' |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + public function versionsHooks() { |
|
| 195 | + $versionsActions = new Versions($this->logger); |
|
| 196 | + Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
| 197 | + Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Connect to trash bin hooks |
|
| 202 | + */ |
|
| 203 | + private function trashbinHooks() { |
|
| 204 | + $trashActions = new Trashbin($this->logger); |
|
| 205 | + Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 206 | + Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | } |
@@ -88,18 +88,18 @@ discard block |
||
| 88 | 88 | private function userManagementHooks() { |
| 89 | 89 | $userActions = new UserManagement($this->logger); |
| 90 | 90 | |
| 91 | - Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 92 | - Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 93 | - Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 91 | + Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 92 | + Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 93 | + Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 94 | 94 | $this->userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - private function groupHooks() { |
|
| 97 | + private function groupHooks() { |
|
| 98 | 98 | $groupActions = new GroupManagement($this->logger); |
| 99 | - $this->groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 100 | - $this->groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 101 | - $this->groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 102 | - $this->groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 99 | + $this->groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 100 | + $this->groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 101 | + $this->groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 102 | + $this->groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | public function versionsHooks() { |
| 195 | 195 | $versionsActions = new Versions($this->logger); |
| 196 | 196 | Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
| 197 | - Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete'); |
|
| 197 | + Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -30,69 +30,69 @@ |
||
| 30 | 30 | * @package OCA\Admin_Audit\Actions |
| 31 | 31 | */ |
| 32 | 32 | class UserManagement extends Action { |
| 33 | - /** |
|
| 34 | - * Log creation of users |
|
| 35 | - * |
|
| 36 | - * @param array $params |
|
| 37 | - */ |
|
| 38 | - public function create(array $params) { |
|
| 39 | - $this->log( |
|
| 40 | - 'User created: "%s"', |
|
| 41 | - $params, |
|
| 42 | - [ |
|
| 43 | - 'uid', |
|
| 44 | - ] |
|
| 45 | - ); |
|
| 46 | - } |
|
| 33 | + /** |
|
| 34 | + * Log creation of users |
|
| 35 | + * |
|
| 36 | + * @param array $params |
|
| 37 | + */ |
|
| 38 | + public function create(array $params) { |
|
| 39 | + $this->log( |
|
| 40 | + 'User created: "%s"', |
|
| 41 | + $params, |
|
| 42 | + [ |
|
| 43 | + 'uid', |
|
| 44 | + ] |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Log deletion of users |
|
| 50 | - * |
|
| 51 | - * @param array $params |
|
| 52 | - */ |
|
| 53 | - public function delete(array $params) { |
|
| 54 | - $this->log( |
|
| 55 | - 'User deleted: "%s"', |
|
| 56 | - $params, |
|
| 57 | - [ |
|
| 58 | - 'uid', |
|
| 59 | - ] |
|
| 60 | - ); |
|
| 61 | - } |
|
| 48 | + /** |
|
| 49 | + * Log deletion of users |
|
| 50 | + * |
|
| 51 | + * @param array $params |
|
| 52 | + */ |
|
| 53 | + public function delete(array $params) { |
|
| 54 | + $this->log( |
|
| 55 | + 'User deleted: "%s"', |
|
| 56 | + $params, |
|
| 57 | + [ |
|
| 58 | + 'uid', |
|
| 59 | + ] |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Log enabling of users |
|
| 65 | - * |
|
| 66 | - * @param array $params |
|
| 67 | - */ |
|
| 68 | - public function change(array $params) { |
|
| 69 | - if ($params['feature'] === 'enabled') { |
|
| 70 | - $this->log( |
|
| 71 | - $params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"', |
|
| 72 | - ['user' => $params['user']->getUID()], |
|
| 73 | - [ |
|
| 74 | - 'user', |
|
| 75 | - ] |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - } |
|
| 63 | + /** |
|
| 64 | + * Log enabling of users |
|
| 65 | + * |
|
| 66 | + * @param array $params |
|
| 67 | + */ |
|
| 68 | + public function change(array $params) { |
|
| 69 | + if ($params['feature'] === 'enabled') { |
|
| 70 | + $this->log( |
|
| 71 | + $params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"', |
|
| 72 | + ['user' => $params['user']->getUID()], |
|
| 73 | + [ |
|
| 74 | + 'user', |
|
| 75 | + ] |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Logs changing of the user scope |
|
| 82 | - * |
|
| 83 | - * @param IUser $user |
|
| 84 | - */ |
|
| 85 | - public function setPassword(IUser $user) { |
|
| 86 | - if($user->getBackendClassName() === 'Database') { |
|
| 87 | - $this->log( |
|
| 88 | - 'Password of user "%s" has been changed', |
|
| 89 | - [ |
|
| 90 | - 'user' => $user->getUID(), |
|
| 91 | - ], |
|
| 92 | - [ |
|
| 93 | - 'user', |
|
| 94 | - ] |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 80 | + /** |
|
| 81 | + * Logs changing of the user scope |
|
| 82 | + * |
|
| 83 | + * @param IUser $user |
|
| 84 | + */ |
|
| 85 | + public function setPassword(IUser $user) { |
|
| 86 | + if($user->getBackendClassName() === 'Database') { |
|
| 87 | + $this->log( |
|
| 88 | + 'Password of user "%s" has been changed', |
|
| 89 | + [ |
|
| 90 | + 'user' => $user->getUID(), |
|
| 91 | + ], |
|
| 92 | + [ |
|
| 93 | + 'user', |
|
| 94 | + ] |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | } |