diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-12-01 10:46:16 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-12-05 08:36:50 +0100 |
commit | 9a206c6282a55c9fdeb99abe8684199c0f934d7f (patch) | |
tree | afbcabe90d48f80bf26284651bbbfceba806bb4e /apps/dav/lib/Controller | |
parent | e27e2e43955bc09bbce86b4cfe458a2af2f66724 (diff) | |
download | nextcloud-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/Controller')
-rw-r--r-- | apps/dav/lib/Controller/OutOfOfficeController.php | 39 |
1 files changed, 35 insertions, 4 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); } |