aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-03-18 17:16:28 +0100
committerRobin Appelman <robin@icewind.nl>2021-03-18 17:16:28 +0100
commit50e374c12fce6b0aeee62f42edcd18a573537a8f (patch)
treed832c977b69aeda8ab22f21a209ccb485d129e64
parentf8bca545df7cc31b4ace6f9af9294cc182bd401e (diff)
downloadnextcloud-server-50e374c12fce6b0aeee62f42edcd18a573537a8f.tar.gz
nextcloud-server-50e374c12fce6b0aeee62f42edcd18a573537a8f.zip
only require user to be set in a query that handles tags
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/Cache/Cache.php12
-rw-r--r--lib/private/Files/Search/SearchQuery.php8
-rw-r--r--lib/public/Files/Search/ISearchQuery.php2
-rw-r--r--tests/lib/Files/Node/FolderTest.php27
4 files changed, 24 insertions, 25 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index a18fddcbdeb..59e50164ef6 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -198,10 +198,10 @@ class Cache implements ICache {
}
$data['permissions'] = (int)$data['permissions'];
if (isset($data['creation_time'])) {
- $data['creation_time'] = (int) $data['creation_time'];
+ $data['creation_time'] = (int)$data['creation_time'];
}
if (isset($data['upload_time'])) {
- $data['upload_time'] = (int) $data['upload_time'];
+ $data['upload_time'] = (int)$data['upload_time'];
}
return new CacheEntry($data);
}
@@ -841,6 +841,10 @@ class Cache implements ICache {
$query->whereStorageId();
if ($this->querySearchHelper->shouldJoinTags($searchQuery->getSearchOperation())) {
+ $user = $searchQuery->getUser();
+ if ($user === null) {
+ throw new \InvalidArgumentException("Searching by tag requires the user to be set in the query");
+ }
$query
->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid'))
->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX(
@@ -848,7 +852,7 @@ class Cache implements ICache {
$builder->expr()->eq('tagmap.categoryid', 'tag.id')
))
->andWhere($builder->expr()->eq('tag.type', $builder->createNamedParameter('files')))
- ->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($searchQuery->getUser()->getUID())));
+ ->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($user->getUID())));
}
$searchExpr = $this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation());
@@ -1031,7 +1035,7 @@ class Cache implements ICache {
return null;
}
- return (string) $path;
+ return (string)$path;
}
/**
diff --git a/lib/private/Files/Search/SearchQuery.php b/lib/private/Files/Search/SearchQuery.php
index b7b8b801104..091fe57d21b 100644
--- a/lib/private/Files/Search/SearchQuery.php
+++ b/lib/private/Files/Search/SearchQuery.php
@@ -37,7 +37,7 @@ class SearchQuery implements ISearchQuery {
private $offset;
/** @var ISearchOrder[] */
private $order;
- /** @var IUser */
+ /** @var ?IUser */
private $user;
private $limitToHome;
@@ -48,7 +48,7 @@ class SearchQuery implements ISearchQuery {
* @param int $limit
* @param int $offset
* @param array $order
- * @param IUser $user
+ * @param ?IUser $user
* @param bool $limitToHome
*/
public function __construct(
@@ -56,7 +56,7 @@ class SearchQuery implements ISearchQuery {
int $limit,
int $offset,
array $order,
- IUser $user,
+ ?IUser $user = null,
bool $limitToHome = false
) {
$this->searchOperation = $searchOperation;
@@ -96,7 +96,7 @@ class SearchQuery implements ISearchQuery {
}
/**
- * @return IUser
+ * @return ?IUser
*/
public function getUser() {
return $this->user;
diff --git a/lib/public/Files/Search/ISearchQuery.php b/lib/public/Files/Search/ISearchQuery.php
index 4d866f8d7b6..dd7c901f7f5 100644
--- a/lib/public/Files/Search/ISearchQuery.php
+++ b/lib/public/Files/Search/ISearchQuery.php
@@ -62,7 +62,7 @@ interface ISearchQuery {
/**
* The user that issued the search
*
- * @return IUser
+ * @return ?IUser
* @since 12.0.0
*/
public function getUser();
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 1ba052b8de4..6d3367ac09e 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -305,10 +305,9 @@ class FolderTest extends NodeTest {
->willReturn('foo');
$cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
+ ->method('searchQuery')
->willReturn([
- ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
+ new CacheEntry(['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'])
]);
$root->expects($this->once())
@@ -358,11 +357,10 @@ class FolderTest extends NodeTest {
->willReturn($cache);
$cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
+ ->method('searchQuery')
->willReturn([
- ['fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'],
- ['fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'],
+ new CacheEntry(['fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']),
+ new CacheEntry(['fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']),
]);
$root->expects($this->once())
@@ -409,10 +407,9 @@ class FolderTest extends NodeTest {
->willReturn($cache);
$cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
+ ->method('searchQuery')
->willReturn([
- ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
+ new CacheEntry(['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'])
]);
$root->expects($this->once())
@@ -475,17 +472,15 @@ class FolderTest extends NodeTest {
->willReturn($subCache);
$cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
+ ->method('searchQuery')
->willReturn([
- ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
+ new CacheEntry(['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'])
]);
$subCache->expects($this->once())
- ->method('search')
- ->with('%qw%')
+ ->method('searchQuery')
->willReturn([
- ['fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
+ new CacheEntry(['fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'])
]);
$root->expects($this->once())