Skip to content

Commit

Permalink
Change getAvatarFolder to accept user object
Browse files Browse the repository at this point in the history
This is to make sure we don't get into user id casing issues.
  • Loading branch information
Vincent Petry committed Oct 19, 2016
1 parent 5415cad commit 97669c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/private/AvatarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\IUserManager;
use OCP\Files\IRootFolder;
use OCP\IL10N;
use OCP\IUser;

/**
* This class implements methods to access Avatar functionality
Expand Down Expand Up @@ -86,7 +87,7 @@ public function getAvatar($userId) {

$userId = $user->getUID();

$avatarsFolder = $this->getAvatarFolder($userId);
$avatarsFolder = $this->getAvatarFolder($user);
return new Avatar($avatarsFolder, $this->l, $user, $this->logger);
}

Expand All @@ -106,14 +107,14 @@ private function buildAvatarPath($userId) {
/**
* Returns the avatar folder for the given user
*
* @param $userId user id
* @param IUser $user user
* @return Folder|\OCP\Files\Node
*
* @internal
*/
public function getAvatarFolder($userId) {
public function getAvatarFolder(IUser $user) {
$avatarsFolder = $this->getFolder($this->rootFolder, 'avatars');
$parts = $this->buildAvatarPath($userId);
$parts = $this->buildAvatarPath($user->getUID());
foreach ($parts as $part) {
$avatarsFolder = $this->getFolder($avatarsFolder, $part);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Repair/MoveAvatarOutsideHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function moveAvatars(IOutput $out, IUser $user) {
$oldAvatarUserFolder = $this->rootFolder->get('/' . $userId);
$oldAvatar = new Avatar($oldAvatarUserFolder, $this->l, $user, $this->logger);
if ($oldAvatar->exists()) {
$newAvatarsUserFolder = $this->avatarManager->getAvatarFolder($userId);
$newAvatarsUserFolder = $this->avatarManager->getAvatarFolder($user);

// get original file
$oldAvatarFile = $oldAvatar->getFile(-1);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/AvatarManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testGetAvatarValidUserDifferentCasing() {
$folder = $this->createMock(Folder::class);
$this->avatarManager->expects($this->once())
->method('getAvatarFolder')
->with('valid-user')
->with($user)
->willReturn($folder);

$avatar = $this->avatarManager->getAvatar('vaLid-USER');
Expand Down

0 comments on commit 97669c5

Please sign in to comment.