Skip to content
Prev Previous commit
Next Next commit
only require user to be set in a query that handles tags
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Mar 24, 2021
commit 4655f6feb1073a799f4be386b7a0b27fc8c252be
12 changes: 8 additions & 4 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader
}
$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);
}
Expand Down Expand Up @@ -819,14 +819,18 @@ public function searchQuery(ISearchQuery $searchQuery) {
$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(
$builder->expr()->eq('tagmap.type', 'tag.type'),
$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());
Expand Down Expand Up @@ -1007,7 +1011,7 @@ public function getPathById($id) {
return null;
}

return (string) $path;
return (string)$path;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Files/Search/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SearchQuery implements ISearchQuery {
private $offset;
/** @var ISearchOrder[] */
private $order;
/** @var IUser */
/** @var ?IUser */
private $user;
private $limitToHome;

Expand All @@ -48,15 +48,15 @@ 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(
ISearchOperator $searchOperation,
int $limit,
int $offset,
array $order,
IUser $user,
?IUser $user = null,
bool $limitToHome = false
) {
$this->searchOperation = $searchOperation;
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getOrder() {
}

/**
* @return IUser
* @return ?IUser
*/
public function getUser() {
return $this->user;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Files/Search/ISearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getOrder();
/**
* The user that issued the search
*
* @return IUser
* @return ?IUser
* @since 12.0.0
*/
public function getUser();
Expand Down
27 changes: 11 additions & 16 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,9 @@ public function testSearch() {
->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())
Expand Down Expand Up @@ -358,11 +357,10 @@ public function testSearchInRoot() {
->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())
Expand Down Expand Up @@ -409,10 +407,9 @@ public function testSearchInStorageRoot() {
->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())
Expand Down Expand Up @@ -475,17 +472,15 @@ public function testSearchSubStorages() {
->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())
Expand Down