From 4fd84e47bf01958058f6e26b5655fa3671e15f67 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 9 Dec 2024 11:33:12 +0100 Subject: [PATCH 1/2] fix(calendar): Fix getting the permissions of the user Signed-off-by: Joas Schilling --- apps/dav/lib/CalDAV/CalendarImpl.php | 6 +++++- lib/public/Calendar/ICalendar.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalendarImpl.php b/apps/dav/lib/CalDAV/CalendarImpl.php index 919b08eefce2b..b3062f005ee27 100644 --- a/apps/dav/lib/CalDAV/CalendarImpl.php +++ b/apps/dav/lib/CalDAV/CalendarImpl.php @@ -110,6 +110,10 @@ public function getPermissions(): int { $permissions = $this->calendar->getACL(); $result = 0; foreach ($permissions as $permission) { + if ($this->calendarInfo['principaluri'] !== $permission['principal']) { + continue; + } + switch ($permission['privilege']) { case '{DAV:}read': $result |= Constants::PERMISSION_READ; @@ -133,7 +137,7 @@ public function getPermissions(): int { public function isWritable(): bool { return $this->calendar->canWrite(); } - + /** * @since 26.0.0 */ diff --git a/lib/public/Calendar/ICalendar.php b/lib/public/Calendar/ICalendar.php index f29d6f3017636..2dfc1ca632f43 100644 --- a/lib/public/Calendar/ICalendar.php +++ b/lib/public/Calendar/ICalendar.php @@ -53,7 +53,7 @@ public function getDisplayColor(): ?string; public function search(string $pattern, array $searchProperties = [], array $options = [], ?int $limit = null, ?int $offset = null): array; /** - * @return int build up using \OCP\Constants + * @return int build up using {@see \OCP\Constants} * @since 13.0.0 */ public function getPermissions(): int; From fddbc54003996c59302ed459c361118e99a52b6f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Dec 2024 08:36:25 +0100 Subject: [PATCH 2/2] test: Adjust tests to proof exclusion of other principal permissions Signed-off-by: Joas Schilling --- .../tests/unit/CalDAV/CalendarImplTest.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php index a0b2965f22376..ee9b85fafe8b5 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php @@ -40,7 +40,8 @@ protected function setUp(): void { 'id' => 'fancy_id_123', '{DAV:}displayname' => 'user readable name 123', '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', - 'uri' => '/this/is/a/uri' + 'uri' => '/this/is/a/uri', + 'principaluri' => 'principal/users/foobar' ]; $this->backend = $this->createMock(CalDavBackend::class); @@ -76,7 +77,10 @@ public function testGetPermissionRead(): void { ->method('getACL') ->with() ->willReturn([ - ['privilege' => '{DAV:}read'] + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/foobar'], + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/other'], + ['privilege' => '{DAV:}write', 'principal' => 'principal/users/other'], + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], ]); $this->assertEquals(1, $this->calendarImpl->getPermissions()); @@ -87,7 +91,9 @@ public function testGetPermissionWrite(): void { ->method('getACL') ->with() ->willReturn([ - ['privilege' => '{DAV:}write'] + ['privilege' => '{DAV:}write', 'principal' => 'principal/users/foobar'], + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/other'], + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], ]); $this->assertEquals(6, $this->calendarImpl->getPermissions()); @@ -98,8 +104,9 @@ public function testGetPermissionReadWrite(): void { ->method('getACL') ->with() ->willReturn([ - ['privilege' => '{DAV:}read'], - ['privilege' => '{DAV:}write'] + ['privilege' => '{DAV:}write', 'principal' => 'principal/users/foobar'], + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/foobar'], + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], ]); $this->assertEquals(7, $this->calendarImpl->getPermissions()); @@ -110,7 +117,7 @@ public function testGetPermissionAll(): void { ->method('getACL') ->with() ->willReturn([ - ['privilege' => '{DAV:}all'] + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/foobar'], ]); $this->assertEquals(31, $this->calendarImpl->getPermissions());