diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2021-07-02 16:29:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-02 16:29:18 +0200 |
commit | 8ebbd91909dff3c216dd646f430a776219a49c5e (patch) | |
tree | 2a2d69668b362d7ef8ed8a1280ef01a369dedd78 | |
parent | 129214e430865836dad57b271f49e63412d5c842 (diff) | |
parent | 8927205d8aa77d0dfa3e4699a3500ea75b82c896 (diff) | |
download | nextcloud-server-8ebbd91909dff3c216dd646f430a776219a49c5e.tar.gz nextcloud-server-8ebbd91909dff3c216dd646f430a776219a49c5e.zip |
Merge pull request #17148 from nextcloud/always-provide-color-to-default-personal-calendar
Always provide theme color for default personal calendar
-rw-r--r-- | apps/dav/lib/HookManager.php | 8 | ||||
-rw-r--r-- | apps/dav/tests/unit/DAV/HookManagerTest.php | 44 |
2 files changed, 46 insertions, 6 deletions
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php index 3929fdabbd0..03e7551e971 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,8 @@ 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(), + 'components' => 'VEVENT' ]); } 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..d3cdfbf68f7 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,11 @@ 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', + 'components' => 'VEVENT' + ]); /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */ $card = $this->getMockBuilder(CardDavBackend::class) @@ -93,7 +105,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 +125,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 +144,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 +164,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 +177,11 @@ 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', + 'components' => 'VEVENT' + ]); /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */ $card = $this->getMockBuilder(CardDavBackend::class) @@ -165,7 +192,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 +214,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 +238,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']); } |