-
Notifications
You must be signed in to change notification settings - Fork 310
basic notify_push usage with session handling #3876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
fcfbcc6
basic notify_push usage with session handling (rebased)
alangecker fd6e15b
ensure activeSessions is an array
alangecker 7dc64de
dedicated Listener class, constants for events
alangecker 6bfb54e
use strict types in new php classes
alangecker 38aed97
better session handling
alangecker 567b9cc
use data() for constants instead of a computed property
alangecker dd307fa
use nextcloud's database type constants
alangecker cd7fb9a
increase session timeout
alangecker b3d4ac5
don't refresh closed sessions when tab is in the background
alangecker af13495
optimize sql queries / indexing
alangecker 0aede22
remove refreshData() leftover
alangecker 0272b2d
fix linter errors after rebase
alangecker ed125e9
avoid naming conflicts for indexes
alangecker 6684730
docs: sessions API documentation
alangecker c82a5a1
session list: minor visual improvements
alangecker 43a1b1a
sessions: integration tests
alangecker 2d465a7
fix acl test
alangecker a674b5b
fix php7 syntax error (unexpected '|')
alangecker 54b3900
Update lib/Service/SessionService.php
alangecker e1e29fe
Update lib/Controller/SessionController.php
alangecker 8007a06
Update lib/Controller/SessionController.php
alangecker b114520
update @nextcloud/notify_push to 1.1.3
alangecker d791949
stub OCA\NotifyPush\Queue\IQueue
alangecker 0ea384d
session cleanup via background job
alangecker 5386e6e
make psalm & linter happy
alangecker ccf7373
sessions: let's be an OCS API to support extenal clients
alangecker 6d86ec7
sessions: fix failing tests due to changed api endpoints
alangecker 541ee13
sessions: ignore self-emitted update events
alangecker f03521e
fix syntax error/mistake after rebase
alangecker e89cd98
fix broken requests in tests after switch to OCS
alangecker a466b76
use dependency injection for logger
alangecker a1d2e69
fix intentation mistake during rebase
alangecker d892979
chore(psalm): Fix annotations to make psalm happy
juliusknorr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2022, chandi Langecker (git@chandi.it) | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program 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 program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Deck\Controller; | ||
|
|
||
| use OCA\Deck\Service\SessionService; | ||
| use OCA\Deck\Service\PermissionService; | ||
| use OCA\Deck\Db\BoardMapper; | ||
| use OCP\AppFramework\Db\DoesNotExistException; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\AppFramework\OCSController; | ||
| use OCP\IRequest; | ||
| use OCA\Deck\Db\Acl; | ||
|
|
||
| class SessionController extends OCSController { | ||
| private SessionService $sessionService; | ||
| private PermissionService $permissionService; | ||
| private BoardMapper $boardMapper; | ||
|
|
||
| public function __construct($appName, | ||
| IRequest $request, | ||
| SessionService $sessionService, | ||
| PermissionService $permissionService, | ||
| BoardMapper $boardMapper | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| $this->sessionService = $sessionService; | ||
| $this->permissionService = $permissionService; | ||
| $this->boardMapper = $boardMapper; | ||
| } | ||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| */ | ||
| public function create(int $boardId): DataResponse { | ||
| $this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ); | ||
|
|
||
| $session = $this->sessionService->initSession($boardId); | ||
| return new DataResponse([ | ||
| 'token' => $session->getToken(), | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * notifies the server that the session is still active | ||
| * @NoAdminRequired | ||
| * @param $boardId | ||
| */ | ||
| public function sync(int $boardId, string $token): DataResponse { | ||
| $this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ); | ||
| try { | ||
| $this->sessionService->syncSession($boardId, $token); | ||
| return new DataResponse([]); | ||
| } catch (DoesNotExistException $e) { | ||
| return new DataResponse([], 404); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * delete a session if existing | ||
| * @NoAdminRequired | ||
| * @NoCSRFRequired | ||
| * @param $boardId | ||
| */ | ||
| public function close(int $boardId, string $token) { | ||
| $this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ); | ||
| $this->sessionService->closeSession($boardId, $token); | ||
| return new DataResponse(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2022, chandi Langecker (git@chandi.it) | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program 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 program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
|
|
||
|
|
||
| namespace OCA\Deck\Cron; | ||
|
|
||
| use OCA\Deck\Service\SessionService; | ||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\BackgroundJob\TimedJob; | ||
| use OCP\ILogger; | ||
|
|
||
| class SessionsCleanup extends TimedJob { | ||
| private $sessionService; | ||
| private $documentService; | ||
| private $logger; | ||
| private $imageService; | ||
|
|
||
|
|
||
| public function __construct(ITimeFactory $time, | ||
| SessionService $sessionService, | ||
| ILogger $logger) { | ||
| parent::__construct($time); | ||
| $this->sessionService = $sessionService; | ||
| $this->logger = $logger; | ||
| $this->setInterval(SessionService::SESSION_VALID_TIME); | ||
| } | ||
|
|
||
| protected function run($argument) { | ||
| $this->logger->debug('Run cleanup job for deck sessions'); | ||
|
|
||
| $removedSessions = $this->sessionService->removeInactiveSessions(); | ||
| $this->logger->debug('Removed ' . $removedSessions . ' inactive sessions'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2022, chandi Langecker (git@chandi.it) | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program 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 program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Deck\Db; | ||
|
|
||
| use OCP\AppFramework\Db\Entity; | ||
|
|
||
| class Session extends Entity implements \JsonSerializable { | ||
| public $id; | ||
| protected $userId; | ||
| protected $token; | ||
| protected $lastContact; | ||
| protected $boardId; | ||
|
|
||
| public function __construct() { | ||
| $this->addType('id', 'integer'); | ||
| $this->addType('boardId', 'integer'); | ||
| $this->addType('lastContact', 'integer'); | ||
| } | ||
|
|
||
| public function jsonSerialize(): array { | ||
| return [ | ||
| 'id' => $this->id, | ||
| 'userId' => $this->userId, | ||
| 'token' => $this->token, | ||
| 'lastContact' => $this->lastContact, | ||
| 'boardId' => $this->boardId, | ||
| ]; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.