From b5922e467ab2570d25ccbfce0d20115fbf831be8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Mar 2016 09:33:00 +0100 Subject: [PATCH] Allow the activity app to set the current user when sending emails --- lib/private/activitymanager.php | 20 +++++++++++++++++++- lib/public/activity/imanager.php | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/private/activitymanager.php b/lib/private/activitymanager.php index 373105291d..e522dca9e3 100644 --- a/lib/private/activitymanager.php +++ b/lib/private/activitymanager.php @@ -49,6 +49,9 @@ class ActivityManager implements IManager { /** @var int */ protected $formattingObjectId; + /** @var string */ + protected $currentUserId; + /** * constructor of the controller * @@ -475,6 +478,19 @@ class ActivityManager implements IManager { return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); } + /** + * Set the user we need to use + * + * @param string|null $currentUserId + * @throws \UnexpectedValueException If the user is invalid + */ + public function setCurrentUserId($currentUserId) { + if (!is_string($currentUserId) && $currentUserId !== null) { + throw new \UnexpectedValueException('The given current user is invalid'); + } + $this->currentUserId = $currentUserId; + } + /** * Get the user we need to use * @@ -484,7 +500,9 @@ class ActivityManager implements IManager { * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique */ public function getCurrentUserId() { - if (!$this->session->isLoggedIn()) { + if ($this->currentUserId !== null) { + return $this->currentUserId; + } else if (!$this->session->isLoggedIn()) { return $this->getUserFromToken(); } else { return $this->session->getUser()->getUID(); diff --git a/lib/public/activity/imanager.php b/lib/public/activity/imanager.php index 0b97f8a07e..cbd0872241 100644 --- a/lib/public/activity/imanager.php +++ b/lib/public/activity/imanager.php @@ -204,6 +204,16 @@ interface IManager { */ public function getQueryForFilter($filter); + + /** + * Set the user we need to use + * + * @param string|null $currentUserId + * @throws \UnexpectedValueException If the user is invalid + * @since 9.0.1 + */ + public function setCurrentUserId($currentUserId); + /** * Get the user we need to use *