Skip to content

Commit

Permalink
Merge pull request #20954 from owncloud/settings_user_only_load_avata…
Browse files Browse the repository at this point in the history
…r_if_available

Settings user only load avatar if available
  • Loading branch information
DeepDiver1975 committed Dec 7, 2015
2 parents c1fb9fa + 8c9a3cc commit 085f3f5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
3 changes: 2 additions & 1 deletion settings/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public function __construct(array $urlParams=[]){
$c->query('Mailer'),
$c->query('DefaultMailAddress'),
$c->query('URLGenerator'),
$c->query('OCP\\App\\IAppManager')
$c->query('OCP\\App\\IAppManager'),
$c->query('OCP\\IAvatarManager')
);
});
$container->registerService('LogSettingsController', function(IContainer $c) {
Expand Down
14 changes: 13 additions & 1 deletion settings/controller/userscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\IAvatarManager;

/**
* @package OC\Settings\Controller
Expand Down Expand Up @@ -74,6 +75,8 @@ class UsersController extends Controller {
private $isEncryptionAppEnabled;
/** @var bool contains the state of the admin recovery setting */
private $isRestoreEnabled = false;
/** @var IAvatarManager */
private $avatarManager;

/**
* @param string $appName
Expand Down Expand Up @@ -104,7 +107,8 @@ public function __construct($appName,
IMailer $mailer,
$fromMailAddress,
IURLGenerator $urlGenerator,
IAppManager $appManager) {
IAppManager $appManager,
IAvatarManager $avatarManager) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
Expand All @@ -117,6 +121,7 @@ public function __construct($appName,
$this->mailer = $mailer;
$this->fromMailAddress = $fromMailAddress;
$this->urlGenerator = $urlGenerator;
$this->avatarManager = $avatarManager;

// check for encryption state - TODO see formatUserForIndex
$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
Expand Down Expand Up @@ -168,6 +173,12 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
if (is_null($displayName)) {
$displayName = '';
}

$avatarAvailable = false;
if ($this->config->getSystemValue('enable_avatars', true) === true) {
$avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists();
}

return [
'name' => $user->getUID(),
'displayname' => $user->getDisplayName(),
Expand All @@ -179,6 +190,7 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
'backend' => $user->getBackendClassName(),
'email' => $displayName,
'isRestoreDisabled' => !$restorePossible,
'isAvatarAvailable' => $avatarAvailable,
];
}

Expand Down
8 changes: 6 additions & 2 deletions settings/js/users/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ var UserList = {
/**
* Avatar or placeholder
*/
if ($tr.find('div.avatardiv').length){
$('div.avatardiv', $tr).avatar(user.name, 32, undefined, undefined, undefined, user.displayname);
if ($tr.find('div.avatardiv').length) {
if (user.isAvatarAvailable === true) {
$('div.avatardiv', $tr).avatar(user.name, 32, undefined, undefined, undefined, user.displayname);
} else {
$('div.avatardiv', $tr).imageplaceholder(user.displayname);
}
}

/**
Expand Down
60 changes: 49 additions & 11 deletions tests/settings/controller/userscontrollertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ protected function setUp() {
->disableOriginalConstructor()->getMock();
$this->container['OCP\\App\\IAppManager'] = $this->getMockBuilder('OCP\\App\\IAppManager')
->disableOriginalConstructor()->getMock();


/*
* Set default avtar behaviour for whole testsuite
*/
$this->container['OCP\\IAvatarManager'] = $this->getMock('OCP\IAvatarManager');

$avatarExists = $this->getMock('OCP\IAvatar');
$avatarExists->method('exists')->willReturn(true);
$avatarNotExists = $this->getMock('OCP\IAvatar');
$avatarNotExists->method('exists')->willReturn(false);
$this->container['OCP\\IAvatarManager']
->method('getAvatar')
->will($this->returnValueMap([
['foo', $avatarExists],
['bar', $avatarExists],
['admin', $avatarNotExists],
]));

$this->container['Config']
->method('getSystemValue')
->with('enable_avatars', true)
->willReturn(true);

}

public function testIndexAdmin() {
Expand All @@ -62,7 +86,7 @@ public function testIndexAdmin() {
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('foo'));
$foo
Expand All @@ -86,7 +110,7 @@ public function testIndexAdmin() {
$admin = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$admin
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('admin'));
$admin
Expand All @@ -112,7 +136,7 @@ public function testIndexAdmin() {
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('bar'));
$bar
Expand Down Expand Up @@ -188,7 +212,6 @@ public function testIndexAdmin() {
->method('getSubAdmin')
->will($this->returnValue($subadmin));


$expectedResponse = new DataResponse(
array(
0 => array(
Expand All @@ -202,6 +225,7 @@ public function testIndexAdmin() {
'backend' => 'OC_User_Database',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
1 => array(
'name' => 'admin',
Expand All @@ -214,6 +238,7 @@ public function testIndexAdmin() {
'backend' => '\Test\Util\User\Dummy',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => false,
),
2 => array(
'name' => 'bar',
Expand All @@ -226,6 +251,7 @@ public function testIndexAdmin() {
'backend' => '\Test\Util\User\Dummy',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
)
);
Expand All @@ -246,7 +272,7 @@ public function testIndexSubAdmin() {
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('foo'));
$foo
Expand All @@ -270,7 +296,7 @@ public function testIndexSubAdmin() {
$admin = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$admin
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('admin'));
$admin
Expand All @@ -296,7 +322,7 @@ public function testIndexSubAdmin() {
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('bar'));
$bar
Expand Down Expand Up @@ -401,6 +427,7 @@ public function testIndexSubAdmin() {
'backend' => '\Test\Util\User\Dummy',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
],
1=> [
'name' => 'foo',
Expand All @@ -413,6 +440,7 @@ public function testIndexSubAdmin() {
'backend' => 'OC_User_Database',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
],
2 => [
'name' => 'admin',
Expand All @@ -425,6 +453,7 @@ public function testIndexSubAdmin() {
'backend' => '\Test\Util\User\Dummy',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => false,
],
]
);
Expand All @@ -443,7 +472,7 @@ public function testIndexWithSearch() {
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('foo'));
$foo
Expand All @@ -467,7 +496,7 @@ public function testIndexWithSearch() {
$admin = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$admin
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('admin'));
$admin
Expand All @@ -493,7 +522,7 @@ public function testIndexWithSearch() {
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('bar'));
$bar
Expand Down Expand Up @@ -553,6 +582,7 @@ public function testIndexWithSearch() {
'backend' => 'OC_User_Database',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
1 => array(
'name' => 'admin',
Expand All @@ -565,6 +595,7 @@ public function testIndexWithSearch() {
'backend' => '\Test\Util\User\Dummy',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => false,
),
2 => array(
'name' => 'bar',
Expand All @@ -577,6 +608,7 @@ public function testIndexWithSearch() {
'backend' => '\Test\Util\User\Dummy',
'email' => '[email protected]',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
)
);
Expand All @@ -590,7 +622,7 @@ public function testIndexWithBackend() {
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('getUID')
->will($this->returnValue('foo'));
$user
Expand Down Expand Up @@ -648,6 +680,7 @@ public function testIndexWithBackend() {
'backend' => 'OC_User_Database',
'email' => null,
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
)
)
);
Expand Down Expand Up @@ -719,6 +752,7 @@ public function testCreateSuccessfulWithoutGroupAdmin() {
'subadmin' => array(),
'email' => null,
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -807,6 +841,7 @@ public function testCreateSuccessfulWithoutGroupSubAdmin() {
'subadmin' => [],
'email' => null,
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -889,6 +924,7 @@ public function testCreateSuccessfulWithGroupAdmin() {
'subadmin' => array(),
'email' => null,
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -984,6 +1020,7 @@ public function testCreateSuccessfulWithGroupSubAdmin() {
'subadmin' => [],
'email' => null,
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -1480,6 +1517,7 @@ private function mockUser($userId = 'foo', $displayName = 'M. Foo',
'backend' => $backend,
'email' => null,
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
];

return [$user, $result];
Expand Down

0 comments on commit 085f3f5

Please sign in to comment.