diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-12-09 11:07:05 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-12-10 22:33:38 +0100 |
commit | 4df99d5ef4581b422ef7a895f5c465b4f1d4d3c9 (patch) | |
tree | ab76393141aad2c28e6c288d55237e9d38feabda /apps | |
parent | db5be3d12a70c0535a8cc89b8f0fe0588e8135be (diff) | |
download | nextcloud-server-4df99d5ef4581b422ef7a895f5c465b4f1d4d3c9.tar.gz nextcloud-server-4df99d5ef4581b422ef7a895f5c465b4f1d4d3c9.zip |
feat(dashboard): wish happy birthdayfeat/noid/happy-birthday
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dashboard/lib/Controller/DashboardController.php | 1 | ||||
-rw-r--r-- | apps/dashboard/lib/Service/DashboardService.php | 26 | ||||
-rw-r--r-- | apps/dashboard/src/DashboardApp.vue | 13 | ||||
-rw-r--r-- | apps/dashboard/tests/DashboardServiceTest.php | 100 |
4 files changed, 139 insertions, 1 deletions
diff --git a/apps/dashboard/lib/Controller/DashboardController.php b/apps/dashboard/lib/Controller/DashboardController.php index 959129cdfa3..da7e0901115 100644 --- a/apps/dashboard/lib/Controller/DashboardController.php +++ b/apps/dashboard/lib/Controller/DashboardController.php @@ -68,6 +68,7 @@ class DashboardController extends Controller { $this->initialState->provideInitialState('layout', $this->service->getLayout()); $this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true)); $this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1'); + $this->initialState->provideInitialState('birthdate', $this->service->getBirthdate()); $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0'); $response = new TemplateResponse('dashboard', 'index', [ diff --git a/apps/dashboard/lib/Service/DashboardService.php b/apps/dashboard/lib/Service/DashboardService.php index a311caf5d48..bb5333c2cc7 100644 --- a/apps/dashboard/lib/Service/DashboardService.php +++ b/apps/dashboard/lib/Service/DashboardService.php @@ -9,12 +9,17 @@ declare(strict_types=1); namespace OCA\Dashboard\Service; use JsonException; +use OCP\Accounts\IAccountManager; +use OCP\Accounts\PropertyDoesNotExistException; use OCP\IConfig; +use OCP\IUserManager; class DashboardService { public function __construct( private IConfig $config, private ?string $userId, + private IUserManager $userManager, + private IAccountManager $accountManager, ) { } @@ -42,4 +47,25 @@ class DashboardService { return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== '')); } } + + public function getBirthdate(): string { + if ($this->userId === null) { + return ''; + } + + $user = $this->userManager->get($this->userId); + if ($user === null) { + return ''; + } + + $account = $this->accountManager->getAccount($user); + + try { + $birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE); + } catch (PropertyDoesNotExistException) { + return ''; + } + + return $birthdate->getValue(); + } } diff --git a/apps/dashboard/src/DashboardApp.vue b/apps/dashboard/src/DashboardApp.vue index 727edbb8a93..79a082d908a 100644 --- a/apps/dashboard/src/DashboardApp.vue +++ b/apps/dashboard/src/DashboardApp.vue @@ -147,6 +147,7 @@ import ApiDashboardWidget from './components/ApiDashboardWidget.vue' const panels = loadState('dashboard', 'panels') const firstRun = loadState('dashboard', 'firstRun') +const birthdate = new Date(loadState('dashboard', 'birthdate')) const statusInfo = { weather: { @@ -194,15 +195,21 @@ export default { apiWidgets: [], apiWidgetItems: {}, loadingItems: true, + birthdate, } }, computed: { greeting() { const time = this.timer.getHours() + const isBirthday = this.birthdate instanceof Date + && this.birthdate.getMonth() === this.timer.getMonth() + && this.birthdate.getDate() === this.timer.getDate() // Determine part of the day let partOfDay - if (time >= 22 || time < 5) { + if (isBirthday) { + partOfDay = 'birthday' + } else if (time >= 22 || time < 5) { partOfDay = 'night' } else if (time >= 18) { partOfDay = 'evening' @@ -231,6 +238,10 @@ export default { generic: t('dashboard', 'Hello'), withName: t('dashboard', 'Hello, {name}', { name: this.displayName }, undefined, { escape: false }), }, + birthday: { + generic: t('dashboard', 'Happy birthday 🥳🤩🎂🎉'), + withName: t('dashboard', 'Happy birthday, {name} 🥳🤩🎂🎉', { name: this.displayName }, undefined, { escape: false }), + }, } // Figure out which greeting to show diff --git a/apps/dashboard/tests/DashboardServiceTest.php b/apps/dashboard/tests/DashboardServiceTest.php new file mode 100644 index 00000000000..c603b88e7ff --- /dev/null +++ b/apps/dashboard/tests/DashboardServiceTest.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Dashboard\Tests; + +use OC\Accounts\Account; +use OCA\Dashboard\Service\DashboardService; +use OCP\Accounts\IAccountManager; +use OCP\IConfig; +use OCP\IUser; +use OCP\IUserManager; +use PHPUnit\Framework\MockObject\MockObject; +use Test\TestCase; + +class DashboardServiceTest extends TestCase { + + private IConfig&MockObject $config; + private IUserManager&MockObject $userManager; + private IAccountManager&MockObject $accountManager; + private DashboardService $service; + + protected function setUp(): void { + parent::setUp(); + + $this->config = $this->createMock(IConfig::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->accountManager = $this->createMock(IAccountManager::class); + + $this->service = new DashboardService( + $this->config, + 'alice', + $this->userManager, + $this->accountManager, + ); + } + + public function testGetBirthdate() { + $user = $this->createMock(IUser::class); + $this->userManager->method('get') + ->willReturn($user); + + $account = new Account($user); + $account->setProperty( + IAccountManager::PROPERTY_BIRTHDATE, + '2024-12-10T00:00:00.000Z', + IAccountManager::SCOPE_LOCAL, + IAccountManager::VERIFIED, + ); + + $this->accountManager->method('getAccount') + ->willReturn($account); + + $birthdate = $this->service->getBirthdate(); + + $this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate); + } + + public function testGetBirthdatePropertyDoesNotExist() { + $user = $this->createMock(IUser::class); + $this->userManager->method('get') + ->willReturn($user); + + $account = new Account($user); + $this->accountManager->method('getAccount') + ->willReturn($account); + + $birthdate = $this->service->getBirthdate(); + + $this->assertEquals('', $birthdate); + } + + public function testGetBirthdateUserNotFound() { + $this->userManager->method('get') + ->willReturn(null); + + $birthdate = $this->service->getBirthdate(); + + $this->assertEquals('', $birthdate); + } + + public function testGetBirthdateNoUserId() { + $service = new DashboardService( + $this->config, + null, + $this->userManager, + $this->accountManager, + ); + + $birthdate = $service->getBirthdate(); + + $this->assertEquals('', $birthdate); + } + +} |