diff options
author | Björn Schießle <bjoern@schiessle.org> | 2014-12-22 23:31:07 +0100 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2014-12-22 23:31:07 +0100 |
commit | 711220e82d70764b96e30c9cd9b53c0fa9524232 (patch) | |
tree | 678deeb10d1724c4ad94d48738ee831feaf73ab3 | |
parent | bedc4664e41b542eae15b1038b22ace817fc447f (diff) | |
parent | 3afcc717640cfcde78c671ed536ab3b618b85f72 (diff) | |
download | nextcloud-server-711220e82d70764b96e30c9cd9b53c0fa9524232.tar.gz nextcloud-server-711220e82d70764b96e30c9cd9b53c0fa9524232.zip |
Merge pull request #12997 from owncloud/sharing_activities
add activity if public shared file/folder was downloaded
-rw-r--r-- | apps/files_sharing/application.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/lib/activity.php | 30 | ||||
-rw-r--r-- | apps/files_sharing/lib/controllers/sharecontroller.php | 18 |
3 files changed, 44 insertions, 7 deletions
diff --git a/apps/files_sharing/application.php b/apps/files_sharing/application.php index 9fe8785df0b..773831d99b1 100644 --- a/apps/files_sharing/application.php +++ b/apps/files_sharing/application.php @@ -42,7 +42,8 @@ class Application extends App { $c->query('ServerContainer')->getConfig(), $c->query('URLGenerator'), $c->query('ServerContainer')->getUserManager(), - $c->query('ServerContainer')->getLogger() + $c->query('ServerContainer')->getLogger(), + $c->query('ServerContainer')->getActivityManager() ); }); $container->registerService('ExternalSharesController', function(SimpleContainer $c) { diff --git a/apps/files_sharing/lib/activity.php b/apps/files_sharing/lib/activity.php index 868830d80cd..5c8fd64db78 100644 --- a/apps/files_sharing/lib/activity.php +++ b/apps/files_sharing/lib/activity.php @@ -25,10 +25,13 @@ namespace OCA\Files_Sharing; class Activity implements \OCP\Activity\IExtension { const TYPE_REMOTE_SHARE = 'remote_share'; + const TYPE_PUBLIC_LINKS = 'public_links'; const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; + const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; + const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; /** * The extension can return an array of additional notification types. @@ -39,7 +42,10 @@ class Activity implements \OCP\Activity\IExtension { */ public function getNotificationTypes($languageCode) { $l = \OC::$server->getL10N('files_sharing', $languageCode); - return array(self::TYPE_REMOTE_SHARE => $l->t('A file or folder was shared from <strong>another server</strong>')); + return array( + self::TYPE_REMOTE_SHARE => $l->t('A file or folder was shared from <strong>another server</strong>'), + self::TYPE_PUBLIC_LINKS => $l->t('A public shared file or folder was <strong>downloaded</strong>'), + ); } /** @@ -63,7 +69,7 @@ class Activity implements \OCP\Activity\IExtension { */ public function getDefaultTypes($method) { if ($method === 'stream') { - return array(self::TYPE_REMOTE_SHARE); + return array(self::TYPE_REMOTE_SHARE, self::TYPE_PUBLIC_LINKS); } return false; @@ -97,8 +103,12 @@ class Activity implements \OCP\Activity\IExtension { return $l->t('%1$s accepted remote share %2$s', $params)->__toString(); case self::SUBJECT_REMOTE_SHARE_DECLINED: return $l->t('%1$s declined remote share %2$s', $params)->__toString(); - case self::SUBJECT_REMOTE_SHARE_UNSHARED: + case self::SUBJECT_REMOTE_SHARE_UNSHARED: return $l->t('%1$s unshared %2$s from you', $params)->__toString(); + case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: + return $l->t('Public shared folder %1$s was downloaded', $params)->__toString(); + case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: + return $l->t('Public shared file %1$s was downloaded', $params)->__toString(); } } } @@ -128,6 +138,11 @@ class Activity implements \OCP\Activity\IExtension { 0 => '',// We can not use 'username' since the user is in a different ownCloud 1 => 'file', ); + case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: + case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: + return array( + 0 => 'file', + ); } } @@ -142,7 +157,14 @@ class Activity implements \OCP\Activity\IExtension { * @return string|false */ public function getTypeIcon($type) { - return 'icon-share'; + switch ($type) { + case self::TYPE_REMOTE_SHARE: + return 'icon-share'; + case self::TYPE_PUBLIC_LINKS: + return 'icon-download'; + } + + return false; } /** diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index 0a0594ed8ff..8b04fbd0341 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -29,6 +29,7 @@ use OCP\ILogger; use OCA\Files_Sharing\Helper; use OCP\User; use OCP\Util; +use OCA\Files_Sharing\Activity; /** * Class ShareController @@ -49,6 +50,8 @@ class ShareController extends Controller { protected $userManager; /** @var \OCP\ILogger */ protected $logger; + /** @var OCP\Activity\IManager */ + protected $activityManager; /** * @param string $appName @@ -59,6 +62,7 @@ class ShareController extends Controller { * @param URLGenerator $urlGenerator * @param OC\User\Manager $userManager * @param ILogger $logger + * @param OCP\Activity\IManager $activityManager */ public function __construct($appName, IRequest $request, @@ -67,7 +71,8 @@ class ShareController extends Controller { OCP\IConfig $config, URLGenerator $urlGenerator, OC\User\Manager $userManager, - ILogger $logger) { + ILogger $logger, + OCP\Activity\IManager $activityManager) { parent::__construct($appName, $request); $this->userSession = $userSession; @@ -76,6 +81,7 @@ class ShareController extends Controller { $this->urlGenerator = $urlGenerator; $this->userManager = $userManager; $this->logger = $logger; + $this->activityManager = $activityManager; } /** @@ -226,9 +232,17 @@ class ShareController extends Controller { if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) { $getPath = Filesystem::normalizePath($path); - $originalSharePath .= $getPath; + $originalSharePath = Filesystem::normalizePath($originalSharePath . $getPath); + $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); + if (!is_null($files)) { // download selected files $files_list = json_decode($files); // in case we get only a single file |