Skip to content

Commit

Permalink
Always provide theme color for default personal calendar
Browse files Browse the repository at this point in the history
Before this calendar-color wasn't defined for default calendar

Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Jun 25, 2021
1 parent 00edbc2 commit f734786
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
7 changes: 7 additions & 0 deletions apps/dav/lib/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\SyncService;
use OCP\Defaults;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Util;
Expand Down Expand Up @@ -59,18 +60,23 @@ class HookManager {
/** @var array */
private $addressBooksToDelete = [];

/** @var Defaults */
private $themingDefaults;

/** @var EventDispatcherInterface */
private $eventDispatcher;

public function __construct(IUserManager $userManager,
SyncService $syncService,
CalDavBackend $calDav,
CardDavBackend $cardDav,
Defaults $themingDefaults,
EventDispatcherInterface $eventDispatcher) {
$this->userManager = $userManager;
$this->syncService = $syncService;
$this->calDav = $calDav;
$this->cardDav = $cardDav;
$this->themingDefaults = $themingDefaults;
$this->eventDispatcher = $eventDispatcher;
}

Expand Down Expand Up @@ -156,6 +162,7 @@ public function firstLogin(IUser $user = null) {
try {
$this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [
'{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
'{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary()
]);
} catch (\Exception $ex) {
\OC::$server->getLogger()->logException($ex);
Expand Down
42 changes: 36 additions & 6 deletions apps/dav/tests/unit/DAV/HookManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\HookManager;
use OCP\Defaults;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
Expand Down Expand Up @@ -75,14 +76,24 @@ public function test() {
->disableOriginalConstructor()
->getMock();

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();

$defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca');

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
$cal->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0);
$cal->expects($this->once())->method('createCalendar')->with(
'principals/users/newUser',
'personal', ['{DAV:}displayname' => 'Personal']);
'personal', [
'{DAV:}displayname' => 'Personal',
'{http://apple.com/ns/ical/}calendar-color' => '#745bca'
]);

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
Expand All @@ -93,7 +104,7 @@ public function test() {
'principals/users/newUser',
'contacts', ['{DAV:}displayname' => 'Contacts']);

$hm = new HookManager($userManager, $syncService, $cal, $card, $this->eventDispatcher);
$hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
$hm->firstLogin($user);
}

Expand All @@ -113,6 +124,11 @@ public function testWithExisting() {
->disableOriginalConstructor()
->getMock();

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
Expand All @@ -127,7 +143,7 @@ public function testWithExisting() {
$card->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(1);
$card->expects($this->never())->method('createAddressBook');

$hm = new HookManager($userManager, $syncService, $cal, $card, $this->eventDispatcher);
$hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
$hm->firstLogin($user);
}

Expand All @@ -147,14 +163,23 @@ public function testWithBirthdayCalendar() {
->disableOriginalConstructor()
->getMock();

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();
$defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca');

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
$cal->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0);
$cal->expects($this->once())->method('createCalendar')->with(
'principals/users/newUser',
'personal', ['{DAV:}displayname' => 'Personal']);
'personal', [
'{DAV:}displayname' => 'Personal',
'{http://apple.com/ns/ical/}calendar-color' => '#745bca'
]);

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
Expand All @@ -165,7 +190,7 @@ public function testWithBirthdayCalendar() {
'principals/users/newUser',
'contacts', ['{DAV:}displayname' => 'Contacts']);

$hm = new HookManager($userManager, $syncService, $cal, $card, $this->eventDispatcher);
$hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
$hm->firstLogin($user);
}

Expand All @@ -187,6 +212,11 @@ public function testDeleteCalendar() {
$syncService->expects($this->once())
->method('deleteUser');

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
Expand All @@ -206,7 +236,7 @@ public function testDeleteCalendar() {
]);
$card->expects($this->once())->method('deleteAddressBook');

$hm = new HookManager($userManager, $syncService, $cal, $card, $this->eventDispatcher);
$hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
$hm->preDeleteUser(['uid' => 'newUser']);
$hm->postDeleteUser(['uid' => 'newUser']);
}
Expand Down

0 comments on commit f734786

Please sign in to comment.