Skip to content
Merged
Show file tree
Hide file tree
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 Aug 4, 2022
fd6e15b
ensure activeSessions is an array
alangecker Aug 4, 2022
7dc64de
dedicated Listener class, constants for events
alangecker Aug 4, 2022
6bfb54e
use strict types in new php classes
alangecker Sep 5, 2022
38aed97
better session handling
alangecker Sep 5, 2022
567b9cc
use data() for constants instead of a computed property
alangecker Sep 5, 2022
dd307fa
use nextcloud's database type constants
alangecker Sep 5, 2022
cd7fb9a
increase session timeout
alangecker Sep 5, 2022
b3d4ac5
don't refresh closed sessions when tab is in the background
alangecker Sep 5, 2022
af13495
optimize sql queries / indexing
alangecker Sep 5, 2022
0aede22
remove refreshData() leftover
alangecker Sep 5, 2022
0272b2d
fix linter errors after rebase
alangecker Sep 26, 2022
ed125e9
avoid naming conflicts for indexes
alangecker Sep 26, 2022
6684730
docs: sessions API documentation
alangecker Sep 26, 2022
c82a5a1
session list: minor visual improvements
alangecker Sep 26, 2022
43a1b1a
sessions: integration tests
alangecker Oct 6, 2022
2d465a7
fix acl test
alangecker Oct 6, 2022
a674b5b
fix php7 syntax error (unexpected '|')
alangecker Oct 6, 2022
54b3900
Update lib/Service/SessionService.php
alangecker Nov 4, 2022
e1e29fe
Update lib/Controller/SessionController.php
alangecker Nov 4, 2022
8007a06
Update lib/Controller/SessionController.php
alangecker Nov 4, 2022
b114520
update @nextcloud/notify_push to 1.1.3
alangecker Nov 4, 2022
d791949
stub OCA\NotifyPush\Queue\IQueue
alangecker Nov 8, 2022
0ea384d
session cleanup via background job
alangecker Nov 10, 2022
5386e6e
make psalm & linter happy
alangecker Nov 11, 2022
ccf7373
sessions: let's be an OCS API to support extenal clients
alangecker Nov 12, 2022
6d86ec7
sessions: fix failing tests due to changed api endpoints
alangecker Nov 13, 2022
541ee13
sessions: ignore self-emitted update events
alangecker Nov 21, 2022
f03521e
fix syntax error/mistake after rebase
alangecker Nov 21, 2022
e89cd98
fix broken requests in tests after switch to OCS
alangecker Nov 22, 2022
a466b76
use dependency injection for logger
alangecker Dec 6, 2022
a1d2e69
fix intentation mistake during rebase
alangecker Jan 3, 2023
d892979
chore(psalm): Fix annotations to make psalm happy
juliusknorr Jan 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<job>OCA\Deck\Cron\DeleteCron</job>
<job>OCA\Deck\Cron\ScheduledNotifications</job>
<job>OCA\Deck\Cron\CardDescriptionActivity</job>
<job>OCA\Deck\Cron\SessionsCleanup</job>
</background-jobs>
<repair-steps>
<live-migration>
Expand Down
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,10 @@
['name' => 'overview_api#upcomingCards', 'url' => '/api/v{apiVersion}/overview/upcoming', 'verb' => 'GET'],

['name' => 'search#search', 'url' => '/api/v{apiVersion}/search', 'verb' => 'GET'],

// sessions
['name' => 'Session#create', 'url' => '/api/v{apiVersion}/session/create', 'verb' => 'PUT'],
['name' => 'Session#sync', 'url' => '/api/v{apiVersion}/session/sync', 'verb' => 'POST'],
['name' => 'Session#close', 'url' => '/api/v{apiVersion}/session/close', 'verb' => 'POST'],
]
];
107 changes: 107 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1394,3 +1394,110 @@ A bad request response is returned if invalid input values are provided. The res
A not found response might be returned if:
- The card for the given cardId could not be found
- The comment could not be found


## Sessions

### PUT /session/create - creates a new session

#### Request parameters

| Parameter | Type | Description |
| --------- | ------- | ---------------------------------------------------- |
| boardId | Integer | The id of the opened board |

```
curl -X PUT 'https://admin:admin@nextcloud/ocs/v2.php/apps/deck/api/v1.0/session/create' \
-H 'Accept: application/json' -H 'OCS-APIRequest: true' \
-H 'Content-Type: application/json;charset=utf-8' \
--data '{"boardId":1}'
```

