Skip to content

Commit 284827a

Browse files
authored
Merge pull request #49730 from nextcloud/feat/noid/happy-birthday
feat(dashboard): wish happy birthday
2 parents 08e959d + 4df99d5 commit 284827a

File tree

6 files changed

+142
-4
lines changed

6 files changed

+142
-4
lines changed

apps/dashboard/lib/Controller/DashboardController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function index(): TemplateResponse {
6868
$this->initialState->provideInitialState('layout', $this->service->getLayout());
6969
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
7070
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
71+
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
7172
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
7273

7374
$response = new TemplateResponse('dashboard', 'index', [

apps/dashboard/lib/Service/DashboardService.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
namespace OCA\Dashboard\Service;
1010

1111
use JsonException;
12+
use OCP\Accounts\IAccountManager;
13+
use OCP\Accounts\PropertyDoesNotExistException;
1214
use OCP\IConfig;
15+
use OCP\IUserManager;
1316

1417
class DashboardService {
1518
public function __construct(
1619
private IConfig $config,
1720
private ?string $userId,
21+
private IUserManager $userManager,
22+
private IAccountManager $accountManager,
1823
) {
1924

2025
}
@@ -42,4 +47,25 @@ public function getStatuses() {
4247
return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
4348
}
4449
}
50+
51+
public function getBirthdate(): string {
52+
if ($this->userId === null) {
53+
return '';
54+
}
55+
56+
$user = $this->userManager->get($this->userId);
57+
if ($user === null) {
58+
return '';
59+
}
60+
61+
$account = $this->accountManager->getAccount($user);
62+
63+
try {
64+
$birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE);
65+
} catch (PropertyDoesNotExistException) {
66+
return '';
67+
}
68+
69+
return $birthdate->getValue();
70+
}
4571
}

apps/dashboard/src/DashboardApp.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ import ApiDashboardWidget from './components/ApiDashboardWidget.vue'
147147
148148
const panels = loadState('dashboard', 'panels')
149149
const firstRun = loadState('dashboard', 'firstRun')
150+
const birthdate = new Date(loadState('dashboard', 'birthdate'))
150151
151152
const statusInfo = {
152153
weather: {
@@ -194,15 +195,21 @@ export default {
194195
apiWidgets: [],
195196
apiWidgetItems: {},
196197
loadingItems: true,
198+
birthdate,
197199
}
198200
},
199201
computed: {
200202
greeting() {
201203
const time = this.timer.getHours()
204+
const isBirthday = this.birthdate instanceof Date
205+
&& this.birthdate.getMonth() === this.timer.getMonth()
206+
&& this.birthdate.getDate() === this.timer.getDate()
202207
203208
// Determine part of the day
204209
let partOfDay
205-
if (time >= 22 || time < 5) {
210+
if (isBirthday) {
211+
partOfDay = 'birthday'
212+
} else if (time >= 22 || time < 5) {
206213
partOfDay = 'night'
207214
} else if (time >= 18) {
208215
partOfDay = 'evening'
@@ -231,6 +238,10 @@ export default {
231238
generic: t('dashboard', 'Hello'),
232239
withName: t('dashboard', 'Hello, {name}', { name: this.displayName }, undefined, { escape: false }),
233240
},
241+
birthday: {
242+
generic: t('dashboard', 'Happy birthday 🥳🤩🎂🎉'),
243+
withName: t('dashboard', 'Happy birthday, {name} 🥳🤩🎂🎉', { name: this.displayName }, undefined, { escape: false }),
244+
},
234245
}
235246
236247
// Figure out which greeting to show
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Dashboard\Tests;
11+
12+
use OC\Accounts\Account;
13+
use OCA\Dashboard\Service\DashboardService;
14+
use OCP\Accounts\IAccountManager;
15+
use OCP\IConfig;
16+
use OCP\IUser;
17+
use OCP\IUserManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use Test\TestCase;
20+
21+
class DashboardServiceTest extends TestCase {
22+
23+
private IConfig&MockObject $config;
24+
private IUserManager&MockObject $userManager;
25+
private IAccountManager&MockObject $accountManager;
26+
private DashboardService $service;
27+
28+
protected function setUp(): void {
29+
parent::setUp();
30+
31+
$this->config = $this->createMock(IConfig::class);
32+
$this->userManager = $this->createMock(IUserManager::class);
33+
$this->accountManager = $this->createMock(IAccountManager::class);
34+
35+
$this->service = new DashboardService(
36+
$this->config,
37+
'alice',
38+
$this->userManager,
39+
$this->accountManager,
40+
);
41+
}
42+
43+
public function testGetBirthdate() {
44+
$user = $this->createMock(IUser::class);
45+
$this->userManager->method('get')
46+
->willReturn($user);
47+
48+
$account = new Account($user);
49+
$account->setProperty(
50+
IAccountManager::PROPERTY_BIRTHDATE,
51+
'2024-12-10T00:00:00.000Z',
52+
IAccountManager::SCOPE_LOCAL,
53+
IAccountManager::VERIFIED,
54+
);
55+
56+
$this->accountManager->method('getAccount')
57+
->willReturn($account);
58+
59+
$birthdate = $this->service->getBirthdate();
60+
61+
$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
62+
}
63+
64+
public function testGetBirthdatePropertyDoesNotExist() {
65+
$user = $this->createMock(IUser::class);
66+
$this->userManager->method('get')
67+
->willReturn($user);
68+
69+
$account = new Account($user);
70+
$this->accountManager->method('getAccount')
71+
->willReturn($account);
72+
73+
$birthdate = $this->service->getBirthdate();
74+
75+
$this->assertEquals('', $birthdate);
76+
}
77+
78+
public function testGetBirthdateUserNotFound() {
79+
$this->userManager->method('get')
80+
->willReturn(null);
81+
82+
$birthdate = $this->service->getBirthdate();
83+
84+
$this->assertEquals('', $birthdate);
85+
}
86+
87+
public function testGetBirthdateNoUserId() {
88+
$service = new DashboardService(
89+
$this->config,
90+
null,
91+
$this->userManager,
92+
$this->accountManager,
93+
);
94+
95+
$birthdate = $service->getBirthdate();
96+
97+
$this->assertEquals('', $birthdate);
98+
}
99+
100+
}

dist/dashboard-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dashboard-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)