Browse Source

implement principal property search for calendar user address set property

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
tags/v16.0.0beta1
Georg Ehrke 5 years ago
parent
commit
d74e49b3e6
No account linked to committer's email address

+ 8
- 0
apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php View File

@@ -244,6 +244,14 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
$stmt->closeCursor();
break;

case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set':
// If you add support for more search properties that qualify as a user-address,
// please also add them to the array below
$results[] = $this->searchPrincipals($this->principalPrefix, [
'{http://sabredav.org/ns}email-address' => $value,
], 'anyof');
break;

default:
$results[] = [];
break;

+ 10
- 0
apps/dav/lib/Connector/Sabre/Principal.php View File

@@ -287,6 +287,16 @@ class Principal implements BackendInterface {
}, []);
break;

case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set':
// If you add support for more search properties that qualify as a user-address,
// please also add them to the array below
$results[] = $this->searchUserPrincipals([
// In theory this should also search for principal:principals/users/...
// but that's used internally only anyway and i don't know of any client querying that
'{http://sabredav.org/ns}email-address' => $value,
], 'anyof');
break;

default:
$results[] = [];
break;

+ 7
- 0
apps/dav/lib/DAV/GroupPrincipalBackend.php View File

@@ -222,6 +222,13 @@ class GroupPrincipalBackend implements BackendInterface {
}, []);
break;

case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set':
// If you add support for more search properties that qualify as a user-address,
// please also add them to the array below
$results[] = $this->searchPrincipals(self::PRINCIPAL_PREFIX, [
], 'anyof');
break;

default:
$results[] = [];
break;

+ 119
- 0
apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php View File

@@ -519,6 +519,125 @@ abstract class AbstractPrincipalBackendTest extends TestCase {
];
}

public function testSearchPrincipalsByCalendarUserAddressSet() {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->exactly(2))
->method('getUser')
->with()
->will($this->returnValue($user));
$this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds')
->with($user)
->will($this->returnValue(['group1', 'group2']));

$queryBuilder1 = $this->createMock(IQueryBuilder::class);
$stmt1 = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
$expr1 = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);

$this->dbConnection->expects($this->at(0))
->method('getQueryBuilder')
->with()
->will($this->returnValue($queryBuilder1));
$this->dbConnection->expects($this->at(1))
->method('escapeLikeParameter')
->with('foo')
->will($this->returnValue('escapedFoo'));

$queryBuilder1->method('expr')
->will($this->returnValue($expr1));

$expr1->method('iLike')
->will($this->returnValueMap([
['email', 'createNamedParameter-1', null, 'ILIKE_CLAUSE_1'],
]));

$queryBuilder1->method('expr')
->will($this->returnValue($expr1));

$queryBuilder1->method('createNamedParameter')
->will($this->returnValueMap([
['%escapedFoo%', \PDO::PARAM_STR, null, 'createNamedParameter-1'],
]));

$queryBuilder1->expects($this->at(0))
->method('select')
->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions'])
->will($this->returnValue($queryBuilder1));
$queryBuilder1->expects($this->at(1))
->method('from')
->with($this->expectedDbTable)
->will($this->returnValue($queryBuilder1));
$queryBuilder1->expects($this->at(4))
->method('where')
->with('ILIKE_CLAUSE_1')
->will($this->returnValue($queryBuilder1));
$queryBuilder1->expects($this->at(5))
->method('execute')
->with()
->will($this->returnValue($stmt1));

$stmt1->expects($this->at(0))
->method('fetch')
->with(\PDO::FETCH_ASSOC)
->will($this->returnValue([
'id' => 0,
'backend_id' => 'db',
'resource_id' => '1',
'email' => '1',
'displayname' => 'Resource 1',
'group_restrictions' => null,
]));
$stmt1->expects($this->at(1))
->method('fetch')
->with(\PDO::FETCH_ASSOC)
->will($this->returnValue([
'id' => 1,
'backend_id' => 'db',
'resource_id' => '2',
'email' => '2',
'displayname' => 'Resource 2',
'group_restrictions' => '',
]));
$stmt1->expects($this->at(2))
->method('fetch')
->with(\PDO::FETCH_ASSOC)
->will($this->returnValue([
'id' => 2,
'backend_id' => 'db',
'resource_id' => '3',
'email' => '3',
'displayname' => 'Resource 3',
'group_restrictions' => '["group3"]',
]));
$stmt1->expects($this->at(3))
->method('fetch')
->with(\PDO::FETCH_ASSOC)
->will($this->returnValue([
'id' => 99,
'backend_id' => 'db',
'resource_id' => '99',
'email' => '99',
'displayname' => 'Resource 99',
'group_restrictions' => '["group1", "group2"]',
]));
$stmt1->expects($this->at(4))
->method('fetch')
->with(\PDO::FETCH_ASSOC)
->will($this->returnValue(null));

$actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'foo',
]);

$this->assertEquals(
str_replace('%prefix%', $this->principalPrefix, [
'%prefix%/db-1',
'%prefix%/db-2',
'%prefix%/db-99',
]),
$actual);
}

public function testSearchPrincipalsEmptySearchProperties() {
$this->userSession->expects($this->never())
->method('getUser');

+ 26
- 0
apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php View File

@@ -391,6 +391,32 @@ class PrincipalTest extends TestCase {
];
}

public function testSearchPrincipalByCalendarUserAddressSet() {
$this->shareManager->expects($this->exactly(2))
->method('shareAPIEnabled')
->will($this->returnValue(true));

$this->shareManager->expects($this->exactly(2))
->method('shareWithGroupMembersOnly')
->will($this->returnValue(false));

$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->will($this->returnValue('user2'));
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->will($this->returnValue('user3'));

$this->userManager->expects($this->at(0))
->method('getByEmail')
->with('user@example.com')
->will($this->returnValue([$user2, $user3]));

$this->assertEquals([
'principals/users/user2',
'principals/users/user3',
], $this->connector->searchPrincipals('principals/users',
['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'user@example.com']));
}

public function testFindByUriSharingApiDisabled() {
$this->shareManager->expects($this->once())
->method('shareApiEnabled')

Loading…
Cancel
Save