diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-03-16 11:03:26 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-03-17 15:35:21 +0100 |
commit | 950530b162cb109d258ba23d041e8fd98c9a936e (patch) | |
tree | 5138f6b9484c337d28e07dd00146caf257e4f3b5 /apps/files/controller | |
parent | f778e48ee5c9c80724d631190a1425eabc8d0df1 (diff) | |
download | nextcloud-server-950530b162cb109d258ba23d041e8fd98c9a936e.tar.gz nextcloud-server-950530b162cb109d258ba23d041e8fd98c9a936e.zip |
Display share status info in favorite list
Returns the shareTypes share status info to the favorites file list.
Diffstat (limited to 'apps/files/controller')
-rw-r--r-- | apps/files/controller/apicontroller.php | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/apps/files/controller/apicontroller.php b/apps/files/controller/apicontroller.php index c96d92a046b..43abf2ff458 100644 --- a/apps/files/controller/apicontroller.php +++ b/apps/files/controller/apicontroller.php @@ -34,6 +34,10 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataDisplayResponse; use OCA\Files\Service\TagService; use OCP\IPreview; +use OCP\Share\IManager; +use OCP\Files\FileInfo; +use OCP\Files\Node; +use OCP\IUserSession; /** * Class ApiController @@ -43,8 +47,12 @@ use OCP\IPreview; class ApiController extends Controller { /** @var TagService */ private $tagService; + /** @var IManager **/ + private $shareManager; /** @var IPreview */ private $previewManager; + /** IUserSession */ + private $userSession; /** * @param string $appName @@ -54,11 +62,15 @@ class ApiController extends Controller { */ public function __construct($appName, IRequest $request, + IUserSession $userSession, TagService $tagService, - IPreview $previewManager){ + IPreview $previewManager, + IManager $shareManager) { parent::__construct($appName, $request); + $this->userSession = $userSession; $this->tagService = $tagService; $this->previewManager = $previewManager; + $this->shareManager = $shareManager; } /** @@ -132,8 +144,10 @@ class ApiController extends Controller { */ public function getFilesByTag($tagName) { $files = array(); - $fileInfos = $this->tagService->getFilesByTag($tagName); - foreach ($fileInfos as &$fileInfo) { + $nodes = $this->tagService->getFilesByTag($tagName); + foreach ($nodes as &$node) { + $shareTypes = $this->getShareTypes($node); + $fileInfo = $node->getFileInfo(); $file = \OCA\Files\Helper::formatFileInfo($fileInfo); $parts = explode('/', dirname($fileInfo->getPath()), 4); if(isset($parts[3])) { @@ -142,9 +156,43 @@ class ApiController extends Controller { $file['path'] = '/'; } $file['tags'] = [$tagName]; + if (!empty($shareTypes)) { + $file['shareTypes'] = $shareTypes; + } $files[] = $file; } return new DataResponse(['files' => $files]); } + /** + * Return a list of share types for outgoing shares + * + * @param Node $node file node + * + * @return int[] array of share types + */ + private function getShareTypes(Node $node) { + $userId = $this->userSession->getUser()->getUID(); + $shareTypes = []; + $requestedShareTypes = [ + \OCP\Share::SHARE_TYPE_USER, + \OCP\Share::SHARE_TYPE_GROUP, + \OCP\Share::SHARE_TYPE_LINK + ]; + foreach ($requestedShareTypes as $requestedShareType) { + // one of each type is enough to find out about the types + $shares = $this->shareManager->getSharesBy( + $userId, + $requestedShareType, + $node, + false, + 1 + ); + if (!empty($shares)) { + $shareTypes[] = $requestedShareType; + } + } + return $shareTypes; + } + } |