summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-12-16 22:30:19 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2020-12-17 10:35:23 +0100
commit11f5904dd58cbcb45e0e3e6c466f187e30323155 (patch)
tree17e7cd35948b161a0e567dec94bb9aecbe64d895
parent7bebaab86e2676466eb9d104ec1a57cd9634c0b4 (diff)
Fix mapper->find and empty user sessions
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
-rw-r--r--AUTHORS.md5
-rw-r--r--CHANGELOG.md8
-rw-r--r--lib/Controller/AdminController.php5
-rw-r--r--lib/Controller/ApiController.php19
-rw-r--r--lib/Controller/Controller.php20
-rw-r--r--lib/Controller/Exceptions/NotLoggedInException.php14
-rw-r--r--lib/Controller/ExportController.php5
-rw-r--r--lib/Controller/FeedApiController.php6
-rw-r--r--lib/Controller/FeedController.php5
-rw-r--r--lib/Controller/FolderApiController.php5
-rw-r--r--lib/Controller/FolderController.php5
-rw-r--r--lib/Controller/ItemApiController.php5
-rw-r--r--lib/Controller/ItemController.php5
-rw-r--r--lib/Controller/PageController.php5
-rw-r--r--lib/Controller/UserApiController.php5
-rw-r--r--lib/Controller/UtilityApiController.php5
-rw-r--r--lib/Service/Service.php6
-rw-r--r--tests/Unit/Controller/AdminControllerTest.php2
-rw-r--r--tests/Unit/Controller/ExportControllerTest.php1
-rw-r--r--tests/Unit/Controller/FeedApiControllerTest.php1
-rw-r--r--tests/Unit/Controller/FeedControllerTest.php1
-rw-r--r--tests/Unit/Controller/FolderApiControllerTest.php1
-rw-r--r--tests/Unit/Controller/FolderControllerTest.php1
-rw-r--r--tests/Unit/Controller/ItemApiControllerTest.php1
-rw-r--r--tests/Unit/Controller/ItemControllerTest.php1
-rw-r--r--tests/Unit/Controller/PageControllerTest.php1
-rw-r--r--tests/Unit/Controller/UserApiControllerTest.php3
-rw-r--r--tests/Unit/Controller/UtilityApiControllerTest.php1
-rw-r--r--tests/Unit/Service/FeedServiceTest.php38
-rw-r--r--tests/Unit/Service/ServiceTest.php8
30 files changed, 101 insertions, 87 deletions
diff --git a/AUTHORS.md b/AUTHORS.md
index cd988e2a8..171f443cf 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -9,8 +9,8 @@
* [Sean Molenaar](mailto:SMillerDev@users.noreply.github.com)
* [Jan-Christoph Borchardt](mailto:hey@jancborchardt.net)
* [Daniel Schaal](mailto:daniel@schaal.email)
-* [Davide Saurino](mailto:davide.saurino@alcacoop.it)
* [anoy](mailto:anoymouserver+github@mailbox.org)
+* [Davide Saurino](mailto:davide.saurino@alcacoop.it)
* [raghunayyar](mailto:me@iraghu.com)
* [bastei](mailto:bastei@users.noreply.github.com)
* [Bernhard Posselt](mailto:bep@foryouandyourcustomers.com)
@@ -95,6 +95,7 @@
* [Hanzei](mailto:Hanzei@users.noreply.github.com)
* [Hendrik Leppelsack](mailto:hendrik@leppelsack.de)
* [Jasper Knockaert](mailto:jasper@knockaert.nl)
+* [Kevin Decherf](mailto:kevin@kdecherf.com)
* [Maceček Richard](mailto:46937538+macecekrichard@users.noreply.github.com)
* [Marc Cousin](mailto:marc.cousin@people-doc.com)
* [Martin Ferretti](mailto:ferrettimartin@protonmail.com)
@@ -132,6 +133,7 @@
* [bjoerns1983](mailto:bjoern@sengotta.net)
* [blackcrack](mailto:blackcrack@blackysgate.de)
* [comradekingu](mailto:epost@anotheragency.no)
+* [derritter88](mailto:derritter88@users.noreply.github.com)
* [e-alfred](mailto:e-alfred@users.noreply.github.com)
* [fran-penedo](mailto:fran@franpenedo.com)
* [joeplus](mailto:joerg@honululu.Speedport_W_723V_1_32_000)
@@ -143,6 +145,7 @@
* [ritchiewilson](mailto:rawilson52@gmail.com)
* [sonologic](mailto:gmc@sonologic.nl)
* [tflidd](mailto:tflidd@aspekte.net)
+* [waffshappen](mailto:44290023+waffshappen@users.noreply.github.com)
* [wizdude](mailto:wizdude@users.noreply.github.com)
* [zero77](mailto:zero77@users.noreply.github.com)
* [Éloi Rivard](mailto:eloi.rivard@aquilenet.fr) \ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 565ba0069..b78ea20b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,12 +3,16 @@ All notable changes to this project will be documented in this file.
## Unreleased
+### Fixed
+- Fix #985
+- Fix #981
+
## 15.1.1-rc1
-## Changed
+### Changed
- Remove outdated folder DB code
-## Fixed
+### Fixed
- Export Unread/Starred Articles gives Error Message #963
- Some events don't appear in feed #921
diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php
index 059a0c4a7..8a0dfd99c 100644
--- a/lib/Controller/AdminController.php
+++ b/lib/Controller/AdminController.php
@@ -36,13 +36,12 @@ class AdminController extends Controller
/**
* AdminController constructor.
*
- * @param string $appName The name of the app
* @param IRequest $request The request
* @param IConfig $config Config for nextcloud
*/
- public function __construct(string $appName, IRequest $request, IConfig $config)
+ public function __construct(IRequest $request, IConfig $config)
{
- parent::__construct($appName, $request);
+ parent::__construct(Application::NAME, $request);
$this->config = $config;
}
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index de7a0919c..1ffa1272d 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -15,8 +15,10 @@
namespace OCA\News\Controller;
+use OCA\News\AppInfo\Application;
+use OCA\News\Controller\Exceptions\NotLoggedInException;
+use \OCP\IUser;
use \OCP\IRequest;
-use OCP\IUser;
use \OCP\IUserSession;
use \OCP\AppFramework\ApiController as BaseApiController;
@@ -28,7 +30,7 @@ use \OCP\AppFramework\ApiController as BaseApiController;
class ApiController extends BaseApiController
{
/**
- * @var IUserSession
+ * @var IUserSession|null
*/
private $userSession;
@@ -37,13 +39,12 @@ class ApiController extends BaseApiController
*
* Stores the user session to be able to leverage the user in further methods
*
- * @param string $appName The name of the app
- * @param IRequest $request The request
- * @param IUserSession $userSession The user session
+ * @param IRequest $request The request
+ * @param IUserSession|null $userSession The user session
*/
- public function __construct(string $appName, IRequest $request, IUserSession $userSession)
+ public function __construct(IRequest $request, ?IUserSession $userSession)
{
- parent::__construct($appName, $request);
+ parent::__construct(Application::NAME, $request);
$this->userSession = $userSession;
}
@@ -52,6 +53,10 @@ class ApiController extends BaseApiController
*/
protected function getUser()
{
+ if ($this->userSession === null) {
+ throw new NotLoggedInException();
+ }
+
return $this->userSession->getUser();
}
diff --git a/lib/Controller/Controller.php b/lib/Controller/Controller.php
index b2b86b007..726ee8e7d 100644
--- a/lib/Controller/Controller.php
+++ b/lib/Controller/Controller.php
@@ -13,9 +13,11 @@
namespace OCA\News\Controller;
+use OCA\News\AppInfo\Application;
+use OCA\News\Controller\Exceptions\NotLoggedInException;
use OCP\AppFramework\Controller as BaseController;
+use \OCP\IUser;
use \OCP\IRequest;
-use OCP\IUser;
use \OCP\IUserSession;
/**
@@ -26,7 +28,7 @@ use \OCP\IUserSession;
class Controller extends BaseController
{
/**
- * @var IUserSession
+ * @var IUserSession|null
*/
private $userSession;
@@ -35,13 +37,13 @@ class Controller extends BaseController
*
* Stores the user session to be able to leverage the user in further methods
*
- * @param string $appName The name of the app
- * @param IRequest $request The request
- * @param IUserSession $userSession The user session
+ * @param IRequest $request The request
+ * @param IUserSession|null $userSession The user session
*/
- public function __construct(string $appName, IRequest $request, IUserSession $userSession)
+ public function __construct(IRequest $request, ?IUserSession $userSession)
{
- parent::__construct($appName, $request);
+ parent::__construct(Application::NAME, $request);
+
$this->userSession = $userSession;
}
@@ -50,6 +52,10 @@ class Controller extends BaseController
*/
protected function getUser()
{
+ if ($this->userSession === null) {
+ throw new NotLoggedInException();
+ }
+
return $this->userSession->getUser();
}
diff --git a/lib/Controller/Exceptions/NotLoggedInException.php b/lib/Controller/Exceptions/NotLoggedInException.php
new file mode 100644
index 000000000..9bdf2475c
--- /dev/null
+++ b/lib/Controller/Exceptions/NotLoggedInException.php
@@ -0,0 +1,14 @@
+<?php
+
+
+namespace OCA\News\Controller\Exceptions;
+
+use Throwable;
+
+class NotLoggedInException extends \Exception
+{
+ public function __construct(?string $message = null)
+ {
+ parent::__construct($message ?? 'Unauthorized: User is not logged in!', 0, null);
+ }
+}
diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php
index 4bd4c667d..ad1975639 100644
--- a/lib/Controller/ExportController.php
+++ b/lib/Controller/ExportController.php
@@ -31,15 +31,14 @@ class ExportController extends Controller
private $itemService;
public function __construct(
- string $appName,
IRequest $request,
FolderServiceV2 $folderService,
FeedServiceV2 $feedService,
ItemServiceV2 $itemService,
OpmlService $opmlService,
- IUserSession $userSession
+ ?IUserSession $userSession
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->feedService = $feedService;
$this->folderService = $folderService;
$this->opmlService = $opmlService;
diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php
index 65181f8ac..eb6edcad2 100644
--- a/lib/Controller/FeedApiController.php
+++ b/lib/Controller/FeedApiController.php
@@ -16,6 +16,7 @@
namespace OCA\News\Controller;
use Exception;
+use OCA\News\AppInfo\Application;
use OCA\News\Service\Exceptions\ServiceConflictException;
use OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCA\News\Service\FeedServiceV2;
@@ -61,15 +62,14 @@ class FeedApiController extends ApiController
private $serializer;
public function __construct(
- string $appName,
IRequest $request,
- IUserSession $userSession,
+ ?IUserSession $userSession,
FeedService $oldFeedService,
FeedServiceV2 $feedService,
ItemService $oldItemService,
LoggerInterface $logger
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->feedService = $feedService;
$this->oldFeedService = $oldFeedService;
$this->oldItemService = $oldItemService;
diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php
index 5881d7eb9..5abcd3393 100644
--- a/lib/Controller/FeedController.php
+++ b/lib/Controller/FeedController.php
@@ -44,15 +44,14 @@ class FeedController extends Controller
private $settings;
public function __construct(
- string $appName,
IRequest $request,
FolderServiceV2 $folderService,
FeedService $feedService,
ItemService $itemService,
IConfig $settings,
- IUserSession $userSession
+ ?IUserSession $userSession
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->folderService = $folderService;
$this->feedService = $feedService;
$this->itemService = $itemService;
diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php
index 7f7f97525..8de4b9e69 100644
--- a/lib/Controller/FolderApiController.php
+++ b/lib/Controller/FolderApiController.php
@@ -35,13 +35,12 @@ class FolderApiController extends ApiController
private $itemService;
public function __construct(
- string $appName,
IRequest $request,
- IUserSession $userSession,
+ ?IUserSession $userSession,
FolderServiceV2 $folderService,
ItemService $itemService
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->folderService = $folderService;
$this->itemService = $itemService;
diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php
index c12c7042f..b33f46c54 100644
--- a/lib/Controller/FolderController.php
+++ b/lib/Controller/FolderController.php
@@ -39,14 +39,13 @@ class FolderController extends Controller
private $itemService;
public function __construct(
- string $appName,
IRequest $request,
FolderServiceV2 $folderService,
FeedService $feedService,
ItemService $itemService,
- IUserSession $userSession
+ ?IUserSession $userSession
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->folderService = $folderService;
$this->feedService = $feedService;
$this->itemService = $itemService;
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index 3e31d2fdd..442734127 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -32,13 +32,12 @@ class ItemApiController extends ApiController
private $itemService;
public function __construct(
- string $appName,
IRequest $request,
- IUserSession $userSession,
+ ?IUserSession $userSession,
ItemService $oldItemService,
ItemServiceV2 $itemService
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->oldItemService = $oldItemService;
$this->itemService = $itemService;
diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php
index be4f707c9..7506891d4 100644
--- a/lib/Controller/ItemController.php
+++ b/lib/Controller/ItemController.php
@@ -32,14 +32,13 @@ class ItemController extends Controller
private $settings;
public function __construct(
- $appName,
IRequest $request,
FeedService $feedService,
ItemService $itemService,
IConfig $settings,
- IUserSession $userSession
+ ?IUserSession $userSession
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->itemService = $itemService;
$this->feedService = $feedService;
$this->settings = $settings;
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 8e55e69ee..4b39ba9c2 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -58,16 +58,15 @@ class PageController extends Controller
private $statusService;
public function __construct(
- string $appName,
IRequest $request,
IConfig $settings,
IURLGenerator $urlGenerator,
IL10N $l10n,
RecommendedSites $recommendedSites,
StatusService $statusService,
- IUserSession $userSession
+ ?IUserSession $userSession
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->settings = $settings;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
diff --git a/lib/Controller/UserApiController.php b/lib/Controller/UserApiController.php
index f5137992d..42f5607fe 100644
--- a/lib/Controller/UserApiController.php
+++ b/lib/Controller/UserApiController.php
@@ -24,11 +24,10 @@ use \OCP\AppFramework\Http;
class UserApiController extends ApiController
{
public function __construct(
- string $appName,
IRequest $request,
- IUserSession $userSession
+ ?IUserSession $userSession
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
}
/**
diff --git a/lib/Controller/UtilityApiController.php b/lib/Controller/UtilityApiController.php
index a2e5ae910..943aa7b15 100644
--- a/lib/Controller/UtilityApiController.php
+++ b/lib/Controller/UtilityApiController.php
@@ -30,14 +30,13 @@ class UtilityApiController extends ApiController
private $statusService;
public function __construct(
- string $appName,
IRequest $request,
- IUserSession $userSession,
+ ?IUserSession $userSession,
UpdaterService $updater,
IConfig $settings,
StatusService $statusService
) {
- parent::__construct($appName, $request, $userSession);
+ parent::__construct($request, $userSession);
$this->updaterService = $updater;
$this->settings = $settings;
$this->statusService = $statusService;
diff --git a/lib/Service/Service.php b/lib/Service/Service.php
index 970613830..597a99647 100644
--- a/lib/Service/Service.php
+++ b/lib/Service/Service.php
@@ -40,8 +40,8 @@ abstract class Service
/**
* Service constructor.
*
- * @param NewsMapperV2 $mapper
- * @param LoggerInterface $logger
+ * @param NewsMapperV2 $mapper
+ * @param LoggerInterface $logger
*/
public function __construct($mapper, LoggerInterface $logger)
{
@@ -97,7 +97,7 @@ abstract class Service
public function find(string $userId, int $id): Entity
{
try {
- return $this->mapper->find($userId, $id);
+ return $this->mapper->findFromUser($userId, $id);
} catch (DoesNotExistException $ex) {
throw new ServiceNotFoundException($ex->getMessage());
} catc