summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2015-02-17 15:08:16 +0100
committerJoas Schilling <nickvergessen@gmx.de>2015-02-17 17:26:03 +0100
commit0833a6e332766c842a1c890c29db7ac731fa008a (patch)
treef03be5762e49b10e17916ae16542375c974d4f15 /apps/files_sharing/lib
parent76c511de92f1b4dc6dcc31ac5ae15ffade29bb18 (diff)
downloadnextcloud-server-0833a6e332766c842a1c890c29db7ac731fa008a.tar.gz
nextcloud-server-0833a6e332766c842a1c890c29db7ac731fa008a.zip
Correctly create activities for public downloads
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/controllers/sharecontroller.php48
1 files changed, 35 insertions, 13 deletions
diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php
index 34339154b5c..cdcf3bbdc37 100644
--- a/apps/files_sharing/lib/controllers/sharecontroller.php
+++ b/apps/files_sharing/lib/controllers/sharecontroller.php
@@ -230,26 +230,48 @@ class ShareController extends Controller {
}
}
+ $files_list = null;
+ if (!is_null($files)) { // download selected files
+ $files_list = json_decode($files);
+ // in case we get only a single file
+ if ($files_list === null) {
+ $files_list = array($files);
+ }
+ }
+
$originalSharePath = self::getPath($token);
+ // Create the activities
if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) {
$originalSharePath = Filesystem::normalizePath($originalSharePath . $path);
- $type = \OC\Files\Filesystem::is_dir($originalSharePath) ? 'folder' : 'file';
- $args = $type === 'folder' ? array('dir' => $originalSharePath) : array('dir' => dirname($originalSharePath), 'scrollto' => basename($originalSharePath));
- $linkToFile = \OCP\Util::linkToAbsolute('files', 'index.php', $args);
- $subject = $type === 'folder' ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
- $this->activityManager->publishActivity(
- 'files_sharing', $subject, array($originalSharePath), '', array(), $originalSharePath,
- $linkToFile, $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM);
- }
+ $isDir = \OC\Files\Filesystem::is_dir($originalSharePath);
- if (!is_null($files)) { // download selected files
- $files_list = json_decode($files);
- // in case we get only a single file
- if ($files_list === NULL) {
- $files_list = array($files);
+ $activities = [];
+ if (!$isDir) {
+ // Single file public share
+ $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
+ } else if (!empty($files_list)) {
+ // Only some files are 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;
+ }
+ } 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
+ );
+ }
+ }
+
+ // download selected files
+ if (!is_null($files)) {
// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
// after dispatching the request which results in a "Cannot modify header information" notice.
OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');