Merge pull request #19052 from owncloud/revert-14856-remote_avatars

Revert "Allow Remote avatars"
This commit is contained in:
Thomas Müller 2015-09-16 00:10:00 +02:00
commit ac1239220d
2 changed files with 13 additions and 22 deletions

View File

@ -90,18 +90,14 @@ class AvatarController extends Controller {
} }
/** /**
* @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* @PublicPage
* *
* @param string $userId * @param string $userId
* @param int $size * @param int $size
* @return DataResponse|DataDisplayResponse * @return DataResponse|DataDisplayResponse
*/ */
public function getAvatar($userId, $size) { public function getAvatar($userId, $size) {
if (!$this->userManager->userExists($userId)) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($size > 2048) { if ($size > 2048) {
$size = 2048; $size = 2048;
} elseif ($size <= 0) { } elseif ($size <= 0) {

View File

@ -96,12 +96,8 @@ class AvatarControllerTest extends \Test\TestCase {
// Configure userMock // Configure userMock
$this->userMock->method('getDisplayName')->willReturn($this->user); $this->userMock->method('getDisplayName')->willReturn($this->user);
$this->userMock->method('getUID')->willReturn($this->user); $this->userMock->method('getUID')->willReturn($this->user);
$this->container['UserManager'] $this->container['UserManager']->method('get')
->method('get')
->willReturnMap([[$this->user, $this->userMock]]); ->willReturnMap([[$this->user, $this->userMock]]);
$this->container['UserManager']
->method('userExists')
->willReturnMap([[$this->user, true]]);
$this->container['UserSession']->method('getUser')->willReturn($this->userMock); $this->container['UserSession']->method('getUser')->willReturn($this->userMock);
} }
@ -124,10 +120,11 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch an avatar if a user has no avatar * Fetch an avatar if a user has no avatar
*/ */
public function testGetAvatarNoAvatar() { public function testGetAvatarNoAvatar() {
$this->container['UserManager']->expects($this->once())->method('userExists'); $this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
$this->container['AvatarManager']->expects($this->once())->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->getAvatar($this->user, 32); $response = $this->avatarController->getAvatar($this->user, 32);
//Comment out until JS is fixed
//$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertEquals(Http::STATUS_OK, $response->getStatus()); $this->assertEquals(Http::STATUS_OK, $response->getStatus());
$this->assertEquals($this->user, $response->getData()['data']['displayname']); $this->assertEquals($this->user, $response->getData()['data']['displayname']);
} }
@ -136,11 +133,9 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch the user's avatar * Fetch the user's avatar
*/ */
public function testGetAvatar() { public function testGetAvatar() {
$this->container['UserManager']->expects($this->once())->method('userExists');
$image = new Image(OC::$SERVERROOT.'/tests/data/testimage.jpg'); $image = new Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
$this->avatarMock->expects($this->once())->method('get')->willReturn($image); $this->avatarMock->method('get')->willReturn($image);
$this->container['AvatarManager']->expects($this->once())->method('getAvatar')->willReturn($this->avatarMock); $this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->getAvatar($this->user, 32); $response = $this->avatarController->getAvatar($this->user, 32);
@ -155,19 +150,21 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch the avatar of a non-existing user * Fetch the avatar of a non-existing user
*/ */
public function testGetAvatarNoUser() { public function testGetAvatarNoUser() {
$this->container['UserManager']->expects($this->once())->method('userExists'); $this->avatarMock->method('get')->willReturn(null);
$this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->getAvatar($this->user . 'doesnotexist', 32); $response = $this->avatarController->getAvatar($this->user . 'doesnotexist', 32);
//Comment out until JS is fixed //Comment out until JS is fixed
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); //$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertEquals([], $response->getData()); $this->assertEquals(Http::STATUS_OK, $response->getStatus());
$this->assertEquals('', $response->getData()['data']['displayname']);
} }
/** /**
* Make sure we get the correct size * Make sure we get the correct size
*/ */
public function testGetAvatarSize() { public function testGetAvatarSize() {
$this->container['UserManager']->expects($this->once())->method('userExists');
$this->avatarMock->expects($this->once()) $this->avatarMock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo(32)); ->with($this->equalTo(32));
@ -181,7 +178,6 @@ class AvatarControllerTest extends \Test\TestCase {
* We cannot get avatars that are 0 or negative * We cannot get avatars that are 0 or negative
*/ */
public function testGetAvatarSizeMin() { public function testGetAvatarSizeMin() {
$this->container['UserManager']->expects($this->once())->method('userExists');
$this->avatarMock->expects($this->once()) $this->avatarMock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo(64)); ->with($this->equalTo(64));
@ -195,7 +191,6 @@ class AvatarControllerTest extends \Test\TestCase {
* We do not support avatars larger than 2048*2048 * We do not support avatars larger than 2048*2048
*/ */
public function testGetAvatarSizeMax() { public function testGetAvatarSizeMax() {
$this->container['UserManager']->expects($this->once())->method('userExists');
$this->avatarMock->expects($this->once()) $this->avatarMock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo(2048)); ->with($this->equalTo(2048));