Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
90dfa981
Commit
90dfa981
authored
9 years ago
by
Morris Jobke
Browse files
Options
Downloads
Plain Diff
Merge pull request #14856 from rullzer/remote_avatars
Allow Remote avatars
parents
723f8c8f
ae62537a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/avatar/avatarcontroller.php
+5
-1
5 additions, 1 deletion
core/avatar/avatarcontroller.php
tests/core/avatar/avatarcontrollertest.php
+17
-12
17 additions, 12 deletions
tests/core/avatar/avatarcontrollertest.php
with
22 additions
and
13 deletions
core/avatar/avatarcontroller.php
+
5
−
1
View file @
90dfa981
...
...
@@ -90,14 +90,18 @@ class AvatarController extends Controller {
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*
* @param string $userId
* @param int $size
* @return DataResponse|DataDisplayResponse
*/
public
function
getAvatar
(
$userId
,
$size
)
{
if
(
!
$this
->
userManager
->
userExists
(
$userId
))
{
return
new
DataResponse
([],
Http
::
STATUS_NOT_FOUND
);
}
if
(
$size
>
2048
)
{
$size
=
2048
;
}
elseif
(
$size
<=
0
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/core/avatar/avatarcontrollertest.php
+
17
−
12
View file @
90dfa981
...
...
@@ -96,8 +96,12 @@ class AvatarControllerTest extends \Test\TestCase {
// Configure userMock
$this
->
userMock
->
method
(
'getDisplayName'
)
->
willReturn
(
$this
->
user
);
$this
->
userMock
->
method
(
'getUID'
)
->
willReturn
(
$this
->
user
);
$this
->
container
[
'UserManager'
]
->
method
(
'get'
)
$this
->
container
[
'UserManager'
]
->
method
(
'get'
)
->
willReturnMap
([[
$this
->
user
,
$this
->
userMock
]]);
$this
->
container
[
'UserManager'
]
->
method
(
'userExists'
)
->
willReturnMap
([[
$this
->
user
,
true
]]);
$this
->
container
[
'UserSession'
]
->
method
(
'getUser'
)
->
willReturn
(
$this
->
userMock
);
}
...
...
@@ -120,11 +124,10 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch an avatar if a user has no avatar
*/
public
function
testGetAvatarNoAvatar
()
{
$this
->
container
[
'AvatarManager'
]
->
method
(
'getAvatar'
)
->
willReturn
(
$this
->
avatarMock
);
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'userExists'
);
$this
->
container
[
'AvatarManager'
]
->
expects
(
$this
->
once
())
->
method
(
'getAvatar'
)
->
willReturn
(
$this
->
avatarMock
);
$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
(
$this
->
user
,
$response
->
getData
()[
'data'
][
'displayname'
]);
}
...
...
@@ -133,9 +136,11 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch the user's avatar
*/
public
function
testGetAvatar
()
{
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'userExists'
);
$image
=
new
Image
(
OC
::
$SERVERROOT
.
'/tests/data/testimage.jpg'
);
$this
->
avatarMock
->
method
(
'get'
)
->
willReturn
(
$image
);
$this
->
container
[
'AvatarManager'
]
->
method
(
'getAvatar'
)
->
willReturn
(
$this
->
avatarMock
);
$this
->
avatarMock
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
willReturn
(
$image
);
$this
->
container
[
'AvatarManager'
]
->
expects
(
$this
->
once
())
->
method
(
'getAvatar'
)
->
willReturn
(
$this
->
avatarMock
);
$response
=
$this
->
avatarController
->
getAvatar
(
$this
->
user
,
32
);
...
...
@@ -150,21 +155,19 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch the avatar of a non-existing user
*/
public
function
testGetAvatarNoUser
()
{
$this
->
avatarMock
->
method
(
'get'
)
->
willReturn
(
null
);
$this
->
container
[
'AvatarManager'
]
->
method
(
'getAvatar'
)
->
willReturn
(
$this
->
avatarMock
);
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'userExists'
);
$response
=
$this
->
avatarController
->
getAvatar
(
$this
->
user
.
'doesnotexist'
,
32
);
//Comment out until JS is fixed
//$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this
->
assertEquals
(
Http
::
STATUS_OK
,
$response
->
getStatus
());
$this
->
assertEquals
(
''
,
$response
->
getData
()[
'data'
][
'displayname'
]);
$this
->
assertEquals
(
Http
::
STATUS_NOT_FOUND
,
$response
->
getStatus
());
$this
->
assertEquals
([],
$response
->
getData
());
}
/**
* Make sure we get the correct size
*/
public
function
testGetAvatarSize
()
{
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'userExists'
);
$this
->
avatarMock
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
$this
->
equalTo
(
32
));
...
...
@@ -178,6 +181,7 @@ class AvatarControllerTest extends \Test\TestCase {
* We cannot get avatars that are 0 or negative
*/
public
function
testGetAvatarSizeMin
()
{
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'userExists'
);
$this
->
avatarMock
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
$this
->
equalTo
(
64
));
...
...
@@ -191,6 +195,7 @@ class AvatarControllerTest extends \Test\TestCase {
* We do not support avatars larger than 2048*2048
*/
public
function
testGetAvatarSizeMax
()
{
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'userExists'
);
$this
->
avatarMock
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
$this
->
equalTo
(
2048
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment