Skip to content

Commit c557c4a

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

25 files changed

+792
-319
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\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.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\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.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/Settings/AvailabilitySettings.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
77
*
88
* @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
9+
* @author Richard Steinmetz <richard@steinmetz.cloud>
910
*
1011
* @license GNU AGPL version 3 or any later version
1112
*
@@ -26,6 +27,8 @@
2627
namespace OCA\DAV\Settings;
2728

2829
use OCA\DAV\AppInfo\Application;
30+
use OCA\DAV\Db\AbsenceMapper;
31+
use OCP\AppFramework\Db\DoesNotExistException;
2932
use OCP\AppFramework\Http\TemplateResponse;
3033
use OCP\AppFramework\Services\IInitialState;
3134
use OCP\IConfig;
@@ -38,7 +41,8 @@ class AvailabilitySettings implements ISettings {
3841

3942
public function __construct(IConfig $config,
4043
IInitialState $initialState,
41-
?string $userId) {
44+
?string $userId,
45+
private AbsenceMapper $absenceMapper) {
4246
$this->config = $config;
4347
$this->initialState = $initialState;
4448
$this->userId = $userId;
@@ -54,6 +58,19 @@ public function getForm(): TemplateResponse {
5458
'no'
5559
)
5660
);
61+
$hideAbsenceSettings = $this->config->getAppValue(
62+
Application::APP_ID,
63+
'hide_absence_settings',
64+
'yes',
65+
) === 'yes';
66+
$this->initialState->provideInitialState('hide_absence_settings', $hideAbsenceSettings);
67+
if (!$hideAbsenceSettings) {
68+
try {
69+
$absence = $this->absenceMapper->findByUserId($this->userId);
70+
$this->initialState->provideInitialState('absence', $absence);
71+
} catch (DoesNotExistException|\OCP\DB\Exception) {
72+
}
73+
}
5774

5875
return new TemplateResponse(Application::APP_ID, 'settings-personal-availability');
5976
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<!--
2+
- @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
3+
-
4+
- @author Richard Steinmetz <richard@steinmetz.cloud>
5+
-
6+
- @license AGPL-3.0-or-later
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU General Public License as published by
10+
- the Free Software Foundation, either version 3 of the License, or
11+
- (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-
21+
-->
22+
23+
<template>
24+
<div class="absence">
25+
<div class="absence__dates">
26+
<NcDateTimePickerNative id="absence-first-day"
27+
v-model="firstDay"
28+
:label="$t('dav', 'First day')"
29+
class="absence__dates__picker" />
30+
<NcDateTimePickerNative id="absence-last-day"
31+
v-model="lastDay"
32+
:label="$t('dav', 'Last day (inclusive)')"
33+
class="absence__dates__picker" />
34+
</div>
35+
<NcTextField :value.sync="status" :label="$t('dav', 'Short absence status')" />
36+
<NcTextArea :value.sync="message" :label="$t('dav', 'Long absence Message')" />
37+
38+
<div class="absence__buttons">
39+
<NcButton :disabled="loading"
40+
type="primary"
41+
@click="saveForm">
42+
{{ $t('dav', 'Save') }}
43+
</NcButton>
44+
<NcButton :disabled="loading"
45+
type="error"
46+
@click="clearAbsence">
47+
{{ $t('dav', 'Disable absence') }}
48+
</NcButton>
49+
</div>
50+
</div>
51+
</template>
52+
53+
<script>
54+
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
55+
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
56+
import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js'
57+
import NcDateTimePickerNative from '@nextcloud/vue/dist/Components/NcDateTimePickerNative.js'
58+
import { generateUrl } from '@nextcloud/router'
59+
import axios from '@nextcloud/axios'
60+
import { formatDateAsYMD } from '../utils/date.js'
61+
import { loadState } from '@nextcloud/initial-state'
62+
import { showError } from '@nextcloud/dialogs'
63+
64+
export default {
65+
name: 'AbsenceForm',
66+
components: {
67+
NcButton,
68+
NcTextField,
69+
NcTextArea,
70+
NcDateTimePickerNative,
71+
},
72+
data() {
73+
const { firstDay, lastDay, status, message } = loadState('dav', 'absence', {})
74+
75+
return {
76+
loading: false,
77+
status: status ?? '',
78+
message: message ?? '',
79+
firstDay: firstDay ? new Date(firstDay) : new Date(),
80+
lastDay: lastDay ? new Date(lastDay) : null,
81+
}
82+
},
83+
computed: {
84+
/**
85+
* @return {boolean}
86+
*/
87+
valid() {
88+
return !!this.firstDay
89+
&& !!this.lastDay
90+
&& !!this.status
91+
&& this.lastDay > this.firstDay
92+
},
93+
},
94+
methods: {
95+
resetForm() {
96+
this.status = ''
97+
this.message = ''
98+
this.firstDay = new Date()
99+
this.lastDay = null
100+
},
101+
async saveForm() {
102+
if (!this.valid) {
103+
return
104+
}
105+
106+
this.loading = true
107+
try {
108+
await axios.post(generateUrl('/apps/dav/settings/absence'), {
109+
firstDay: formatDateAsYMD(this.firstDay),
110+
lastDay: formatDateAsYMD(this.lastDay),
111+
status: this.status,
112+
message: this.message,
113+
})
114+
} catch (error) {
115+
showError(this.$t('dav', 'Failed to save your absence settings'))
116+
} finally {
117+
this.loading = false
118+
}
119+
},
120+
async clearAbsence() {
121+
this.loading = true
122+
try {
123+
await axios.delete(generateUrl('/apps/dav/settings/absence'))
124+
this.resetForm()
125+
} catch (error) {
126+
// TODO: Handle error
127+
} finally {
128+
this.loading = false
129+
}
130+
},
131+
},
132+
}
133+
</script>
134+
135+
<style lang="scss" scoped>
136+
.absence {
137+
display: flex;
138+
flex-direction: column;
139+
gap: 5px;
140+
141+
&__dates {
142+
display: flex;
143+
gap: 10px;
144+
width: 100%;
145+
146+
&__picker {
147+
flex: 1 auto;
148+
149+
::v-deep .native-datetime-picker--input {
150+
margin-bottom: 0;
151+
}
152+
}
153+
}
154+
155+
&__buttons {
156+
display: flex;
157+
gap: 5px;
158+
}
159+
}
160+
</style>

0 commit comments

Comments
 (0)