summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-04-09 00:18:31 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-04-09 00:18:31 +0200
commit9c76d068c3f0c57f667359ac65a296e72db721c2 (patch)
tree665a8a99c6544d819998a905c96f3ca82460d7ae /lib
parent84ae9532c882a1096cf5aad45d29305f3720c6ad (diff)
parent730efe25a4c386b2d2e4c1d1b0d16a71be7b9f28 (diff)
downloadnextcloud-server-9c76d068c3f0c57f667359ac65a296e72db721c2.tar.gz
nextcloud-server-9c76d068c3f0c57f667359ac65a296e72db721c2.zip
Merge pull request #15196 from owncloud/limit-file-activities-to-favorites
Limit file activities to favorites
Diffstat (limited to 'lib')
-rw-r--r--lib/private/activitymanager.php65
-rw-r--r--lib/private/allconfig.php2
-rw-r--r--lib/private/server.php10
-rw-r--r--lib/public/activity/imanager.php10
-rw-r--r--lib/public/iconfig.php2
-rw-r--r--lib/public/iservercontainer.php2
6 files changed, 85 insertions, 6 deletions
diff --git a/lib/private/activitymanager.php b/lib/private/activitymanager.php
index c6cd5a1fe83..26db0c78df2 100644
--- a/lib/private/activitymanager.php
+++ b/lib/private/activitymanager.php
@@ -28,8 +28,34 @@ namespace OC;
use OCP\Activity\IConsumer;
use OCP\Activity\IExtension;
use OCP\Activity\IManager;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IUserSession;
class ActivityManager implements IManager {
+ /** @var IRequest */
+ protected $request;
+
+ /** @var IUserSession */
+ protected $session;
+
+ /** @var IConfig */
+ protected $config;
+
+ /**
+ * constructor of the controller
+ *
+ * @param IRequest $request
+ * @param IUserSession $session
+ * @param IConfig $config
+ */
+ public function __construct(IRequest $request,
+ IUserSession $session,
+ IConfig $config) {
+ $this->request = $request;
+ $this->session = $session;
+ $this->config = $config;
+ }
/**
* @var \Closure[]
@@ -348,4 +374,43 @@ class ActivityManager implements IManager {
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
}
+
+ /**
+ * Get the user we need to use
+ *
+ * Either the user is logged in, or we try to get it from the token
+ *
+ * @return string
+ * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
+ */
+ public function getCurrentUserId() {
+ if (!$this->session->isLoggedIn()) {
+ return $this->getUserFromToken();
+ } else {
+ return $this->session->getUser()->getUID();
+ }
+ }
+
+ /**
+ * Get the user for the token
+ *
+ * @return string
+ * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
+ */
+ protected function getUserFromToken() {
+ $token = (string) $this->request->getParam('token', '');
+ if (strlen($token) !== 30) {
+ throw new \UnexpectedValueException('The token is invalid');
+ }
+
+ $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
+
+ if (sizeof($users) !== 1) {
+ // No unique user found
+ throw new \UnexpectedValueException('The token is invalid');
+ }
+
+ // Token found login as that user
+ return array_shift($users);
+ }
}
diff --git a/lib/private/allconfig.php b/lib/private/allconfig.php
index df75a332a13..63cc92601bb 100644
--- a/lib/private/allconfig.php
+++ b/lib/private/allconfig.php
@@ -253,7 +253,7 @@ class AllConfig implements \OCP\IConfig {
* @param string $userId the userId of the user that we want to store the value under
* @param string $appName the appName that we stored the value under
* @param string $key the key under which the value is being stored
- * @param string $default the default value to be returned if the value isn't set
+ * @param mixed $default the default value to be returned if the value isn't set
* @return string
*/
public function getUserValue($userId, $appName, $key, $default = '') {
diff --git a/lib/private/server.php b/lib/private/server.php
index 661aaf6786d..6b35998afa8 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -228,8 +228,12 @@ class Server extends SimpleContainer implements IServerContainer {
new ArrayCache()
);
});
- $this->registerService('ActivityManager', function ($c) {
- return new ActivityManager();
+ $this->registerService('ActivityManager', function (Server $c) {
+ return new ActivityManager(
+ $c->getRequest(),
+ $c->getUserSession(),
+ $c->getConfig()
+ );
});
$this->registerService('AvatarManager', function ($c) {
return new AvatarManager();
@@ -435,7 +439,7 @@ class Server extends SimpleContainer implements IServerContainer {
* currently being processed is returned from this method.
* In case the current execution was not initiated by a web request null is returned
*
- * @return \OCP\IRequest|null
+ * @return \OCP\IRequest
*/
function getRequest() {
return $this->query('Request');
diff --git a/lib/public/activity/imanager.php b/lib/public/activity/imanager.php
index f7885860c4a..2e55c8b45b2 100644
--- a/lib/public/activity/imanager.php
+++ b/lib/public/activity/imanager.php
@@ -136,4 +136,14 @@ interface IManager {
* @return array
*/
function getQueryForFilter($filter);
+
+ /**
+ * Get the user we need to use
+ *
+ * Either the user is logged in, or we try to get it from the token
+ *
+ * @return string
+ * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
+ */
+ public function getCurrentUserId();
}
diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php
index c63ba1a90a6..f28a114a2bb 100644
--- a/lib/public/iconfig.php
+++ b/lib/public/iconfig.php
@@ -133,7 +133,7 @@ interface IConfig {
* @param string $userId the userId of the user that we want to store the value under
* @param string $appName the appName that we stored the value under
* @param string $key the key under which the value is being stored
- * @param string $default the default value to be returned if the value isn't set
+ * @param mixed $default the default value to be returned if the value isn't set
* @return string
*/
public function getUserValue($userId, $appName, $key, $default = '');
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 16a680ec170..dd0d2f417cf 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -60,7 +60,7 @@ interface IServerContainer {
* is returned from this method.
* In case the current execution was not initiated by a web request null is returned
*
- * @return \OCP\IRequest|null
+ * @return \OCP\IRequest
*/
function getRequest();