diff --git a/lib/ContactsStoreUserProvider.php b/lib/ContactsStoreUserProvider.php index feac35fb..194823da 100644 --- a/lib/ContactsStoreUserProvider.php +++ b/lib/ContactsStoreUserProvider.php @@ -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); diff --git a/lib/User.php b/lib/User.php index 9c4a4f2d..1b81badb 100644 --- a/lib/User.php +++ b/lib/User.php @@ -2,6 +2,7 @@ namespace OCA\OJSXC; +use OCA\OJSXC\AppInfo\Application; use OCP\IUser; class User @@ -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; } @@ -48,7 +49,7 @@ public function getUid() */ public function setUid($uid) { - $this->uid = $uid; + $this->uid = Application::santizeUserId($uid); } /** diff --git a/lib/UserManagerUserProvider.php b/lib/UserManagerUserProvider.php index 0b85a229..ac9571ae 100644 --- a/lib/UserManagerUserProvider.php +++ b/lib/UserManagerUserProvider.php @@ -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; diff --git a/lib/stanzahandlers/iq.php b/lib/stanzahandlers/iq.php index db157ab7..c185d85f 100644 --- a/lib/stanzahandlers/iq.php +++ b/lib/stanzahandlers/iq.php @@ -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) { @@ -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()); } } diff --git a/tests/unit/stanzahandlers/IQTest.php b/tests/unit/stanzahandlers/IQTest.php index 69271200..9ec33c7f 100644 --- a/tests/unit/stanzahandlers/IQTest.php +++ b/tests/unit/stanzahandlers/IQTest.php @@ -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') @@ -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'); @@ -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()); - } }