3434use OCP \IGroupManager ;
3535use OCP \IUser ;
3636use OCP \IUserManager ;
37+ use OCP \Share \IManager as IShareManager ;
3738use Sabre \DAV \Exception ;
3839use \Sabre \DAV \PropPatch ;
3940use 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 ) {
0 commit comments