Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-02-18 16:46:58 +0300
committerVincent Petry <pvince81@owncloud.com>2015-02-18 16:46:58 +0300
commit837365fff24b5dc2a85289c32f9bdb885fea2b9a (patch)
tree7abd32e10e2cd97a26e0a93baab894310cb8c1c5 /apps
parentcaa6d3e2db27390a4fc591f563ab05bad7cc3c70 (diff)
parentb768a70616eade852fb1eec43dc3fa5095bf4bf7 (diff)
Merge pull request #14210 from owncloud/activity/225-sharing-extension-jenkins
Activity/225 sharing extension
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/appinfo/app.php5
-rw-r--r--apps/files_sharing/lib/activity.php214
-rw-r--r--apps/files_sharing/tests/activity.php12
3 files changed, 156 insertions, 75 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 837ceacbab3..8989f8cef2a 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -28,7 +28,10 @@ OCP\Util::addScript('files_sharing', 'external');
OC_FileProxy::register(new OCA\Files\Share\Proxy());
\OC::$server->getActivityManager()->registerExtension(function() {
- return new \OCA\Files_Sharing\Activity();
+ return new \OCA\Files_Sharing\Activity(
+ \OC::$server->query('L10NFactory'),
+ \OC::$server->getURLGenerator()
+ );
});
$config = \OC::$server->getConfig();
diff --git a/apps/files_sharing/lib/activity.php b/apps/files_sharing/lib/activity.php
index bfac91fd71a..0cd874d69f0 100644
--- a/apps/files_sharing/lib/activity.php
+++ b/apps/files_sharing/lib/activity.php
@@ -1,37 +1,70 @@
<?php
/**
- * ownCloud - publish activities
+ * ownCloud - Sharing Activity Extension
*
* @copyright (c) 2014, ownCloud Inc.
*
* @author Bjoern Schiessle <schiessle@owncloud.com>
+ * @author Joas Schilling <nickvergessen@owncloud.com>
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
*/
namespace OCA\Files_Sharing;
-class Activity implements \OCP\Activity\IExtension {
+use OC\L10N\Factory;
+use OCP\Activity\IExtension;
+use OCP\IURLGenerator;
- const TYPE_REMOTE_SHARE = 'remote_share';
+class Activity implements IExtension {
+ /**
+ * Filter with all sharing related activities
+ */
+ const FILTER_SHARES = 'shares';
+
+ /**
+ * Activity types known to this extension
+ */
const TYPE_PUBLIC_LINKS = 'public_links';
- const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received';
+ const TYPE_REMOTE_SHARE = 'remote_share';
+ const TYPE_SHARED = 'shared';
+
+ /**
+ * Subject keys for translation of the subjections
+ */
+ const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded';
+ const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded';
+
const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted';
const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined';
+ const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received';
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';
+
+ const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
+ const SUBJECT_SHARED_LINK_SELF = 'shared_link_self';
+ const SUBJECT_SHARED_USER_SELF = 'shared_user_self';
+ const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
+
+ /** @var Factory */
+ protected $languageFactory;
+
+ /** @var IURLGenerator */
+ protected $URLGenerator;
+
+ /**
+ * @param Factory $languageFactory
+ * @param IURLGenerator $URLGenerator
+ */
+ public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator) {
+ $this->languageFactory = $languageFactory;
+ $this->URLGenerator = $URLGenerator;
+ }
+
+ protected function getL10N($languageCode = null) {
+ return $this->languageFactory->get('files_sharing', $languageCode);
+ }
/**
* The extension can return an array of additional notification types.
@@ -41,45 +74,52 @@ class Activity implements \OCP\Activity\IExtension {
* @return array|false
*/
public function getNotificationTypes($languageCode) {
- $l = \OC::$server->getL10N('files_sharing', $languageCode);
+ $l = $this->getL10N($languageCode);
+
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>'),
+ self::TYPE_SHARED => (string) $l->t('A file or folder has been <strong>shared</strong>'),
+ self::TYPE_REMOTE_SHARE => (string) $l->t('A file or folder was shared from <strong>another server</strong>'),
+ self::TYPE_PUBLIC_LINKS => (string) $l->t('A public shared file or folder was <strong>downloaded</strong>'),
);
}
/**
- * The extension can filter the types based on the filter if required.
- * In case no filter is to be applied false is to be returned unchanged.
+ * For a given method additional types to be displayed in the settings can be returned.
+ * In case no additional types are to be added false is to be returned.
*
- * @param array $types
- * @param string $filter
+ * @param string $method
* @return array|false
*/
- public function filterNotificationTypes($types, $filter) {
- return $types;
+ public function getDefaultTypes($method) {
+ $defaultTypes = [
+ self::TYPE_SHARED,
+ self::TYPE_REMOTE_SHARE,
+ ];
+
+ if ($method === 'stream') {
+ $defaultTypes[] = self::TYPE_PUBLIC_LINKS;
+ }
+
+ return $defaultTypes;
}
/**
- * For a given method additional types to be displayed in the settings can be returned.
- * In case no additional types are to be added false is to be returned.
+ * A string naming the css class for the icon to be used can be returned.
+ * If no icon is known for the given type false is to be returned.
*
- * @param string $method
- * @return array|false
+ * @param string $type
+ * @return string|false
*/
- public function getDefaultTypes($method) {
- switch ($method) {
- case 'email':
- $result = array(self::TYPE_REMOTE_SHARE);
- break;
- case 'stream':
- $result = array(self::TYPE_REMOTE_SHARE, self::TYPE_PUBLIC_LINKS);
- break;
- default:
- $result = false;
+ public function getTypeIcon($type) {
+ switch ($type) {
+ case self::TYPE_SHARED:
+ case self::TYPE_REMOTE_SHARE:
+ return 'icon-share';
+ case self::TYPE_PUBLIC_LINKS:
+ return 'icon-download';
}
- return $result;
+ return false;
}
/**
@@ -95,23 +135,33 @@ class Activity implements \OCP\Activity\IExtension {
* @return string|false
*/
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
-
- $l = \OC::$server->getL10N('files_sharing', $languageCode);
+ $l = $this->getL10N($languageCode);
if ($app === 'files_sharing') {
switch ($text) {
case self::SUBJECT_REMOTE_SHARE_RECEIVED:
- return $l->t('You received a new remote share from %s', $params)->__toString();
+ return (string) $l->t('You received a new remote share from %s', $params);
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
- return $l->t('%1$s accepted remote share %2$s', $params)->__toString();
+ return (string) $l->t('%1$s accepted remote share %2$s', $params);
case self::SUBJECT_REMOTE_SHARE_DECLINED:
- return $l->t('%1$s declined remote share %2$s', $params)->__toString();
+ return (string) $l->t('%1$s declined remote share %2$s', $params);
case self::SUBJECT_REMOTE_SHARE_UNSHARED:
- return $l->t('%1$s unshared %2$s from you', $params)->__toString();
+ return (string) $l->t('%1$s unshared %2$s from you', $params);
case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
- return $l->t('Public shared folder %1$s was downloaded', $params)->__toString();
+ return (string) $l->t('Public shared folder %1$s was downloaded', $params);
case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
- return $l->t('Public shared file %1$s was downloaded', $params)->__toString();
+ return (string) $l->t('Public shared file %1$s was downloaded', $params);
+ }
+ } else if ($app === 'files') {
+ switch ($text) {
+ case self::SUBJECT_SHARED_USER_SELF:
+ return (string) $l->t('You shared %1$s with %2$s', $params);
+ case self::SUBJECT_SHARED_GROUP_SELF:
+ return (string) $l->t('You shared %1$s with group %2$s', $params);
+ case self::SUBJECT_SHARED_WITH_BY:
+ return (string) $l->t('%2$s shared %1$s with you', $params);
+ case self::SUBJECT_SHARED_LINK_SELF:
+ return (string) $l->t('You shared %1$s via link', $params);
}
}
@@ -149,24 +199,19 @@ class Activity implements \OCP\Activity\IExtension {
0 => 'file',
);
}
- }
-
- return false;
- }
+ } else if ($app === 'files') {
+ switch ($text) {
+ case self::SUBJECT_SHARED_LINK_SELF:
+ case self::SUBJECT_SHARED_USER_SELF:
+ case self::SUBJECT_SHARED_WITH_BY:
+ return [0 => 'file', 1 => 'username'];
- /**
- * A string naming the css class for the icon to be used can be returned.
- * If no icon is known for the given type false is to be returned.
- *
- * @param string $type
- * @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';
+ case self::SUBJECT_SHARED_GROUP_SELF:
+ return [
+ 0 => 'file',
+ //1 => 'group', Group does not exist yet
+ ];
+ }
}
return false;
@@ -191,7 +236,17 @@ class Activity implements \OCP\Activity\IExtension {
* @return array|false
*/
public function getNavigation() {
- return false;
+ $l = $this->getL10N();
+ return [
+ 'apps' => [],
+ 'top' => [
+ self::FILTER_SHARES => [
+ 'id' => self::FILTER_SHARES,
+ 'name' => (string) $l->t('Shares'),
+ 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => self::FILTER_SHARES]),
+ ],
+ ],
+ ];
}
/**
@@ -201,6 +256,22 @@ class Activity implements \OCP\Activity\IExtension {
* @return boolean
*/
public function isFilterValid($filterValue) {
+ return $filterValue === self::FILTER_SHARES;
+ }
+
+ /**
+ * The extension can filter the types based on the filter if required.
+ * In case no filter is to be applied false is to be returned unchanged.
+ *
+ * @param array $types
+ * @param string $filter
+ * @return array|false
+ */
+ public function filterNotificationTypes($types, $filter) {
+ switch ($filter) {
+ case self::FILTER_SHARES:
+ return array_intersect([self::TYPE_SHARED, self::TYPE_REMOTE_SHARE], $types);
+ }
return false;
}
@@ -214,8 +285,11 @@ class Activity implements \OCP\Activity\IExtension {
* @return array|false
*/
public function getQueryForFilter($filter) {
- if ($filter === 'shares') {
- return array('`app` = ? and `type` = ?', array('files_sharing', self::TYPE_REMOTE_SHARE));
+ if ($filter === self::FILTER_SHARES) {
+ return [
+ '(`app` = ? or `app` = ?)',
+ ['files_sharing', 'files'],
+ ];
}
return false;
}
diff --git a/apps/files_sharing/tests/activity.php b/apps/files_sharing/tests/activity.php
index 04930e3bb76..6975a41fb8b 100644
--- a/apps/files_sharing/tests/activity.php
+++ b/apps/files_sharing/tests/activity.php
@@ -34,7 +34,12 @@ class Activity extends \OCA\Files_Sharing\Tests\TestCase{
protected function setUp() {
parent::setUp();
- $this->activity = new \OCA\Files_Sharing\Activity();
+ $this->activity = new \OCA\Files_Sharing\Activity(
+ $this->getMock('\OC\L10N\Factory'),
+ $this->getMockBuilder('\OC\URLGenerator')
+ ->disableOriginalConstructor()
+ ->getMock()
+ );
}
/**
@@ -56,9 +61,8 @@ class Activity extends \OCA\Files_Sharing\Tests\TestCase{
public function dataTestGetDefaultType() {
return array(
- array('email', array(\OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE)),
- array('stream', array(\OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::TYPE_PUBLIC_LINKS)),
- array('foo', false)
+ array('email', array(\OCA\Files_Sharing\Activity::TYPE_SHARED, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE)),
+ array('stream', array(\OCA\Files_Sharing\Activity::TYPE_SHARED, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::TYPE_PUBLIC_LINKS)),
);
}