#### Response

##### 200 Success

```json
{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": {
"token": "+zcJHf4rC6dobVSbuNa3delkCSfTW8OvYWTyLFvSpIv80FjtgLIj0ARlxspsazNQ"
}
}
}
```


### POST /session/sync - notifies the server, that the session is still open

#### Request body

| Parameter | Type | Description |
| --------- | ------- | ---------------------------------------------------- |
| boardId | Integer | The id of the opened board |
| token | String | The session token from the /sessions/create response |


```
curl -X POST 'https://admin:admin@nextcloud/ocs/v2.php/apps/deck/api/v1.0/session/create' \
-H 'Accept: application/json' -H 'OCS-APIRequest: true' \
-H 'Content-Type: application/json;charset=utf-8' \
--data '{"boardId":1, "token":"X3DyyoFslArF0t0NBZXzZXzcy8feoX/OEytSNXZtPg9TpUgO5wrkJ38IW3T/FfpV"}'
```

#### Response

##### 200 Success
```json
{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": []
}
}
```

##### 404 Not Found
the provided token is invalid or expired


### POST /session/close - closes the session

#### Request body

| Parameter | Type | Description |
| --------- | ------- | ---------------------------------------------------- |
| boardId | Integer | The id of the opened board |
| token | String | The session token from the /sessions/create response |

```
curl -X POST 'https://admin:admin@nextcloud/ocs/v2.php/apps/deck/api/v1.0/session/close' \
-H 'Accept: application/json' -H 'OCS-APIRequest: true' \
-H 'Content-Type: application/json;charset=utf-8' \
--data '{"boardId":1, "token":"X3DyyoFslArF0t0NBZXzZXzcy8feoX/OEytSNXZtPg9TpUgO5wrkJ38IW3T/FfpV"}'
```

#### Response

##### 200 Success
```json
{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": []
}
}
```
7 changes: 7 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
use OCA\Deck\Event\CardCreatedEvent;
use OCA\Deck\Event\CardDeletedEvent;
use OCA\Deck\Event\CardUpdatedEvent;
use OCA\Deck\Event\SessionClosedEvent;
use OCA\Deck\Event\SessionCreatedEvent;
use OCA\Deck\Listeners\BeforeTemplateRenderedListener;
use OCA\Deck\Listeners\ParticipantCleanupListener;
use OCA\Deck\Listeners\FullTextSearchEventListener;
use OCA\Deck\Listeners\ResourceListener;
use OCA\Deck\Listeners\LiveUpdateListener;
use OCA\Deck\Middleware\DefaultBoardMiddleware;
use OCA\Deck\Middleware\ExceptionMiddleware;
use OCA\Deck\Notification\Notifier;
Expand Down Expand Up @@ -147,6 +150,10 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(UserDeletedEvent::class, ParticipantCleanupListener::class);
$context->registerEventListener(GroupDeletedEvent::class, ParticipantCleanupListener::class);
$context->registerEventListener(CircleDestroyedEvent::class, ParticipantCleanupListener::class);

// Event listening for realtime updates via notify_push
$context->registerEventListener(SessionCreatedEvent::class, LiveUpdateListener::class);
$context->registerEventListener(SessionClosedEvent::class, LiveUpdateListener::class);
}

public function registerNotifications(NotificationManager $notificationManager): void {
Expand Down
91 changes: 91 additions & 0 deletions lib/Controller/SessionController.php
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();
}
}
56 changes: 56 additions & 0 deletions lib/Cron/SessionsCleanup.php
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');
}
}
2 changes: 2 additions & 0 deletions lib/Db/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Board extends RelationalEntity {
protected $users = [];
protected $shared;
protected $stacks = [];
protected $activeSessions = [];
protected $deletedAt = 0;
protected $lastModified = 0;

Expand All @@ -59,6 +60,7 @@ public function __construct() {
$this->addRelation('acl');
$this->addRelation('shared');
$this->addRelation('users');
$this->addRelation('activeSessions');
$this->addRelation('permissions');
$this->addRelation('stacks');
$this->addRelation('settings');
Expand Down
51 changes: 51 additions & 0 deletions lib/Db/Session.php
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,
];
}
}
Loading