Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LEDfan committed Oct 20, 2017
1 parent 8ef696d commit 3ff54e2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 89 deletions.
1 change: 1 addition & 0 deletions lib/ContactsStoreUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function getAllUsers()
if (is_null(self::$cache)) {
$result = [];
$contacts = $this->contactsStore->getContacts($this->userSession->getUser(), '');
// TODO check if contact is disabled
foreach ($contacts as $contact) {
if ($contact->getProperty('isLocalSystemBook')) {
$result[] = new User($contact->getProperty('UID'), $contact->getFullName(), $contact);
Expand Down
5 changes: 3 additions & 2 deletions lib/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OCA\OJSXC;

use OCA\OJSXC\AppInfo\Application;
use OCP\IUser;

class User
Expand Down Expand Up @@ -30,7 +31,7 @@ class User
*/
public function __construct($uid, $fullName, $origin)
{
$this->uid = $uid;
$this->uid = Application::santizeUserId($uid);
$this->fullName = $fullName;
$this->origin = $origin;
}
Expand All @@ -48,7 +49,7 @@ public function getUid()
*/
public function setUid($uid)
{
$this->uid = $uid;
$this->uid = Application::santizeUserId($uid);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/UserManagerUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function getAllUsers()
if (is_null(self::$cache)) {
$result = [];
foreach ($this->userManager->search('') as $user) {
$result[] = new User($user->getUID(), $user->getDisplayName(), $user);
if ($user->isEnabled()) {
$result[] = new User($user->getUID(), $user->getDisplayName(), $user);
}
}

self::$cache = $result;
Expand Down
5 changes: 1 addition & 4 deletions lib/stanzahandlers/iq.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class IQ extends StanzaHandler
* @param IUserManager $userManager
* @param IConfig $config
* @param IUserProvider $userProvider
* @param NewContentContainer $newContentContainer
*/
public function __construct($userId, $host, IUserManager $userManager, IConfig $config, IUserProvider $userProvider)
{
Expand Down Expand Up @@ -78,10 +77,8 @@ public function handle(array $stanza)
$iqRoster->setType('result');
$iqRoster->setTo($this->userId);
$iqRoster->setQid($id);
//$userId = Application::santizeUserId($user->getUID()); TODO
// if ($debugMode || ($userId !== $this->userId && $user->isEnabled())) { // TODO
foreach ($this->userProvider->getAllUsers() as $user) {
if ($debugMode || (strtolower($user->getUID()) !== $this->userId)) {
if ($debugMode || $user->getUID() !== $this->userId) {
$iqRoster->addItem($user->getUID() . '@' . $this->host, $user->getFullName());
}
}
Expand Down
82 changes: 0 additions & 82 deletions tests/unit/stanzahandlers/IQTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public function iqRosterProvider()
->method('getFullName')
->will($this->returnValue('John'));

// $user1->expects($this->any())
// ->method('isEnabled')
// ->will($this->returnValue(true));
// TOOD

$user2 = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock();
$user2->expects($this->any())
->method('getUID')
Expand All @@ -79,11 +74,6 @@ public function iqRosterProvider()
->method('getFullName')
->will($this->returnValue('Richard'));

$user2->expects($this->any())
->method('isEnabled')
->will($this->returnValue(true));


$expected1 = new IQRoster();
$expected1->setType('result');
$expected1->setTo('john');
Expand Down Expand Up @@ -196,76 +186,4 @@ public function testIqRoster(array $stanza, array $users, $searchCount, $expecte
}
}

public function testIqRosterWithDisabledUsers()
{
$user1 = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock();
$user1->expects($this->any())
->method('getUID')
->will($this->returnValue('jan'));

$user1->expects($this->any())
->method('getDisplayName')
->will($this->returnValue('Jan'));

$user1->expects($this->any())
->method('isEnabled')
->will($this->returnValue(true));

$user2 = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock();
$user2->expects($this->any())
->method('getUID')
->will($this->returnValue('richard'));

$user2->expects($this->any())
->method('getDisplayName')
->will($this->returnValue('Richard'));

$user2->expects($this->any())
->method('isEnabled')
->will($this->returnValue(false));

$expected = new IQRoster();
$expected->setType('result');
$expected->setTo('john');
$expected->setQid('f9a26583-3c59-4f09-89be-964ce265fbfd:sendIQ');
$expected->addItem('jan@localhost', 'Jan');

$this->config->expects($this->once())
->method('getSystemValue')
->with('debug')
->will($this->returnValue(false));

$this->userManager->expects($this->once())
->method('search')
->with('')
->will($this->returnValue([$user1, $user2]));

$result = $this->iq->handle(
[
'name' => '{jabber:client}iq',
'value' =>
[
0 =>
[
'name' => '{jabber:iq:roster}query',
'value' => null,
'attributes' => []
]
],
'attributes' =>
[
'type' => 'get',
'id' => 'f9a26583-3c59-4f09-89be-964ce265fbfd:sendIQ',
],
]
);

$this->assertEquals($expected->getFrom(), $result->getFrom());
$this->assertEquals($expected->getId(), $result->getId());
$this->assertEquals($expected->getItems(), $result->getItems());
$this->assertEquals($expected->getQid(), $result->getQid());
$this->assertEquals($expected->getTo(), $result->getTo());
$this->assertEquals($expected->getType(), $result->getType());
$this->assertEquals($expected->getStanza(), $result->getStanza());
}
}

0 comments on commit 3ff54e2

Please sign in to comment.