Merge pull request #12997 from owncloud/sharing_activities
add activity if public shared file/folder was downloaded
This commit is contained in:
commit
711220e82d
3 changed files with 44 additions and 7 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -99,6 +105,10 @@ class Activity implements \OCP\Activity\IExtension {
|
|||
return $l->t('%1$s declined remote share %2$s', $params)->__toString();
|
||||
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) {
|
||||
switch ($type) {
|
||||
case self::TYPE_REMOTE_SHARE:
|
||||
return 'icon-share';
|
||||
case self::TYPE_PUBLIC_LINKS:
|
||||
return 'icon-download';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue