relax strict getHome behaviour for LDAP users in a shadow state

* simplifies deletion process
* less strange behaviour when looking up home storage (as long as it is local)
* thus could enable transfer ownerships after user went invisible on ldap

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2019-10-28 15:11:41 +01:00 committed by Christoph Wurst
parent 69ae7abe72
commit 411a47cadb
No known key found for this signature in database
GPG key ID: CC42AC2A7F0E56D8
2 changed files with 8 additions and 45 deletions

View file

@ -47,7 +47,6 @@ use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use OCP\Util;
@ -59,9 +58,6 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
/** @var INotificationManager */
protected $notificationManager;
/** @var string */
protected $currentUserInDeletionProcess;
/** @var UserPluginManager */
protected $userPluginManager;
@ -76,20 +72,6 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
$this->ocConfig = $ocConfig;
$this->notificationManager = $notificationManager;
$this->userPluginManager = $userPluginManager;
$this->registerHooks($userSession);
}
protected function registerHooks(IUserSession $userSession) {
$userSession->listen('\OC\User', 'preDelete', [$this, 'preDeleteUser']);
$userSession->listen('\OC\User', 'postDelete', [$this, 'postDeleteUser']);
}
public function preDeleteUser(IUser $user) {
$this->currentUserInDeletionProcess = $user->getUID();
}
public function postDeleteUser() {
$this->currentUserInDeletionProcess = null;
}
/**
@ -430,21 +412,13 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
// early return path if it is a deleted user
$user = $this->access->userManager->get($uid);
if($user instanceof OfflineUser) {
if($this->currentUserInDeletionProcess !== null
&& $this->currentUserInDeletionProcess === $user->getOCName()
) {
return $user->getHomePath();
} else {
throw new NoUserException($uid . ' is not a valid user anymore');
}
} else if ($user === null) {
if($user instanceof User || $user instanceof OfflineUser) {
$path = $user->getHomePath() ?: false;
} else {
throw new NoUserException($uid . ' is not a valid user anymore');
}
$path = $user->getHomePath();
$this->access->cacheUserHome($uid, $path);
return $path;
}

View file

@ -314,22 +314,12 @@ class User_LDAPTest extends TestCase {
$offlineUser->expects($this->once())
->method('getHomePath')
->willReturn($home);
$offlineUser->expects($this->once())
->method('getOCName')
->willReturn($uid);
$this->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($offlineUser);
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
/** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->once())
->method('getUID')
->willReturn($uid);
$backend->preDeleteUser($user);
$result = $backend->deleteUser($uid);
$this->assertTrue($result);
/** @noinspection PhpUnhandledExceptionInspection */
@ -836,10 +826,7 @@ class User_LDAPTest extends TestCase {
$this->assertFalse($result);
}
public function testGetHomeDeletedUser() {
$this->expectException(\OC\User\NoUserException::class);
$uid = 'newyorker';
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
@ -869,14 +856,16 @@ class User_LDAPTest extends TestCase {
->will($this->returnValue(true));
$offlineUser = $this->createMock(OfflineUser::class);
$offlineUser->expects($this->never())
->method('getHomePath');
$offlineUser->expects($this->atLeastOnce())
->method('getHomePath')
->willReturn('');
$this->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($offlineUser);
$backend->getHome($uid);
$result = $backend->getHome($uid);
$this->assertFalse($result);
}
public function testGetHomeWithPlugin() {