Merge pull request #49731 from nextcloud/bugfix/noid/allow-to-get-permissions-of-a-principal

fix(calendar): Fix getting the permissions of the user
pull/49847/head
Joas Schilling 2024-12-16 15:02:51 +07:00 committed by GitHub
commit f9ee3505a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

@ -110,6 +110,10 @@ class CalendarImpl implements ICreateFromString, IHandleImipMessage {
$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 @@ class CalendarImpl implements ICreateFromString, IHandleImipMessage {
public function isWritable(): bool {
return $this->calendar->canWrite();
}
/**
* @since 26.0.0
*/

@ -40,7 +40,8 @@ class CalendarImplTest extends \Test\TestCase {
'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 @@ class CalendarImplTest extends \Test\TestCase {
->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 @@ class CalendarImplTest extends \Test\TestCase {
->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 @@ class CalendarImplTest extends \Test\TestCase {
->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 @@ class CalendarImplTest extends \Test\TestCase {
->method('getACL')
->with()
->willReturn([
['privilege' => '{DAV:}all']
['privilege' => '{DAV:}all', 'principal' => 'principal/users/foobar'],
]);
$this->assertEquals(31, $this->calendarImpl->getPermissions());

@ -53,7 +53,7 @@ interface ICalendar {
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;