Skip to content

Commit

Permalink
search users with collaborators
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed May 14, 2020
1 parent 05d0920 commit 08821d0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 16 deletions.
57 changes: 56 additions & 1 deletion lib/Search/LocalUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,50 @@

namespace OCA\Circles\Search;

use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Circles\ISearch;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SearchResult;
use OCA\Circles\Service\ConfigService;
use OCP\Collaboration\Collaborators\ISearch as ICollaboratorSearch;
use OCP\Share\IShare;

class LocalUsers implements ISearch {


use TArrayTools;


/** @var ICollaboratorSearch */
private $search;

/** @var ConfigService */
private $configService;


/**
* LocalUsers constructor.
*
* @param ICollaboratorSearch $search
* @param ConfigService $configService
*/
public function __construct(ICollaboratorSearch $search, ConfigService $configService) {
$this->search = $search;
$this->configService = $configService;
}


/**
* {@inheritdoc}
*/
public function search($search) {

$result = [];
$userManager = \OC::$server->getUserManager();

if ($this->configService->getAppValue(ConfigService::CIRCLES_SEARCH_FROM_COLLABORATOR) === '1') {
return $this->searchFromCollaborator($search);
}

$users = $userManager->search($search);
foreach ($users as $user) {
$result[] =
Expand All @@ -50,6 +80,31 @@ public function search($search) {

return $result;
}


/**
* @param $search
*
* @return array
*/
private function searchFromCollaborator($search): array {
list($temp, $hasMore) = $this->search->search($search, [IShare::TYPE_USER], false, 50, 0);

$result = array_merge($temp['exact']['users'], $temp['users']);
$parsed = [];
foreach ($result as $entry) {
$parsed[] =
new SearchResult(
$this->get('value.shareWith', $entry),
Member::TYPE_USER,
'',
['display' => $this->get('label', $entry)]
);
}

return $parsed;
}

}


32 changes: 17 additions & 15 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ConfigService {
const CIRCLES_SELF_SIGNED = 'self_signed_cert';
const CIRCLES_ACTIVITY_ON_CREATION = 'creation_activity';
const CIRCLES_SKIP_INVITATION_STEP = 'skip_invitation_to_closed_circles';
const CIRCLES_SEARCH_FROM_COLLABORATOR = 'search_from_collaborator';
const CIRCLES_TEST_ASYNC_LOCK = 'test_async_lock';
const CIRCLES_TEST_ASYNC_INIT = 'test_async_init';
const CIRCLES_TEST_ASYNC_HAND = 'test_async_hand';
Expand All @@ -61,21 +62,22 @@ class ConfigService {


private $defaults = [
self::CIRCLES_ALLOW_CIRCLES => Circle::CIRCLES_ALL,
self::CIRCLES_CONTACT_BACKEND => '0',
self::CIRCLES_STILL_FRONTEND => '0',
self::CIRCLES_TEST_ASYNC_INIT => '0',
self::CIRCLES_SWAP_TO_TEAMS => '0',
self::CIRCLES_ACCOUNTS_ONLY => '0',
self::CIRCLES_MEMBERS_LIMIT => '50',
self::CIRCLES_ALLOW_LINKED_GROUPS => '0',
self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0',
self::CIRCLES_GS_ENABLED => '0',
self::CIRCLES_ALLOW_NON_SSL_LINKS => '0',
self::CIRCLES_NON_SSL_LOCAL => '0',
self::CIRCLES_SELF_SIGNED => '0',
self::CIRCLES_ACTIVITY_ON_CREATION => '1',
self::CIRCLES_SKIP_INVITATION_STEP => '0'
self::CIRCLES_ALLOW_CIRCLES => Circle::CIRCLES_ALL,
self::CIRCLES_CONTACT_BACKEND => '0',
self::CIRCLES_STILL_FRONTEND => '0',
self::CIRCLES_TEST_ASYNC_INIT => '0',
self::CIRCLES_SWAP_TO_TEAMS => '0',
self::CIRCLES_ACCOUNTS_ONLY => '0',
self::CIRCLES_MEMBERS_LIMIT => '50',
self::CIRCLES_ALLOW_LINKED_GROUPS => '0',
self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0',
self::CIRCLES_GS_ENABLED => '0',
self::CIRCLES_ALLOW_NON_SSL_LINKS => '0',
self::CIRCLES_NON_SSL_LOCAL => '0',
self::CIRCLES_SELF_SIGNED => '0',
self::CIRCLES_ACTIVITY_ON_CREATION => '1',
self::CIRCLES_SKIP_INVITATION_STEP => '0',
self::CIRCLES_SEARCH_FROM_COLLABORATOR => '0'
];

/** @var string */
Expand Down

0 comments on commit 08821d0

Please sign in to comment.