Skip to content

Commit 63a3e72

Browse files
committed
Principal search: Take sharing settings into account
1 parent 28b9e65 commit 63a3e72

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

apps/dav/lib/Connector/Sabre/Principal.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCP\IGroupManager;
3535
use OCP\IUser;
3636
use OCP\IUserManager;
37+
use OCP\Share\IManager as IShareManager;
3738
use Sabre\DAV\Exception;
3839
use \Sabre\DAV\PropPatch;
3940
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
@@ -47,6 +48,9 @@ class Principal implements BackendInterface {
4748
/** @var IGroupManager */
4849
private $groupManager;
4950

51+
/** @var IShareManager */
52+
private $shareManager;
53+
5054
/** @var string */
5155
private $principalPrefix;
5256

@@ -56,13 +60,16 @@ class Principal implements BackendInterface {
5660
/**
5761
* @param IUserManager $userManager
5862
* @param IGroupManager $groupManager
63+
* @param IShareManager $shareManager
5964
* @param string $principalPrefix
6065
*/
6166
public function __construct(IUserManager $userManager,
6267
IGroupManager $groupManager,
68+
IShareManager $shareManager,
6369
$principalPrefix = 'principals/users/') {
6470
$this->userManager = $userManager;
6571
$this->groupManager = $groupManager;
72+
$this->shareManager = $shareManager;
6673
$this->principalPrefix = trim($principalPrefix, '/');
6774
$this->hasGroups = ($principalPrefix === 'principals/users/');
6875
}
@@ -192,7 +199,17 @@ function updatePrincipal($path, PropPatch $propPatch) {
192199
function searchUserPrincipals(array $searchProperties, $test = 'allof') {
193200
$results = [];
194201

195-
//TODO: If more properties should be supported, hook this up to a db query
202+
// If sharing is disabled, return the empty array
203+
if (!$this->shareManager->shareApiEnabled()) {
204+
return $results;
205+
}
206+
207+
// If sharing is restricted to group members only,
208+
// return only members that have groups in common
209+
if ($this->shareManager->shareWithGroupMembersOnly()) {
210+
// TODO - who is performing the search?
211+
}
212+
196213
foreach ($searchProperties as $prop => $value) {
197214
switch ($prop) {
198215
case '{http://sabredav.org/ns}email-address':
@@ -207,19 +224,20 @@ function searchUserPrincipals(array $searchProperties, $test = 'allof') {
207224
}
208225
}
209226

210-
if (count($results) == 1) {
227+
// results is an array of arrays, so this is not the first search result
228+
// but the results of the first searchProperty
229+
if (count($results) === 1) {
211230
return $results[0];
212231
}
213232

214233
switch ($test) {
215-
case 'allof':
216-
217-
return array_intersect(...$results);
218234
case 'anyof':
219235
return array_unique(array_merge(...$results));
220-
}
221236

222-
return [];
237+
case 'allof':
238+
default:
239+
return array_intersect(...$results);
240+
}
223241
}
224242

225243
/**
@@ -247,8 +265,8 @@ function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
247265
* @return string
248266
*/
249267
function findByUri($uri, $principalPrefix) {
250-
if (substr($uri, 0, 7) === 'mailto:') {
251-
if ($principalPrefix === principals/users) {
268+
if (strpos($uri, 'mailto:') === 0) {
269+
if ($principalPrefix === 'principals/users') {
252270
$email = substr($uri, 7);
253271
$users = $this->userManager->getByEmail($email);
254272
if (count($users) === 1) {

apps/dav/lib/RootCollection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ public function __construct() {
4343
$logger = \OC::$server->getLogger();
4444
$userManager = \OC::$server->getUserManager();
4545
$groupManager = \OC::$server->getGroupManager();
46+
$shareManager = \OC::$server->getShareManager();
4647
$db = \OC::$server->getDatabaseConnection();
4748
$dispatcher = \OC::$server->getEventDispatcher();
4849
$userPrincipalBackend = new Principal(
4950
$userManager,
50-
$groupManager
51+
$groupManager,
52+
$shareManager
5153
);
5254
$groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
5355
// as soon as debug mode is enabled we allow listing of principals

0 commit comments

Comments
 (0)