only require user to be set in a query that handles tags

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2021-03-18 17:16:28 +01:00 committed by backportbot[bot]
parent d2245734d4
commit 2500d296c5
4 changed files with 24 additions and 25 deletions

View File

@ -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;
}
/**

View File

@ -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;

View File

@ -62,7 +62,7 @@ interface ISearchQuery {
/**
* The user that issued the search
*
* @return IUser
* @return ?IUser
* @since 12.0.0
*/
public function getUser();

View File

@ -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())