Skip to content

Commit

Permalink
feat: specify media type via url path: systemtags-current/$mediaType
Browse files Browse the repository at this point in the history
- only the media part of the mime type can be search, but not the full
  mime type. It can be added, should it become necessary.
- thus fixes previously hardcoded selector for image/ types
- also fixes a return type hint
- adds a return type hint

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed May 4, 2023
1 parent 512a4b4 commit ce5ea9c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
17 changes: 15 additions & 2 deletions apps/dav/lib/SystemTag/SystemTagsInUseCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,42 @@
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;

class SystemTagsInUseCollection extends \Sabre\DAV\SimpleCollection {
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected string $mediaType;

public function __construct(IUserSession $userSession, IRootFolder $rootFolder) {
public function __construct(IUserSession $userSession, IRootFolder $rootFolder, string $mediaType = '') {
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->mediaType = $mediaType;
$this->name = 'systemtags-current';
if ($this->mediaType != '') {
$this->name .= '/' . $this->mediaType;
}
}

public function setName($name): void {
throw new Forbidden('Permission denied to rename this collection');
}

public function getChild($name) {
if ($this->mediaType !== '') {
throw new NotFound('Invalid media type');
}
return new self($this->userSession, $this->rootFolder, $name);
}

public function getChildren() {
$user = $this->userSession->getUser();
if ($user === null) {
throw new Forbidden('Permission denied to read this collection');
}

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$result = $userFolder->getSystemTags('image');
$result = $userFolder->getSystemTags($this->mediaType);
$children = [];
foreach ($result as $tagData) {
$tag = new SystemTag((string)$tagData['id'], $tagData['name'], (bool)$tagData['visibility'], (bool)$tagData['editable']);
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ protected function applySearchConstraints(CacheQueryBuilder $query, ISearchQuery
}
}


/**
* @return array<array-key, array{id: int, name: string, visibility: int, editable: int, ref_file_id: int, number_files: int}>
*/
public function findUsedTagsInCaches(ISearchQuery $searchQuery, array $caches): array {
$query = $this->getQueryBuilder();
$query->selectTagUsage();
Expand Down
11 changes: 9 additions & 2 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,17 @@ public function searchBySystemTag(string $tag, string $userId, int $limit = 0, i
}

/**
* @return Node[]
*
* @return array<array-key, array{id: int, name: string, visibility: int, editable: int, ref_file_id: int, number_files: int}>
*/
public function getSystemTags(string $mediaType, int $limit = 0, int $offset = 0): array {
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mediaType . '/%'), null, $limit, $offset);
// Currently query has to have exactly one search condition. If no media type is provided,
// we fall back to the presence of a systemtag.
if (empty($mediaType)) {
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%'), null, $limit, $offset);
} else {
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mediaType . '/%'), null, $limit, $offset);
}
[$caches, ] = $this->getCachesAndMountpointsForSearch();
/** @var QuerySearchHelper $searchHelper */
$searchHelper = \OCP\Server::get(QuerySearchHelper::class);
Expand Down

0 comments on commit ce5ea9c

Please sign in to comment.