diff options
author | Thomas Citharel <tcit@tcit.fr> | 2019-09-15 10:29:56 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2021-06-25 14:15:10 +0200 |
commit | f73478654dc39bae79aa6293a743d0bd7e0a7d9e (patch) | |
tree | ecbdfe130629228d25ab0eb919bdd62696b32d08 | |
parent | 00edbc2adf4d9362041f5611c62967f5a70e5b7e (diff) | |
download | nextcloud-server-f73478654dc39bae79aa6293a743d0bd7e0a7d9e.tar.gz nextcloud-server-f73478654dc39bae79aa6293a743d0bd7e0a7d9e.zip |
Always provide theme color for default personal calendar
Before this calendar-color wasn't defined for default calendar
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
-rw-r--r-- | apps/dav/lib/HookManager.php | 7 | ||||
-rw-r--r-- | apps/dav/tests/unit/DAV/HookManagerTest.php | 42 |
2 files changed, 43 insertions, 6 deletions
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php index 3929fdabbd0..6886a62d8e9 100644 --- a/apps/dav/lib/HookManager.php +++ b/apps/dav/lib/HookManager.php @@ -31,6 +31,7 @@ namespace OCA\DAV; 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; @@ -59,6 +60,9 @@ class HookManager { /** @var array */ private $addressBooksToDelete = []; + /** @var Defaults */ + private $themingDefaults; + /** @var EventDispatcherInterface */ private $eventDispatcher; @@ -66,11 +70,13 @@ class HookManager { 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; } @@ -156,6 +162,7 @@ class HookManager { 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); diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php index d36db8f90c8..e86c84e56de 100644 --- a/apps/dav/tests/unit/DAV/HookManagerTest.php +++ b/apps/dav/tests/unit/DAV/HookManagerTest.php @@ -34,6 +34,7 @@ use OCA\DAV\CalDAV\CalDavBackend; 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; @@ -75,6 +76,13 @@ class HookManagerTest extends TestCase { ->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() @@ -82,7 +90,10 @@ class HookManagerTest extends TestCase { $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) @@ -93,7 +104,7 @@ class HookManagerTest extends TestCase { '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); } @@ -113,6 +124,11 @@ class HookManagerTest extends TestCase { ->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() @@ -127,7 +143,7 @@ class HookManagerTest extends TestCase { $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); } @@ -147,6 +163,12 @@ class HookManagerTest extends TestCase { ->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() @@ -154,7 +176,10 @@ class HookManagerTest extends TestCase { $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) @@ -165,7 +190,7 @@ class HookManagerTest extends TestCase { '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); } @@ -187,6 +212,11 @@ class HookManagerTest extends TestCase { $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() @@ -206,7 +236,7 @@ class HookManagerTest extends TestCase { ]); $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']); } |