Merge pull request #7932 from nextcloud/7914-stable13

[stable13] format self-mentions, but don't offer them
This commit is contained in:
Daniel Calviño Sánchez 2018-01-18 14:20:26 +01:00 committed by GitHub
commit a0499e0258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 6 deletions

View File

@ -40,6 +40,15 @@ class Search implements ISearch {
$this->c = $c;
}
/**
* @param string $search
* @param array $shareTypes
* @param bool $lookup
* @param int|null $limit
* @param int|null $offset
* @return array
* @throws \OCP\AppFramework\QueryException
*/
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
$hasMoreResults = false;

View File

@ -83,6 +83,8 @@ class UserPlugin implements ISearchPlugin {
}
}
$this->takeOutCurrentUser($users);
if (!$this->shareeEnumeration || sizeof($users) < $limit) {
$hasMoreResults = true;
}
@ -146,4 +148,13 @@ class UserPlugin implements ISearchPlugin {
return $hasMoreResults;
}
public function takeOutCurrentUser(array &$users) {
$currentUser = $this->userSession->getUser();
if(!is_null($currentUser)) {
if (isset($users[$currentUser->getUID()])) {
unset($users[$currentUser->getUID()]);
}
}
}
}

View File

@ -232,10 +232,6 @@ class Comment implements IComment {
$uids = array_unique($mentions[0]);
$result = [];
foreach ($uids as $uid) {
// exclude author, no self-mentioning
if($uid === '@' . $this->getActorId()) {
continue;
}
$result[] = ['type' => 'user', 'id' => substr($uid, 1)];
}
return $result;

View File

@ -442,4 +442,51 @@ class UserPluginTest extends TestCase {
$this->assertEquals($expected, $result['users']);
$this->assertSame($reachedEnd, $moreResults);
}
public function takeOutCurrentUserProvider() {
$inputUsers = [
'alice' => 'Alice',
'bob' => 'Bob',
'carol' => 'Carol'
];
return [
[
$inputUsers,
['alice', 'carol'],
'bob'
],
[
$inputUsers,
['alice', 'bob', 'carol'],
'dave'
],
[
$inputUsers,
['alice', 'bob', 'carol'],
null
]
];
}
/**
* @dataProvider takeOutCurrentUserProvider
* @param array $users
* @param array $expectedUIDs
* @param $currentUserId
*/
public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId) {
$this->instantiatePlugin();
$this->session->expects($this->once())
->method('getUser')
->willReturnCallback(function() use ($currentUserId) {
if($currentUserId !== null) {
return $this->getUserMock($currentUserId, $currentUserId);
}
return null;
});
$this->plugin->takeOutCurrentUser($users);
$this->assertSame($expectedUIDs, array_keys($users));
}
}

View File

@ -8,6 +8,9 @@ use Test\TestCase;
class CommentTest extends TestCase {
/**
* @throws \OCP\Comments\IllegalIDChangeException
*/
public function testSettersValidInput() {
$comment = new Comment();
@ -58,6 +61,9 @@ class CommentTest extends TestCase {
$comment->setId('c17');
}
/**
* @throws \OCP\Comments\IllegalIDChangeException
*/
public function testResetId() {
$comment = new Comment();
$comment->setId('c23');
@ -133,7 +139,7 @@ class CommentTest extends TestCase {
'@alice @bob look look, a duplication @alice test @bob!', ['alice', 'bob']
],
[
'@alice is the author, but notify @bob!', ['bob'], 'alice'
'@alice is the author, notify @bob, nevertheless mention her!', ['alice', 'bob'], 'alice'
],
[
'@foobar and @barfoo you should know, @foo@bar.com is valid' .
@ -159,7 +165,6 @@ class CommentTest extends TestCase {
$uid = array_shift($expectedUids);
$this->assertSame('user', $mention['type']);
$this->assertSame($uid, $mention['id']);
$this->assertNotSame($author, $mention['id']);
}
$this->assertEmpty($mentions);
$this->assertEmpty($expectedUids);