Skip to content

Commit 2c988e6

Browse files
committed
feat(dav): add out-of-office ocs api to get current data
Signed-off-by: Richard Steinmetz <[email protected]>
1 parent 2b11106 commit 2c988e6

6 files changed

Lines changed: 226 additions & 0 deletions

File tree

apps/dav/appinfo/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* @author Georg Ehrke <[email protected]>
66
* @author Roeland Jago Douma <[email protected]>
7+
* @author Richard Steinmetz <[email protected]>
78
*
89
* @license GNU AGPL version 3 or any later version
910
*
@@ -32,5 +33,6 @@
3233
],
3334
'ocs' => [
3435
['name' => 'direct#getUrl', 'url' => '/api/v1/direct', 'verb' => 'POST'],
36+
['name' => 'out_of_office#getCurrentOutOfOfficeData', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'GET'],
3537
],
3638
];

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
'OCA\\DAV\\Controller\\BirthdayCalendarController' => $baseDir . '/../lib/Controller/BirthdayCalendarController.php',
192192
'OCA\\DAV\\Controller\\DirectController' => $baseDir . '/../lib/Controller/DirectController.php',
193193
'OCA\\DAV\\Controller\\InvitationResponseController' => $baseDir . '/../lib/Controller/InvitationResponseController.php',
194+
'OCA\\DAV\\Controller\\OutOfOfficeController' => $baseDir . '/../lib/Controller/OutOfOfficeController.php',
194195
'OCA\\DAV\\DAV\\CustomPropertiesBackend' => $baseDir . '/../lib/DAV/CustomPropertiesBackend.php',
195196
'OCA\\DAV\\DAV\\GroupPrincipalBackend' => $baseDir . '/../lib/DAV/GroupPrincipalBackend.php',
196197
'OCA\\DAV\\DAV\\PublicAuth' => $baseDir . '/../lib/DAV/PublicAuth.php',
@@ -304,6 +305,7 @@
304305
'OCA\\DAV\\Profiler\\ProfilerPlugin' => $baseDir . '/../lib/Profiler/ProfilerPlugin.php',
305306
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
306307
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
308+
'OCA\\DAV\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
307309
'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php',
308310
'OCA\\DAV\\Search\\ACalendarSearchProvider' => $baseDir . '/../lib/Search/ACalendarSearchProvider.php',
309311
'OCA\\DAV\\Search\\ContactsSearchProvider' => $baseDir . '/../lib/Search/ContactsSearchProvider.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class ComposerStaticInitDAV
206206
'OCA\\DAV\\Controller\\BirthdayCalendarController' => __DIR__ . '/..' . '/../lib/Controller/BirthdayCalendarController.php',
207207
'OCA\\DAV\\Controller\\DirectController' => __DIR__ . '/..' . '/../lib/Controller/DirectController.php',
208208
'OCA\\DAV\\Controller\\InvitationResponseController' => __DIR__ . '/..' . '/../lib/Controller/InvitationResponseController.php',
209+
'OCA\\DAV\\Controller\\OutOfOfficeController' => __DIR__ . '/..' . '/../lib/Controller/OutOfOfficeController.php',
209210
'OCA\\DAV\\DAV\\CustomPropertiesBackend' => __DIR__ . '/..' . '/../lib/DAV/CustomPropertiesBackend.php',
210211
'OCA\\DAV\\DAV\\GroupPrincipalBackend' => __DIR__ . '/..' . '/../lib/DAV/GroupPrincipalBackend.php',
211212
'OCA\\DAV\\DAV\\PublicAuth' => __DIR__ . '/..' . '/../lib/DAV/PublicAuth.php',
@@ -319,6 +320,7 @@ class ComposerStaticInitDAV
319320
'OCA\\DAV\\Profiler\\ProfilerPlugin' => __DIR__ . '/..' . '/../lib/Profiler/ProfilerPlugin.php',
320321
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
321322
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
323+
'OCA\\DAV\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
322324
'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php',
323325
'OCA\\DAV\\Search\\ACalendarSearchProvider' => __DIR__ . '/..' . '/../lib/Search/ACalendarSearchProvider.php',
324326
'OCA\\DAV\\Search\\ContactsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/ContactsSearchProvider.php',
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Richard Steinmetz <[email protected]>
7+
*
8+
* @author Richard Steinmetz <[email protected]>
9+
*
10+
* @license AGPL-3.0-or-later
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV\Controller;
28+
29+
use OCA\DAV\Db\AbsenceMapper;
30+
use OCA\DAV\ResponseDefinitions;
31+
use OCP\AppFramework\Db\DoesNotExistException;
32+
use OCP\AppFramework\Http;
33+
use OCP\AppFramework\Http\DataResponse;
34+
use OCP\AppFramework\OCSController;
35+
use OCP\IRequest;
36+
37+
/**
38+
* @psalm-import-type DavOutOfOfficeData from ResponseDefinitions
39+
*/
40+
class OutOfOfficeController extends OCSController {
41+
42+
public function __construct(
43+
string $appName,
44+
IRequest $request,
45+
private AbsenceMapper $absenceMapper,
46+
) {
47+
parent::__construct($appName, $request);
48+
}
49+
50+
/**
51+
* Get the currently configured out-of-office data of a user.
52+
*
53+
* @NoAdminRequired
54+
* @NoCSRFRequired
55+
*
56+
* @param string $userId The user id to get out-of-office data for.
57+
* @return DataResponse<Http::STATUS_OK, ?DavOutOfOfficeData, array{}>
58+
*
59+
* 200: Out-of-office data
60+
* 404: No out-of-office data was found
61+
*/
62+
public function getCurrentOutOfOfficeData(string $userId): DataResponse {
63+
try {
64+
$data = $this->absenceMapper->findByUserId($userId);
65+
} catch (DoesNotExistException) {
66+
return new DataResponse(null, Http::STATUS_NOT_FOUND);
67+
}
68+
69+
return new DataResponse([
70+
'id' => $data->getId(),
71+
'firstDay' => $data->getFirstDay(),
72+
'lastDay' => $data->getLastDay(),
73+
'status' => $data->getStatus(),
74+
'message' => $data->getMessage(),
75+
]);
76+
}
77+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Richard Steinmetz <[email protected]>
7+
*
8+
* @author Richard Steinmetz <[email protected]>
9+
*
10+
* @license AGPL-3.0-or-later
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV;
28+
29+
/**
30+
* @psalm-type DavOutOfOfficeData = array{
31+
* id: int,
32+
* userId: string,
33+
* firstDay: string,
34+
* lastDay: string,
35+
* status: string,
36+
* message: string,
37+
* }
38+
*/
39+
class ResponseDefinitions {
40+
}

apps/dav/openapi.json

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@
6565
"type": "string"
6666
}
6767
}
68+
},
69+
"OutOfOfficeData": {
70+
"type": "object",
71+
"required": [
72+
"id",
73+
"userId",
74+
"firstDay",
75+
"lastDay",
76+
"status",
77+
"message"
78+
],
79+
"properties": {
80+
"id": {
81+
"type": "integer",
82+
"format": "int64"
83+
},
84+
"userId": {
85+
"type": "string"
86+
},
87+
"firstDay": {
88+
"type": "string"
89+
},
90+
"lastDay": {
91+
"type": "string"
92+
},
93+
"status": {
94+
"type": "string"
95+
},
96+
"message": {
97+
"type": "string"
98+
}
99+
}
68100
}
69101
}
70102
},
@@ -186,6 +218,77 @@
186218
}
187219
}
188220
}
221+
},
222+
"/ocs/v2.php/apps/dav/api/v1/outOfOffice/{userId}": {
223+
"get": {
224+
"operationId": "out_of_office-get-current-out-of-office-data",
225+
"summary": "Get the currently configured out-of-office data of a user.",
226+
"tags": [
227+
"out_of_office"
228+
],
229+
"security": [
230+
{
231+
"bearer_auth": []
232+
},
233+
{
234+
"basic_auth": []
235+
}
236+
],
237+
"parameters": [
238+
{
239+
"name": "userId",
240+
"in": "path",
241+
"description": "The user id to get out-of-office data for.",
242+
"required": true,
243+
"schema": {
244+
"type": "string"
245+
}
246+
},
247+
{
248+
"name": "OCS-APIRequest",
249+
"in": "header",
250+
"description": "Required to be true for the API request to pass",
251+
"required": true,
252+
"schema": {
253+
"type": "boolean",
254+
"default": true
255+
}
256+
}
257+
],
258+
"responses": {
259+
"200": {
260+
"description": "Out-of-office data",
261+
"content": {
262+
"application/json": {
263+
"schema": {
264+
"type": "object",
265+
"required": [
266+
"ocs"
267+
],
268+
"properties": {
269+
"ocs": {
270+
"type": "object",
271+
"required": [
272+
"meta",
273+
"data"
274+
],
275+
"properties": {
276+
"meta": {
277+
"$ref": "#/components/schemas/OCSMeta"
278+
},
279+
"data": {
280+
"$ref": "#/components/schemas/OutOfOfficeData",
281+
"nullable": true
282+
}
283+
}
284+
}
285+
}
286+
}
287+
}
288+
}
289+
}
290+
}
291+
}
189292
}
190293
},
191294
"tags": []

0 commit comments

Comments
 (0)