Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve user share suggestions #23265

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/private/User/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) {

$query = $this->dbConn->getQueryBuilder();

$displayNameParameter = '%' . implode('% %', array_map([$this->dbConn, 'escapeLikeParameter'], explode(' ', $search))) . '%';
$query->select('uid', 'displayname')
->from($this->table, 'u')
->leftJoin('u', 'preferences', 'p', $query->expr()->andX(
Expand All @@ -274,9 +275,20 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) {
)
// sqlite doesn't like re-using a single named parameter here
->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')))
->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')))
->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')))
->orderBy($query->func()->lower('displayname'), 'ASC')
->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter($displayNameParameter)))
->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')));

$serverAbsolutePath = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
$serverFederationPath = rtrim(\OC\Share\Share::removeProtocolFromUrl($serverAbsolutePath), '/');

/*
* the given search looks like a local federation.
*/
if (mb_strpos($search, '@'.$serverFederationPath) !== false) {
$query->orWhere($query->expr()->eq('uid', $query->createPositionalParameter(explode('@', $search)[0])));
}
Comment on lines +281 to +289
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be here from my pov.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your review @nickvergessen
can you give me a little more information what you mean with this?
do you mean it should be in another class/method and somehow gets injected there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well "federation a like" results are returned by other search plugins?


$query->orderBy($query->func()->lower('displayname'), 'ASC')
->orderBy('uid_lower', 'ASC')
->setMaxResults($limit)
->setFirstResult($offset);
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/User/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public function testSearch() {
$result = $this->backend->getDisplayNames('display');
$this->assertCount(1, $result);

$result = $this->backend->getDisplayNames('Use Dis');
$this->assertCount(1, $result);

$result = $this->backend->getDisplayNames($user1Obj->getCloudId());
$this->assertCount(1, $result);

$result = $this->backend->getDisplayNames(strtoupper($user1));
$this->assertCount(1, $result);

Expand Down