4242use OCA \User_LDAP \User \User ;
4343use OCP \IConfig ;
4444use OCP \IUser ;
45+ use OCP \IUserSession ;
4546use OCP \Notification \IManager as INotificationManager ;
4647use OCP \Util ;
4748
@@ -59,24 +60,21 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
5960 * @param Access $access
6061 * @param \OCP\IConfig $ocConfig
6162 * @param \OCP\Notification\IManager $notificationManager
63+ * @param IUserSession $userSession
6264 */
63- public function __construct (Access $ access , IConfig $ ocConfig , INotificationManager $ notificationManager ) {
65+ public function __construct (Access $ access , IConfig $ ocConfig , INotificationManager $ notificationManager, IUserSession $ userSession ) {
6466 parent ::__construct ($ access );
6567 $ this ->ocConfig = $ ocConfig ;
6668 $ this ->notificationManager = $ notificationManager ;
67- $ this ->registerHooks ();
69+ $ this ->registerHooks ($ userSession );
6870 }
6971
70- protected function registerHooks () {
71- Util:: connectHook ( ' OC_User ' , ' pre_deleteUser ' , $ this , 'preDeleteUser ' );
72- Util:: connectHook ( ' OC_User ' , ' post_deleteUser ' , $ this , 'postDeleteUser ' );
72+ protected function registerHooks (IUserSession $ userSession ) {
73+ $ userSession -> listen ( ' \OC\User ' , ' preDelete ' , [ $ this , 'preDeleteUser ' ] );
74+ $ userSession -> listen ( ' \OC\User ' , ' postDelete ' , [ $ this , 'postDeleteUser ' ] );
7375 }
7476
75- public function preDeleteUser (array $ param ) {
76- $ user = $ param [0 ];
77- if (!$ user instanceof IUser) {
78- throw new \RuntimeException ('IUser expected ' );
79- }
77+ public function preDeleteUser (IUser $ user ) {
8078 $ this ->currentUserInDeletionProcess = $ user ->getUID ();
8179 }
8280
@@ -376,8 +374,6 @@ public function deleteUser($uid) {
376374 \OC ::$ server ->getLogger ()->info ('Cleaning up after user ' . $ uid ,
377375 array ('app ' => 'user_ldap ' ));
378376
379- //Get Home Directory out of user preferences so we can return it later,
380- //necessary for removing directories as done by OC_User.
381377 $ this ->access ->getUserMapper ()->unmap ($ uid );
382378 $ this ->access ->userManager ->invalidate ($ uid );
383379 return true ;
@@ -406,7 +402,9 @@ public function getHome($uid) {
406402 // early return path if it is a deleted user
407403 $ user = $ this ->access ->userManager ->get ($ uid );
408404 if ($ user instanceof OfflineUser) {
409- if ($ this ->currentUserInDeletionProcess === $ user ->getUID ()) {
405+ if ($ this ->currentUserInDeletionProcess !== null
406+ && $ this ->currentUserInDeletionProcess === $ user ->getOCName ()
407+ ) {
410408 return $ user ->getHomePath ();
411409 } else {
412410 throw new NoUserException ($ uid . ' is not a valid user anymore ' );
0 commit comments