summaryrefslogtreecommitdiffstats
path: root/apps/comments/lib/Controller/Notifications.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/comments/lib/Controller/Notifications.php')
-rw-r--r--apps/comments/lib/Controller/Notifications.php46
1 files changed, 29 insertions, 17 deletions
diff --git a/apps/comments/lib/Controller/Notifications.php b/apps/comments/lib/Controller/Notifications.php
index 911f19d46e1..3eeba4c8661 100644
--- a/apps/comments/lib/Controller/Notifications.php
+++ b/apps/comments/lib/Controller/Notifications.php
@@ -31,8 +31,10 @@ use OCP\AppFramework\Http\Response;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\IUser;
use OCP\IUserSession;
use OCP\Notification\IManager;
@@ -42,8 +44,8 @@ use OCP\Notification\IManager;
* @package OCA\Comments\Controller
*/
class Notifications extends Controller {
- /** @var Folder */
- protected $folder;
+ /** @var IRootFolder */
+ protected $rootFolder;
/** @var ICommentsManager */
protected $commentsManager;
@@ -63,7 +65,7 @@ class Notifications extends Controller {
* @param string $appName
* @param IRequest $request
* @param ICommentsManager $commentsManager
- * @param Folder $folder
+ * @param IRootFolder $rootFolder
* @param IURLGenerator $urlGenerator
* @param IManager $notificationManager
* @param IUserSession $userSession
@@ -72,35 +74,50 @@ class Notifications extends Controller {
$appName,
IRequest $request,
ICommentsManager $commentsManager,
- Folder $folder,
+ IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IManager $notificationManager,
IUserSession $userSession
) {
parent::__construct($appName, $request);
$this->commentsManager = $commentsManager;
- $this->folder = $folder;
+ $this->rootFolder = $rootFolder;
$this->urlGenerator = $urlGenerator;
$this->notificationManager = $notificationManager;
$this->userSession = $userSession;
}
/**
- * @NoAdminRequired
+ * @PublicPage
* @NoCSRFRequired
*
* @param string $id the comment ID
* @return Response
*/
public function view($id) {
+ $currentUser = $this->userSession->getUser();
+ if (!$currentUser instanceof IUser) {
+ return new RedirectResponse(
+ $this->urlGenerator->linkToRoute('core.login.showLoginForm', [
+ 'redirect_url' => $this->urlGenerator->linkToRoute(
+ 'comments.Notifications.view',
+ ['id' => $id]
+ ),
+ ])
+ );
+ }
+
try {
$comment = $this->commentsManager->get($id);
if($comment->getObjectType() !== 'files') {
return new NotFoundResponse();
}
- $files = $this->folder->getById((int)$comment->getObjectId());
- if(count($files) === 0) {
- $this->markProcessed($comment);
+ $userFolder = $this->rootFolder->getUserFolder($currentUser->getUID());
+ $files = $userFolder->getById((int)$comment->getObjectId());
+
+ $this->markProcessed($comment, $currentUser);
+
+ if (empty($files)) {
return new NotFoundResponse();
}
@@ -109,8 +126,6 @@ class Notifications extends Controller {
[ 'fileid' => $comment->getObjectId() ]
);
- $this->markProcessed($comment);
-
return new RedirectResponse($url);
} catch (\Exception $e) {
return new NotFoundResponse();
@@ -120,17 +135,14 @@ class Notifications extends Controller {
/**
* Marks the notification about a comment as processed
* @param IComment $comment
+ * @param IUser $currentUser
*/
- protected function markProcessed(IComment $comment) {
- $user = $this->userSession->getUser();
- if(is_null($user)) {
- return;
- }
+ protected function markProcessed(IComment $comment, IUser $currentUser) {
$notification = $this->notificationManager->createNotification();
$notification->setApp('comments')
->setObject('comment', $comment->getId())
->setSubject('mention')
- ->setUser($user->getUID());
+ ->setUser($currentUser->getUID());
$this->notificationManager->markProcessed($notification);
}
}