Skip to content

Commit 6033c25

Browse files
Merge pull request #54084 from nextcloud/feat/dav/absence-get-set-commands
feat(dav): add occ commands to get and set absences
2 parents 91a35db + ee00d16 commit 6033c25

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

apps/dav/appinfo/info.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<command>OCA\DAV\Command\DeleteSubscription</command>
6666
<command>OCA\DAV\Command\ExportCalendar</command>
6767
<command>OCA\DAV\Command\FixCalendarSyncCommand</command>
68+
<command>OCA\DAV\Command\GetAbsenceCommand</command>
6869
<command>OCA\DAV\Command\ListAddressbooks</command>
6970
<command>OCA\DAV\Command\ListCalendarShares</command>
7071
<command>OCA\DAV\Command\ListCalendars</command>
@@ -73,6 +74,7 @@
7374
<command>OCA\DAV\Command\RemoveInvalidShares</command>
7475
<command>OCA\DAV\Command\RetentionCleanupCommand</command>
7576
<command>OCA\DAV\Command\SendEventReminders</command>
77+
<command>OCA\DAV\Command\SetAbsenceCommand</command>
7678
<command>OCA\DAV\Command\SyncBirthdayCalendar</command>
7779
<command>OCA\DAV\Command\SyncSystemAddressBook</command>
7880
</commands>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
'OCA\\DAV\\Command\\DeleteSubscription' => $baseDir . '/../lib/Command/DeleteSubscription.php',
166166
'OCA\\DAV\\Command\\ExportCalendar' => $baseDir . '/../lib/Command/ExportCalendar.php',
167167
'OCA\\DAV\\Command\\FixCalendarSyncCommand' => $baseDir . '/../lib/Command/FixCalendarSyncCommand.php',
168+
'OCA\\DAV\\Command\\GetAbsenceCommand' => $baseDir . '/../lib/Command/GetAbsenceCommand.php',
168169
'OCA\\DAV\\Command\\ListAddressbooks' => $baseDir . '/../lib/Command/ListAddressbooks.php',
169170
'OCA\\DAV\\Command\\ListCalendarShares' => $baseDir . '/../lib/Command/ListCalendarShares.php',
170171
'OCA\\DAV\\Command\\ListCalendars' => $baseDir . '/../lib/Command/ListCalendars.php',
@@ -173,6 +174,7 @@
173174
'OCA\\DAV\\Command\\RemoveInvalidShares' => $baseDir . '/../lib/Command/RemoveInvalidShares.php',
174175
'OCA\\DAV\\Command\\RetentionCleanupCommand' => $baseDir . '/../lib/Command/RetentionCleanupCommand.php',
175176
'OCA\\DAV\\Command\\SendEventReminders' => $baseDir . '/../lib/Command/SendEventReminders.php',
177+
'OCA\\DAV\\Command\\SetAbsenceCommand' => $baseDir . '/../lib/Command/SetAbsenceCommand.php',
176178
'OCA\\DAV\\Command\\SyncBirthdayCalendar' => $baseDir . '/../lib/Command/SyncBirthdayCalendar.php',
177179
'OCA\\DAV\\Command\\SyncSystemAddressBook' => $baseDir . '/../lib/Command/SyncSystemAddressBook.php',
178180
'OCA\\DAV\\Comments\\CommentNode' => $baseDir . '/../lib/Comments/CommentNode.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class ComposerStaticInitDAV
180180
'OCA\\DAV\\Command\\DeleteSubscription' => __DIR__ . '/..' . '/../lib/Command/DeleteSubscription.php',
181181
'OCA\\DAV\\Command\\ExportCalendar' => __DIR__ . '/..' . '/../lib/Command/ExportCalendar.php',
182182
'OCA\\DAV\\Command\\FixCalendarSyncCommand' => __DIR__ . '/..' . '/../lib/Command/FixCalendarSyncCommand.php',
183+
'OCA\\DAV\\Command\\GetAbsenceCommand' => __DIR__ . '/..' . '/../lib/Command/GetAbsenceCommand.php',
183184
'OCA\\DAV\\Command\\ListAddressbooks' => __DIR__ . '/..' . '/../lib/Command/ListAddressbooks.php',
184185
'OCA\\DAV\\Command\\ListCalendarShares' => __DIR__ . '/..' . '/../lib/Command/ListCalendarShares.php',
185186
'OCA\\DAV\\Command\\ListCalendars' => __DIR__ . '/..' . '/../lib/Command/ListCalendars.php',
@@ -188,6 +189,7 @@ class ComposerStaticInitDAV
188189
'OCA\\DAV\\Command\\RemoveInvalidShares' => __DIR__ . '/..' . '/../lib/Command/RemoveInvalidShares.php',
189190
'OCA\\DAV\\Command\\RetentionCleanupCommand' => __DIR__ . '/..' . '/../lib/Command/RetentionCleanupCommand.php',
190191
'OCA\\DAV\\Command\\SendEventReminders' => __DIR__ . '/..' . '/../lib/Command/SendEventReminders.php',
192+
'OCA\\DAV\\Command\\SetAbsenceCommand' => __DIR__ . '/..' . '/../lib/Command/SetAbsenceCommand.php',
191193
'OCA\\DAV\\Command\\SyncBirthdayCalendar' => __DIR__ . '/..' . '/../lib/Command/SyncBirthdayCalendar.php',
192194
'OCA\\DAV\\Command\\SyncSystemAddressBook' => __DIR__ . '/..' . '/../lib/Command/SyncSystemAddressBook.php',
193195
'OCA\\DAV\\Comments\\CommentNode' => __DIR__ . '/..' . '/../lib/Comments/CommentNode.php',
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-only
8+
*/
9+
10+
namespace OCA\DAV\Command;
11+
12+
use OCA\DAV\Service\AbsenceService;
13+
use OCP\IUserManager;
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
19+
class GetAbsenceCommand extends Command {
20+
21+
public function __construct(
22+
private IUserManager $userManager,
23+
private AbsenceService $absenceService,
24+
) {
25+
parent::__construct();
26+
}
27+
28+
protected function configure(): void {
29+
$this->setName('dav:absence:get');
30+
$this->addArgument(
31+
'user-id',
32+
InputArgument::REQUIRED,
33+
'User ID of the affected account'
34+
);
35+
}
36+
37+
public function execute(InputInterface $input, OutputInterface $output): int {
38+
$userId = $input->getArgument('user-id');
39+
40+
$user = $this->userManager->get($userId);
41+
if ($user === null) {
42+
$output->writeln('<error>User not found</error>');
43+
return 1;
44+
}
45+
46+
$absence = $this->absenceService->getAbsence($userId);
47+
if ($absence === null) {
48+
$output->writeln('<info>No absence set</info>');
49+
return 0;
50+
}
51+
52+
$output->writeln('<info>Start day:</info> ' . $absence->getFirstDay());
53+
$output->writeln('<info>End day:</info> ' . $absence->getLastDay());
54+
$output->writeln('<info>Short message:</info> ' . $absence->getStatus());
55+
$output->writeln('<info>Message:</info> ' . $absence->getMessage());
56+
$output->writeln('<info>Replacement user:</info> ' . ($absence->getReplacementUserId() ?? 'none'));
57+
$output->writeln('<info>Replacement display name:</info> ' . ($absence->getReplacementUserDisplayName() ?? 'none'));
58+
59+
return 0;
60+
}
61+
62+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-only
8+
*/
9+
10+
namespace OCA\DAV\Command;
11+
12+
use OCA\DAV\Service\AbsenceService;
13+
use OCP\IUserManager;
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
19+
class SetAbsenceCommand extends Command {
20+
21+
public function __construct(
22+
private IUserManager $userManager,
23+
private AbsenceService $absenceService,
24+
) {
25+
parent::__construct();
26+
}
27+
28+
protected function configure(): void {
29+
$this->setName('dav:absence:set');
30+
$this->addArgument(
31+
'user-id',
32+
InputArgument::REQUIRED,
33+
'User ID of the affected account'
34+
);
35+
$this->addArgument(
36+
'first-day',
37+
InputArgument::REQUIRED,
38+
'Inclusive start day formatted as YYYY-MM-DD'
39+
);
40+
$this->addArgument(
41+
'last-day',
42+
InputArgument::REQUIRED,
43+
'Inclusive end day formatted as YYYY-MM-DD'
44+
);
45+
$this->addArgument(
46+
'short-message',
47+
InputArgument::REQUIRED,
48+
'Short message'
49+
);
50+
$this->addArgument(
51+
'message',
52+
InputArgument::REQUIRED,
53+
'Message'
54+
);
55+
$this->addArgument(
56+
'replacement-user-id',
57+
InputArgument::OPTIONAL,
58+
'Replacement user id'
59+
);
60+
}
61+
62+
public function execute(InputInterface $input, OutputInterface $output): int {
63+
$userId = $input->getArgument('user-id');
64+
65+
$user = $this->userManager->get($userId);
66+
if ($user === null) {
67+
$output->writeln('<error>User not found</error>');
68+
return 1;
69+
}
70+
71+
$replacementUserId = $input->getArgument('replacement-user-id');
72+
if ($replacementUserId === null) {
73+
$replacementUser = null;
74+
} else {
75+
$replacementUser = $this->userManager->get($replacementUserId);
76+
if ($replacementUser === null) {
77+
$output->writeln('<error>Replacement user not found</error>');
78+
return 2;
79+
}
80+
}
81+
82+
$this->absenceService->createOrUpdateAbsence(
83+
$user,
84+
$input->getArgument('first-day'),
85+
$input->getArgument('last-day'),
86+
$input->getArgument('short-message'),
87+
$input->getArgument('message'),
88+
$replacementUser?->getUID(),
89+
$replacementUser?->getDisplayName(),
90+
);
91+
92+
return 0;
93+
}
94+
95+
}

0 commit comments

Comments
 (0)