summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-12-01 10:46:16 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-12-05 08:36:50 +0100
commit9a206c6282a55c9fdeb99abe8684199c0f934d7f (patch)
treeafbcabe90d48f80bf26284651bbbfceba806bb4e /apps/dav/lib
parente27e2e43955bc09bbce86b4cfe458a2af2f66724 (diff)
downloadnextcloud-server-9a206c6282a55c9fdeb99abe8684199c0f934d7f.tar.gz
nextcloud-server-9a206c6282a55c9fdeb99abe8684199c0f934d7f.zip
fix(dav): Make current ooo info time-dependent
* If there is an out of office absence info and it happens now -> return data * Else: return no data Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/Controller/OutOfOfficeController.php39
-rw-r--r--apps/dav/lib/ResponseDefinitions.php17
-rw-r--r--apps/dav/lib/Service/AbsenceService.php16
3 files changed, 65 insertions, 7 deletions
diff --git a/apps/dav/lib/Controller/OutOfOfficeController.php b/apps/dav/lib/Controller/OutOfOfficeController.php
index ffac1247a6c..a2e7378f32d 100644
--- a/apps/dav/lib/Controller/OutOfOfficeController.php
+++ b/apps/dav/lib/Controller/OutOfOfficeController.php
@@ -27,7 +27,6 @@ declare(strict_types=1);
namespace OCA\DAV\Controller;
use DateTimeImmutable;
-use OCA\DAV\Db\AbsenceMapper;
use OCA\DAV\ResponseDefinitions;
use OCA\DAV\Service\AbsenceService;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -36,18 +35,20 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
+use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\IAvailabilityCoordinator;
/**
* @psalm-import-type DAVOutOfOfficeData from ResponseDefinitions
+ * @psalm-import-type DAVCurrentOutOfOfficeData from ResponseDefinitions
*/
class OutOfOfficeController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
- private AbsenceMapper $absenceMapper,
+ private IUserManager $userManager,
private ?IUserSession $userSession,
private AbsenceService $absenceService,
private IAvailabilityCoordinator $coordinator,
@@ -59,15 +60,45 @@ class OutOfOfficeController extends OCSController {
* Get the currently configured out-of-office data of a user.
*
* @param string $userId The user id to get out-of-office data for.
- * @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
+ * @return DataResponse<Http::STATUS_OK, DAVCurrentOutOfOfficeData, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Out-of-office data
* 404: No out-of-office data was found
*/
#[NoAdminRequired]
public function getCurrentOutOfOfficeData(string $userId): DataResponse {
+ $user = $this->userManager->get($userId);
+ if ($user === null) {
+ return new DataResponse(null, Http::STATUS_NOT_FOUND);
+ }
+ try {
+ $data = $this->absenceService->getCurrentAbsence($user);
+ if ($data === null) {
+ return new DataResponse(null, Http::STATUS_NOT_FOUND);
+ }
+ } catch (DoesNotExistException) {
+ return new DataResponse(null, Http::STATUS_NOT_FOUND);
+ }
+
+ return new DataResponse($data->jsonSerialize());
+ }
+
+ /**
+ * Get the configured out-of-office data of a user.
+ *
+ * @param string $userId The user id to get out-of-office data for.
+ * @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
+ *
+ * 200: Out-of-office data
+ * 404: No out-of-office data was found
+ */
+ #[NoAdminRequired]
+ public function getOutOfOffice(string $userId): DataResponse {
try {
- $data = $this->absenceMapper->findByUserId($userId);
+ $data = $this->absenceService->getAbsence($userId);
+ if ($data === null) {
+ return new DataResponse(null, Http::STATUS_NOT_FOUND);
+ }
} catch (DoesNotExistException) {
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}
diff --git a/apps/dav/lib/ResponseDefinitions.php b/apps/dav/lib/ResponseDefinitions.php
index 97bd8e9efe9..e6de3d5a65c 100644
--- a/apps/dav/lib/ResponseDefinitions.php
+++ b/apps/dav/lib/ResponseDefinitions.php
@@ -27,13 +27,24 @@ declare(strict_types=1);
namespace OCA\DAV;
/**
- * @psalm-type DAVOutOfOfficeData = array{
+ * @psalm-type DAVOutOfOfficeDataCommon = array{
+ * userId: string,
+ * message: string,
+ * }
+ *
+ * @psalm-type DAVOutOfOfficeData = DAVOutOfOfficeDataCommon&array{
* id: int,
- * userId: string,
* firstDay: string,
* lastDay: string,
* status: string,
- * message: string,
+ * }
+ *
+ * @todo this is a copy of \OCP\User\IOutOfOfficeData
+ * @psalm-type DAVCurrentOutOfOfficeData = DAVOutOfOfficeDataCommon&array{
+ * id: string,
+ * startDate: int,
+ * endDate: int,
+ * shortMessage: string,
* }
*/
class ResponseDefinitions {
diff --git a/apps/dav/lib/Service/AbsenceService.php b/apps/dav/lib/Service/AbsenceService.php
index 7c0d6eec082..3e2a218d52b 100644
--- a/apps/dav/lib/Service/AbsenceService.php
+++ b/apps/dav/lib/Service/AbsenceService.php
@@ -145,6 +145,22 @@ class AbsenceService {
}
}
+ public function getCurrentAbsence(IUser $user): ?IOutOfOfficeData {
+ try {
+ $absence = $this->absenceMapper->findByUserId($user->getUID());
+ $oooData = $absence->toOutOufOfficeData(
+ $user,
+ $this->timezoneService->getUserTimezone($user->getUID()) ?? $this->timezoneService->getDefaultTimezone(),
+ );
+ if ($this->isInEffect($oooData)) {
+ return $oooData;
+ }
+ } catch (DoesNotExistException) {
+ // Nothing there to process
+ }
+ return null;
+ }
+
public function isInEffect(IOutOfOfficeData $absence): bool {
$now = $this->timeFactory->getTime();
return $absence->getStartDate() <= $now && $absence->getEndDate() >= $now;