Skip to content

Commit

Permalink
Merge pull request #49731 from nextcloud/bugfix/noid/allow-to-get-per…
Browse files Browse the repository at this point in the history
…missions-of-a-principal

fix(calendar): Fix getting the permissions of the user
  • Loading branch information
nickvergessen authored Dec 16, 2024
2 parents b9da727 + fddbc54 commit f9ee350
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion apps/dav/lib/CalDAV/CalendarImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -133,7 +137,7 @@ public function getPermissions(): int {
public function isWritable(): bool {
return $this->calendar->canWrite();
}

/**
* @since 26.0.0
*/
Expand Down
19 changes: 13 additions & 6 deletions apps/dav/tests/unit/CalDAV/CalendarImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Calendar/ICalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f9ee350

Please sign in to comment.