Skip to content

Commit 2a1094f

Browse files
committed
feat(dav): implement personal absence settings
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent 356c221 commit 2a1094f

File tree

207 files changed

+6834
-876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+6834
-876
lines changed

apps/dav/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>WebDAV</name>
66
<summary>WebDAV endpoint</summary>
77
<description>WebDAV endpoint</description>
8-
<version>1.28.0</version>
8+
<version>1.29.0</version>
99
<licence>agpl</licence>
1010
<author>owncloud.org</author>
1111
<namespace>DAV</namespace>

apps/dav/appinfo/routes.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* @author Georg Ehrke <oc.list@georgehrke.com>
66
* @author Roeland Jago Douma <roeland@famdouma.nl>
7+
* @author Richard Steinmetz <richard@steinmetz.cloud>
78
*
89
* @license GNU AGPL version 3 or any later version
910
*
@@ -28,7 +29,9 @@
2829
['name' => 'invitation_response#accept', 'url' => '/invitation/accept/{token}', 'verb' => 'GET'],
2930
['name' => 'invitation_response#decline', 'url' => '/invitation/decline/{token}', 'verb' => 'GET'],
3031
['name' => 'invitation_response#options', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'GET'],
31-
['name' => 'invitation_response#processMoreOptionsResult', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'POST']
32+
['name' => 'invitation_response#processMoreOptionsResult', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'POST'],
33+
['name' => 'availability_settings#updateAbsence', 'url' => '/settings/absence', 'verb' => 'POST'],
34+
['name' => 'availability_settings#clearAbsence', 'url' => '/settings/absence', 'verb' => 'DELETE'],
3235
],
3336
'ocs' => [
3437
['name' => 'direct#getUrl', 'url' => '/api/v1/direct', 'verb' => 'POST'],

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
'OCA\\DAV\\Connector\\Sabre\\SharesPlugin' => $baseDir . '/../lib/Connector/Sabre/SharesPlugin.php',
189189
'OCA\\DAV\\Connector\\Sabre\\TagList' => $baseDir . '/../lib/Connector/Sabre/TagList.php',
190190
'OCA\\DAV\\Connector\\Sabre\\TagsPlugin' => $baseDir . '/../lib/Connector/Sabre/TagsPlugin.php',
191+
'OCA\\DAV\\Controller\\AvailabilitySettingsController' => $baseDir . '/../lib/Controller/AvailabilitySettingsController.php',
191192
'OCA\\DAV\\Controller\\BirthdayCalendarController' => $baseDir . '/../lib/Controller/BirthdayCalendarController.php',
192193
'OCA\\DAV\\Controller\\DirectController' => $baseDir . '/../lib/Controller/DirectController.php',
193194
'OCA\\DAV\\Controller\\InvitationResponseController' => $baseDir . '/../lib/Controller/InvitationResponseController.php',
@@ -201,6 +202,8 @@
201202
'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest' => $baseDir . '/../lib/DAV/Sharing/Xml/ShareRequest.php',
202203
'OCA\\DAV\\DAV\\SystemPrincipalBackend' => $baseDir . '/../lib/DAV/SystemPrincipalBackend.php',
203204
'OCA\\DAV\\DAV\\ViewOnlyPlugin' => $baseDir . '/../lib/DAV/ViewOnlyPlugin.php',
205+
'OCA\\DAV\\Db\\Absence' => $baseDir . '/../lib/Db/Absence.php',
206+
'OCA\\DAV\\Db\\AbsenceMapper' => $baseDir . '/../lib/Db/AbsenceMapper.php',
204207
'OCA\\DAV\\Db\\Direct' => $baseDir . '/../lib/Db/Direct.php',
205208
'OCA\\DAV\\Db\\DirectMapper' => $baseDir . '/../lib/Db/DirectMapper.php',
206209
'OCA\\DAV\\Direct\\DirectFile' => $baseDir . '/../lib/Direct/DirectFile.php',
@@ -297,6 +300,7 @@
297300
'OCA\\DAV\\Migration\\Version1018Date20210312100735' => $baseDir . '/../lib/Migration/Version1018Date20210312100735.php',
298301
'OCA\\DAV\\Migration\\Version1024Date20211221144219' => $baseDir . '/../lib/Migration/Version1024Date20211221144219.php',
299302
'OCA\\DAV\\Migration\\Version1027Date20230504122946' => $baseDir . '/../lib/Migration/Version1027Date20230504122946.php',
303+
'OCA\\DAV\\Migration\\Version1029Date20231004091403' => $baseDir . '/../lib/Migration/Version1029Date20231004091403.php',
300304
'OCA\\DAV\\Profiler\\ProfilerPlugin' => $baseDir . '/../lib/Profiler/ProfilerPlugin.php',
301305
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
302306
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
@@ -306,6 +310,7 @@
306310
'OCA\\DAV\\Search\\EventsSearchProvider' => $baseDir . '/../lib/Search/EventsSearchProvider.php',
307311
'OCA\\DAV\\Search\\TasksSearchProvider' => $baseDir . '/../lib/Search/TasksSearchProvider.php',
308312
'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php',
313+
'OCA\\DAV\\Service\\AbsenceService' => $baseDir . '/../lib/Service/AbsenceService.php',
309314
'OCA\\DAV\\Settings\\AvailabilitySettings' => $baseDir . '/../lib/Settings/AvailabilitySettings.php',
310315
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
311316
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class ComposerStaticInitDAV
203203
'OCA\\DAV\\Connector\\Sabre\\SharesPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/SharesPlugin.php',
204204
'OCA\\DAV\\Connector\\Sabre\\TagList' => __DIR__ . '/..' . '/../lib/Connector/Sabre/TagList.php',
205205
'OCA\\DAV\\Connector\\Sabre\\TagsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/TagsPlugin.php',
206+
'OCA\\DAV\\Controller\\AvailabilitySettingsController' => __DIR__ . '/..' . '/../lib/Controller/AvailabilitySettingsController.php',
206207
'OCA\\DAV\\Controller\\BirthdayCalendarController' => __DIR__ . '/..' . '/../lib/Controller/BirthdayCalendarController.php',
207208
'OCA\\DAV\\Controller\\DirectController' => __DIR__ . '/..' . '/../lib/Controller/DirectController.php',
208209
'OCA\\DAV\\Controller\\InvitationResponseController' => __DIR__ . '/..' . '/../lib/Controller/InvitationResponseController.php',
@@ -216,6 +217,8 @@ class ComposerStaticInitDAV
216217
'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest' => __DIR__ . '/..' . '/../lib/DAV/Sharing/Xml/ShareRequest.php',
217218
'OCA\\DAV\\DAV\\SystemPrincipalBackend' => __DIR__ . '/..' . '/../lib/DAV/SystemPrincipalBackend.php',
218219
'OCA\\DAV\\DAV\\ViewOnlyPlugin' => __DIR__ . '/..' . '/../lib/DAV/ViewOnlyPlugin.php',
220+
'OCA\\DAV\\Db\\Absence' => __DIR__ . '/..' . '/../lib/Db/Absence.php',
221+
'OCA\\DAV\\Db\\AbsenceMapper' => __DIR__ . '/..' . '/../lib/Db/AbsenceMapper.php',
219222
'OCA\\DAV\\Db\\Direct' => __DIR__ . '/..' . '/../lib/Db/Direct.php',
220223
'OCA\\DAV\\Db\\DirectMapper' => __DIR__ . '/..' . '/../lib/Db/DirectMapper.php',
221224
'OCA\\DAV\\Direct\\DirectFile' => __DIR__ . '/..' . '/../lib/Direct/DirectFile.php',
@@ -312,6 +315,7 @@ class ComposerStaticInitDAV
312315
'OCA\\DAV\\Migration\\Version1018Date20210312100735' => __DIR__ . '/..' . '/../lib/Migration/Version1018Date20210312100735.php',
313316
'OCA\\DAV\\Migration\\Version1024Date20211221144219' => __DIR__ . '/..' . '/../lib/Migration/Version1024Date20211221144219.php',
314317
'OCA\\DAV\\Migration\\Version1027Date20230504122946' => __DIR__ . '/..' . '/../lib/Migration/Version1027Date20230504122946.php',
318+
'OCA\\DAV\\Migration\\Version1029Date20231004091403' => __DIR__ . '/..' . '/../lib/Migration/Version1029Date20231004091403.php',
315319
'OCA\\DAV\\Profiler\\ProfilerPlugin' => __DIR__ . '/..' . '/../lib/Profiler/ProfilerPlugin.php',
316320
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
317321
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
@@ -321,6 +325,7 @@ class ComposerStaticInitDAV
321325
'OCA\\DAV\\Search\\EventsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/EventsSearchProvider.php',
322326
'OCA\\DAV\\Search\\TasksSearchProvider' => __DIR__ . '/..' . '/../lib/Search/TasksSearchProvider.php',
323327
'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php',
328+
'OCA\\DAV\\Service\\AbsenceService' => __DIR__ . '/..' . '/../lib/Service/AbsenceService.php',
324329
'OCA\\DAV\\Settings\\AvailabilitySettings' => __DIR__ . '/..' . '/../lib/Settings/AvailabilitySettings.php',
325330
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
326331
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
7+
*
8+
* @author Richard Steinmetz <richard@steinmetz.cloud>
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 DateTimeImmutable;
30+
use OCA\DAV\AppInfo\Application;
31+
use OCA\DAV\Service\AbsenceService;
32+
use OCP\AppFramework\Controller;
33+
use OCP\AppFramework\Http;
34+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
35+
use OCP\AppFramework\Http\JSONResponse;
36+
use OCP\AppFramework\Http\Response;
37+
use OCP\IRequest;
38+
39+
class AvailabilitySettingsController extends Controller {
40+
public function __construct(
41+
IRequest $request,
42+
private ?string $userId,
43+
private AbsenceService $absenceService,
44+
) {
45+
parent::__construct(Application::APP_ID, $request);
46+
}
47+
48+
/**
49+
* @throws \OCP\DB\Exception
50+
* @throws \Exception
51+
*/
52+
#[NoAdminRequired]
53+
public function updateAbsence(
54+
string $firstDay,
55+
string $lastDay,
56+
string $status,
57+
string $message,
58+
): Response {
59+
$userId = $this->userId;
60+
if ($userId === null) {
61+
return new JSONResponse([], Http::STATUS_FORBIDDEN);
62+
}
63+
64+
$parsedFirstDay = new DateTimeImmutable($firstDay);
65+
$parsedLastDay = new DateTimeImmutable($lastDay);
66+
if ($parsedFirstDay->getTimestamp() >= $parsedLastDay->getTimestamp()) {
67+
throw new \Exception('First day is on or after last day');
68+
}
69+
70+
$absence = $this->absenceService->createOrUpdateAbsence(
71+
$userId,
72+
$firstDay,
73+
$lastDay,
74+
$status,
75+
$message,
76+
);
77+
return new JSONResponse($absence);
78+
}
79+
80+
/**
81+
* @throws \OCP\DB\Exception
82+
*/
83+
#[NoAdminRequired]
84+
public function clearAbsence(): Response {
85+
$userId = $this->userId;
86+
if ($userId === null) {
87+
return new JSONResponse([], Http::STATUS_FORBIDDEN);
88+
}
89+
90+
$this->absenceService->clearAbsence($userId);
91+
return new JSONResponse([]);
92+
}
93+
94+
}

apps/dav/lib/Db/Absence.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
7+
*
8+
* @author Richard Steinmetz <richard@steinmetz.cloud>
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\Db;
28+
29+
use JsonSerializable;
30+
use OCP\AppFramework\Db\Entity;
31+
32+
/**
33+
* @method string getUserId()
34+
* @method void setUserId(string $userId)
35+
* @method string getFirstDay()
36+
* @method void setFirstDay(string $firstDay)
37+
* @method string getLastDay()
38+
* @method void setLastDay(string $lastDay)
39+
* @method string getStatus()
40+
* @method void setStatus(string $status)
41+
* @method string getMessage()
42+
* @method void setMessage(string $message)
43+
*/
44+
class Absence extends Entity implements JsonSerializable {
45+
protected string $userId = '';
46+
protected string $firstDay = '';
47+
protected string $lastDay = '';
48+
protected string $status = '';
49+
protected string $message = '';
50+
51+
public function __construct() {
52+
$this->addType('userId', 'string');
53+
$this->addType('firstDay', 'string');
54+
$this->addType('lastDay', 'string');
55+
$this->addType('status', 'string');
56+
$this->addType('message', 'string');
57+
}
58+
59+
public function jsonSerialize(): array {
60+
return [
61+
'userId' => $this->userId,
62+
'firstDay' => $this->firstDay,
63+
'lastDay' => $this->lastDay,
64+
'status' => $this->status,
65+
'message' => $this->message,
66+
];
67+
}
68+
}

apps/dav/lib/Db/AbsenceMapper.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 <richard@steinmetz.cloud>
7+
*
8+
* @author Richard Steinmetz <richard@steinmetz.cloud>
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\Db;
28+
29+
use OCP\AppFramework\Db\DoesNotExistException;
30+
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
31+
use OCP\AppFramework\Db\QBMapper;
32+
use OCP\DB\QueryBuilder\IQueryBuilder;
33+
use OCP\IDBConnection;
34+
35+
/**
36+
* @template-extends QBMapper<Absence>
37+
*/
38+
class AbsenceMapper extends QBMapper {
39+
public function __construct(IDBConnection $db) {
40+
parent::__construct($db, 'dav_absence', Absence::class);
41+
}
42+
43+
/**
44+
* @throws DoesNotExistException
45+
* @throws \OCP\DB\Exception
46+
*/
47+
public function findByUserId(string $userId): Absence {
48+
$qb = $this->db->getQueryBuilder();
49+
$qb->select('*')
50+
->from($this->getTableName())
51+
->where($qb->expr()->eq(
52+
'user_id',
53+
$qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR),
54+
IQueryBuilder::PARAM_STR),
55+
);
56+
try {
57+
return $this->findEntity($qb);
58+
} catch (MultipleObjectsReturnedException $e) {
59+
// Won't happen as there is a unique index on user_id
60+
throw new \RuntimeException('The impossible has happened! The query returned multiple absence settings for one user.');
61+
}
62+
}
63+
64+
/**
65+
* @throws \OCP\DB\Exception
66+
*/
67+
public function deleteByUserId(string $userId): void {
68+
$qb = $this->db->getQueryBuilder();
69+
$qb->delete($this->getTableName())
70+
->where($qb->expr()->eq(
71+
'user_id',
72+
$qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR),
73+
IQueryBuilder::PARAM_STR),
74+
);
75+
$qb->executeStatement();
76+
}
77+
}

0 commit comments

Comments
 (0)