sessions: let's be an OCS API to support extenal clients
Signed-off-by: chandi Langecker <git@chandi.it>
This commit is contained in:
@@ -82,11 +82,6 @@ return [
|
||||
['name' => 'label#update', 'url' => '/labels/{labelId}', 'verb' => 'PUT'],
|
||||
['name' => 'label#delete', 'url' => '/labels/{labelId}', 'verb' => 'DELETE'],
|
||||
|
||||
// sessions
|
||||
['name' => 'Session#create', 'url' => '/session/create', 'verb' => 'PUT'],
|
||||
['name' => 'Session#sync', 'url' => '/session/sync', 'verb' => 'POST'],
|
||||
['name' => 'Session#close', 'url' => '/session/close', 'verb' => 'POST'],
|
||||
|
||||
// api
|
||||
['name' => 'board_api#index', 'url' => '/api/v{apiVersion}/boards', 'verb' => 'GET'],
|
||||
['name' => 'board_api#get', 'url' => '/api/v{apiVersion}/boards/{boardId}', 'verb' => 'GET'],
|
||||
@@ -155,5 +150,10 @@ return [
|
||||
['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'],
|
||||
]
|
||||
];
|
||||
|
||||
182
docs/API.md
182
docs/API.md
@@ -1049,81 +1049,6 @@ Make a request to see the json schema of system
|
||||
|
||||
##### 200 Success
|
||||
|
||||
## Sessions
|
||||
|
||||
### PUT /sessions/create - creates a new session
|
||||
|
||||
#### Request body
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------- | ---------------------------------------------------- |
|
||||
| boardId | Integer | The id of the opened board |
|
||||
|
||||
```json
|
||||
{
|
||||
"boardId": 123
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Response
|
||||
|
||||
##### 200 Success
|
||||
|
||||
```json
|
||||
{
|
||||
"token":"LCGVgzFZBTMXPfcSVuWmrqLR0j8ZG5o1PpVLeHgTHZ5+4jOJNxlzUZ6ZfPbTTpqB"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### POST /sessions/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 |
|
||||
|
||||
```json
|
||||
{
|
||||
"boardId": 123,
|
||||
"token":"LCGVgzFZBTMXPfcSVuWmrqLR0j8ZG5o1PpVLeHgTHZ5+4jOJNxlzUZ6ZfPbTTpqB"
|
||||
}
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
##### 200 Success
|
||||
(empty response)
|
||||
|
||||
##### 404 Not Found
|
||||
the provided token is invalid or expired
|
||||
|
||||
|
||||
### POST /sessions/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 |
|
||||
|
||||
```json
|
||||
{
|
||||
"boardId": 123,
|
||||
"token":"LCGVgzFZBTMXPfcSVuWmrqLR0j8ZG5o1PpVLeHgTHZ5+4jOJNxlzUZ6ZfPbTTpqB"
|
||||
}
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
##### 200 Success
|
||||
(empty response)
|
||||
|
||||
|
||||
# OCS API
|
||||
|
||||
The following endpoints are available through the Nextcloud OCS endpoint, which is available at `/ocs/v2.php/apps/deck/api/v1.0/`.
|
||||
@@ -1469,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": []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -29,11 +29,11 @@ use OCA\Deck\Service\PermissionService;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\IRequest;
|
||||
use OCA\Deck\Db\Acl;
|
||||
|
||||
class SessionController extends ApiController {
|
||||
class SessionController extends OCSController {
|
||||
private SessionService $sessionService;
|
||||
private PermissionService $permissionService;
|
||||
private BoardMapper $boardMapper;
|
||||
@@ -82,11 +82,10 @@ class SessionController extends ApiController {
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @param $boardId
|
||||
* @return bool
|
||||
*/
|
||||
public function close(int $boardId, string $token) {
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
$this->sessionService->closeSession($boardId, $token);
|
||||
return true;
|
||||
return new DataResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,16 @@
|
||||
*/
|
||||
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import { generateOcsUrl } from '@nextcloud/router'
|
||||
|
||||
export class SessionApi {
|
||||
|
||||
url(url) {
|
||||
url = `/apps/deck${url}`
|
||||
return generateUrl(url)
|
||||
return generateOcsUrl(`apps/deck/api/v1.0${url}`)
|
||||
}
|
||||
|
||||
async createSession(boardId) {
|
||||
return (await axios.put(this.url('/session/create'), { boardId })).data
|
||||
return (await axios.put(this.url('/session/create'), { boardId })).data.ocs.data
|
||||
}
|
||||
|
||||
async syncSession(boardId, token) {
|
||||
|
||||
Reference in New Issue
Block a user