summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-15 11:49:50 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-20 21:12:26 +0100
commit8734ebe505d621c355da0495e29692c56ca45226 (patch)
tree7e40c72fbc4e0f2318c67c64319569cbc50179a3 /apps/files_sharing/lib
parent717697313b07106fd7941b83ff0271272c2c7791 (diff)
downloadnextcloud-server-8734ebe505d621c355da0495e29692c56ca45226.tar.gz
nextcloud-server-8734ebe505d621c355da0495e29692c56ca45226.zip
[Share 2.0] Make link share download use share manager
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/controllers/sharecontroller.php116
1 files changed, 63 insertions, 53 deletions
diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php
index f701a66dd0f..2342a092c64 100644
--- a/apps/files_sharing/lib/controllers/sharecontroller.php
+++ b/apps/files_sharing/lib/controllers/sharecontroller.php
@@ -52,6 +52,7 @@ use OCP\Util;
use OCA\Files_Sharing\Activity;
use \OCP\Files\NotFoundException;
use \OC\Share20\IShare;
+use OCP\Files\IRootFolder;
/**
* Class ShareController
@@ -76,6 +77,8 @@ class ShareController extends Controller {
protected $session;
/** @var IPreview */
protected $previewManager;
+ /** @var IRootFolder */
+ protected $rootFolder;
/**
* @param string $appName
@@ -98,7 +101,8 @@ class ShareController extends Controller {
\OCP\Activity\IManager $activityManager,
\OC\Share20\Manager $shareManager,
ISession $session,
- IPreview $previewManager) {
+ IPreview $previewManager,
+ IRootFolder $rootFolder) {
parent::__construct($appName, $request);
$this->config = $config;
@@ -109,6 +113,7 @@ class ShareController extends Controller {
$this->shareManager = $shareManager;
$this->session = $session;
$this->previewManager = $previewManager;
+ $this->rootFolder = $rootFolder;
}
/**
@@ -286,14 +291,12 @@ class ShareController extends Controller {
public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
\OC_User::setIncognitoMode(true);
- $linkItem = OCP\Share::getShareByToken($token, false);
+ $share = $this->shareManager->getShareByToken($token);
// Share is password protected - check whether the user is permitted to access the share
- if (isset($linkItem['share_with'])) {
- if(!Helper::authenticate($linkItem)) {
- return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
- array('token' => $token)));
- }
+ if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
+ return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
+ ['token' => $token]));
}
$files_list = null;
@@ -301,41 +304,74 @@ class ShareController extends Controller {
$files_list = json_decode($files);
// in case we get only a single file
if ($files_list === null) {
- $files_list = array($files);
+ $files_list = [$files];
}
}
- $originalSharePath = self::getPath($token);
+ $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID());
+ $originalSharePath = $userFolder->getRelativePath($share->getPath()->getPath());
+
+ // Single file share
+ if ($share->getPath() instanceof \OCP\Files\File) {
+ $this->activityManager->publishActivity(
+ 'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$originalSharePath], '', [],
+ $originalSharePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
+ );
+ }
+ // Directory share
+ else {
+ /** @var \OCP\Files\Folder $node */
+ $node = $share->getPath();
+
+ // Try to get the path
+ if ($path !== '') {
+ try {
+ $node = $node->get($path);
+ } catch (NotFoundException $e) {
+ return new NotFoundResponse();
+ }
+ }
- // Create the activities
- if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) {
- $originalSharePath = Filesystem::normalizePath($originalSharePath . $path);
- $isDir = \OC\Files\Filesystem::is_dir($originalSharePath);
+ $originalSharePath = $userFolder->getRelativePath($node->getPath());
- $activities = [];
- if (!$isDir) {
- // Single file public share
- $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
+ if ($node instanceof \OCP\Files\File) {
+ // Single file download
+ $this->activityManager->publishActivity(
+ 'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$originalSharePath], '', [],
+ $originalSharePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
+ );
} else if (!empty($files_list)) {
- // Only some files are downloaded
+ /** @var \OCP\Files\Folder $node */
+
+ // Subset of files is downloaded
foreach ($files_list as $file) {
- $filePath = Filesystem::normalizePath($originalSharePath . '/' . $file);
- $isDir = \OC\Files\Filesystem::is_dir($filePath);
- $activities[$filePath] = ($isDir) ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
+ $subNode = $node->get($file);
+ $nodePath = $userFolder->getRelativePath($node->getPath());
+ if ($subNode instanceof \OCP\Files\File) {
+ $this->activityManager->publishActivity(
+ 'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$nodePath], '', [],
+ $nodePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
+ );
+ } else {
+ $this->activityManager->publishActivity(
+ 'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$nodePath], '', [],
+ $nodePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
+ );
+ }
}
} else {
// The folder is downloaded
- $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
- }
-
- foreach ($activities as $filePath => $subject) {
$this->activityManager->publishActivity(
- 'files_sharing', $subject, array($filePath), '', array(),
- $filePath, '', $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
+ 'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$originalSharePath], '', [],
+ $originalSharePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
);
}
}
+ /* FIXME: We should do this all nicely in OCP */
+ OC_Util::tearDownFS();
+ OC_Util::setupFS($share->getShareOwner()->getUID());
+
/**
* this sets a cookie to be able to recognize the start of the download
* the content must not be longer than 32 characters and must only contain
@@ -362,30 +398,4 @@ class ShareController extends Controller {
exit();
}
}
-
- /**
- * @param string $token
- * @return string Resolved file path of the token
- * @throws NotFoundException In case share could not get properly resolved
- */
- private function getPath($token) {
- $linkItem = Share::getShareByToken($token, false);
- if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
- // seems to be a valid share
- $rootLinkItem = Share::resolveReShare($linkItem);
- if (isset($rootLinkItem['uid_owner'])) {
- if(!$this->userManager->userExists($rootLinkItem['uid_owner'])) {
- throw new NotFoundException('Owner of the share does not exist anymore');
- }
- OC_Util::tearDownFS();
- OC_Util::setupFS($rootLinkItem['uid_owner']);
- $path = Filesystem::getPath($linkItem['file_source']);
- if(Filesystem::isReadable($path)) {
- return $path;
- }
- }
- }
-
- throw new NotFoundException('No file found belonging to file.');
- }
}