4141use OCA \User_LDAP \User \OfflineUser ;
4242use OCA \User_LDAP \User \User ;
4343use OCP \IConfig ;
44+ use OCP \IUser ;
4445use OCP \Notification \IManager as INotificationManager ;
4546use OCP \Util ;
4647
4748class User_LDAP extends BackendUtility implements \OCP \IUserBackend, \OCP \UserInterface, IUserLDAP {
48- /** @var string[] $homesToKill */
49- protected $ homesToKill = array ();
50-
5149 /** @var \OCP\IConfig */
5250 protected $ ocConfig ;
5351
5452 /** @var INotificationManager */
5553 protected $ notificationManager ;
5654
55+ /** @var string */
56+ protected $ currentUserInDeletionProcess ;
57+
5758 /**
5859 * @param Access $access
5960 * @param \OCP\IConfig $ocConfig
@@ -63,6 +64,24 @@ public function __construct(Access $access, IConfig $ocConfig, INotificationMana
6364 parent ::__construct ($ access );
6465 $ this ->ocConfig = $ ocConfig ;
6566 $ this ->notificationManager = $ notificationManager ;
67+ $ this ->registerHooks ();
68+ }
69+
70+ protected function registerHooks () {
71+ Util::connectHook ('OC_User ' ,'pre_deleteUser ' , $ this , 'preDeleteUser ' );
72+ Util::connectHook ('OC_User ' ,'post_deleteUser ' , $ this , 'postDeleteUser ' );
73+ }
74+
75+ public function preDeleteUser (array $ param ) {
76+ $ user = $ param [0 ];
77+ if (!$ user instanceof IUser) {
78+ throw new \RuntimeException ('IUser expected ' );
79+ }
80+ $ this ->currentUserInDeletionProcess = $ user ->getUID ();
81+ }
82+
83+ public function postDeleteUser () {
84+ $ this ->currentUserInDeletionProcess = null ;
6685 }
6786
6887 /**
@@ -359,10 +378,8 @@ public function deleteUser($uid) {
359378
360379 //Get Home Directory out of user preferences so we can return it later,
361380 //necessary for removing directories as done by OC_User.
362- $ home = $ this ->ocConfig ->getUserValue ($ uid , 'user_ldap ' , 'homePath ' , '' );
363- $ this ->homesToKill [$ uid ] = $ home ;
364381 $ this ->access ->getUserMapper ()->unmap ($ uid );
365-
382+ $ this -> access -> userManager -> invalidate ( $ uid );
366383 return true ;
367384 }
368385
@@ -375,11 +392,6 @@ public function deleteUser($uid) {
375392 * @throws \Exception
376393 */
377394 public function getHome ($ uid ) {
378- if (isset ($ this ->homesToKill [$ uid ]) && !empty ($ this ->homesToKill [$ uid ])) {
379- //a deleted user who needs some clean up
380- return $ this ->homesToKill [$ uid ];
381- }
382-
383395 // user Exists check required as it is not done in user proxy!
384396 if (!$ this ->userExists ($ uid )) {
385397 return false ;
@@ -391,16 +403,18 @@ public function getHome($uid) {
391403 return $ path ;
392404 }
393405
406+ // early return path if it is a deleted user
394407 $ user = $ this ->access ->userManager ->get ($ uid );
395- if (is_null ($ user ) || ($ user instanceof OfflineUser && !$ this ->userExistsOnLDAP ($ user ->getOCName ()))) {
396- throw new NoUserException ($ uid . ' is not a valid user anymore ' );
397- }
398408 if ($ user instanceof OfflineUser) {
399- // apparently this user survived the userExistsOnLDAP check,
400- // we request the user instance again in order to retrieve a User
401- // instance instead
402- $ user = $ this ->access ->userManager ->get ($ uid );
409+ if ($ this ->currentUserInDeletionProcess === $ user ->getUID ()) {
410+ return $ user ->getHomePath ();
411+ } else {
412+ throw new NoUserException ($ uid . ' is not a valid user anymore ' );
413+ }
414+ } else if ($ user === null ) {
415+ throw new NoUserException ($ uid . ' is not a valid user anymore ' );
403416 }
417+
404418 $ path = $ user ->getHomePath ();
405419 $ this ->access ->cacheUserHome ($ uid , $ path );
406420
0 commit comments