Do not copy skeleton on avatar access
Fixes #22119 Just try to get the folder of the user. If it is not there a NotFoundException will be thrown. Which will be handled by the avatar endpoint.
This commit is contained in:
parent
907430a808
commit
47d28155a8
|
@ -26,6 +26,7 @@
|
|||
|
||||
namespace OC;
|
||||
|
||||
use OCP\Files\Folder;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
@ -45,6 +46,13 @@ class AvatarManager implements IAvatarManager {
|
|||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/**
|
||||
* AvatarManager constructor.
|
||||
*
|
||||
* @param IUserManager $userManager
|
||||
* @param IRootFolder $rootFolder
|
||||
* @param IL10N $l
|
||||
*/
|
||||
public function __construct(
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder,
|
||||
|
@ -57,7 +65,7 @@ class AvatarManager implements IAvatarManager {
|
|||
/**
|
||||
* return a user specific instance of \OCP\IAvatar
|
||||
* @see \OCP\IAvatar
|
||||
* @param string $user the ownCloud user id
|
||||
* @param string $userId the ownCloud user id
|
||||
* @return \OCP\IAvatar
|
||||
* @throws \Exception In case the username is potentially dangerous
|
||||
*/
|
||||
|
@ -66,6 +74,16 @@ class AvatarManager implements IAvatarManager {
|
|||
if (is_null($user)) {
|
||||
throw new \Exception('user does not exist');
|
||||
}
|
||||
return new Avatar($this->rootFolder->getUserFolder($userId)->getParent(), $this->l, $user);
|
||||
|
||||
/*
|
||||
* Fix for #22119
|
||||
* Basically we do not want to copy the skeleton folder
|
||||
*/
|
||||
\OC\Files\Filesystem::initMountPoints($userId);
|
||||
$dir = '/' . $userId;
|
||||
/** @var Folder $folder */
|
||||
$folder = $this->rootFolder->get($dir);
|
||||
|
||||
return new Avatar($folder, $this->l, $user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,30 +19,32 @@
|
|||
*
|
||||
*/
|
||||
use OC\AvatarManager;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IUserManager;
|
||||
use Test\Traits\UserTrait;
|
||||
use Test\Traits\MountProviderTrait;
|
||||
|
||||
/**
|
||||
* Class AvatarManagerTest
|
||||
* @group DB
|
||||
*/
|
||||
class AvatarManagerTest extends \Test\TestCase {
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
use UserTrait;
|
||||
use MountProviderTrait;
|
||||
|
||||
/** @var AvatarManager */
|
||||
private $avatarManager;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var \OC\Files\Storage\Temporary */
|
||||
private $storage;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
|
||||
$this->userManager = $this->getMock('\OCP\IUserManager');
|
||||
$l = $this->getMock('\OCP\IL10N');
|
||||
$l->method('t')->will($this->returnArgument(0));
|
||||
$this->avatarManager = new \OC\AvatarManager(
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$l);;
|
||||
$this->createUser('valid-user', 'valid-user');
|
||||
|
||||
$this->storage = new \OC\Files\Storage\Temporary();
|
||||
$this->registerMount('valid-user', $this->storage, '/valid-user/');
|
||||
|
||||
$this->avatarManager = \OC::$server->getAvatarManager();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,23 +56,10 @@ class AvatarManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetAvatarValidUser() {
|
||||
$this->userManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('validUser')
|
||||
->willReturn(true);
|
||||
|
||||
$folder = $this->getMock('\OCP\Files\Folder');
|
||||
$this->rootFolder->expects($this->once())
|
||||
->method('getUserFolder')
|
||||
->with('validUser')
|
||||
->willReturn($folder);
|
||||
|
||||
$folder->expects($this->once())
|
||||
->method('getParent')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$this->avatarManager->getAvatar('validUser');
|
||||
$avatar = $this->avatarManager->getAvatar('valid-user');
|
||||
|
||||
$this->assertInstanceOf('\OCP\IAvatar', $avatar);
|
||||
$this->assertFalse($this->storage->file_exists('files'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue