@@ -36,82 +36,82 @@ |
||
36 | 36 | |
37 | 37 | class LookupPlugin implements ISearchPlugin { |
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
41 | - /** @var IClientService */ |
|
42 | - private $clientService; |
|
43 | - /** @var string remote part of the current user's cloud id */ |
|
44 | - private $currentUserRemote; |
|
45 | - /** @var ICloudIdManager */ |
|
46 | - private $cloudIdManager; |
|
47 | - /** @var ILogger */ |
|
48 | - private $logger; |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | + /** @var IClientService */ |
|
42 | + private $clientService; |
|
43 | + /** @var string remote part of the current user's cloud id */ |
|
44 | + private $currentUserRemote; |
|
45 | + /** @var ICloudIdManager */ |
|
46 | + private $cloudIdManager; |
|
47 | + /** @var ILogger */ |
|
48 | + private $logger; |
|
49 | 49 | |
50 | - public function __construct(IConfig $config, |
|
51 | - IClientService $clientService, |
|
52 | - IUserSession $userSession, |
|
53 | - ICloudIdManager $cloudIdManager, |
|
54 | - ILogger $logger) { |
|
55 | - $this->config = $config; |
|
56 | - $this->clientService = $clientService; |
|
57 | - $this->cloudIdManager = $cloudIdManager; |
|
58 | - $currentUserCloudId = $userSession->getUser()->getCloudId(); |
|
59 | - $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); |
|
60 | - $this->logger = $logger; |
|
61 | - } |
|
50 | + public function __construct(IConfig $config, |
|
51 | + IClientService $clientService, |
|
52 | + IUserSession $userSession, |
|
53 | + ICloudIdManager $cloudIdManager, |
|
54 | + ILogger $logger) { |
|
55 | + $this->config = $config; |
|
56 | + $this->clientService = $clientService; |
|
57 | + $this->cloudIdManager = $cloudIdManager; |
|
58 | + $currentUserCloudId = $userSession->getUser()->getCloudId(); |
|
59 | + $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); |
|
60 | + $this->logger = $logger; |
|
61 | + } |
|
62 | 62 | |
63 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
64 | - $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
|
65 | - $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; |
|
66 | - // if case of Global Scale we always search the lookup server |
|
67 | - if (!$isLookupServerEnabled && !$isGlobalScaleEnabled) { |
|
68 | - return false; |
|
69 | - } |
|
63 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
64 | + $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
|
65 | + $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; |
|
66 | + // if case of Global Scale we always search the lookup server |
|
67 | + if (!$isLookupServerEnabled && !$isGlobalScaleEnabled) { |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | - $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
72 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
73 | - $result = []; |
|
71 | + $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
72 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
73 | + $result = []; |
|
74 | 74 | |
75 | - try { |
|
76 | - $client = $this->clientService->newClient(); |
|
77 | - $response = $client->get( |
|
78 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
79 | - [ |
|
80 | - 'timeout' => 10, |
|
81 | - 'connect_timeout' => 3, |
|
82 | - ] |
|
83 | - ); |
|
75 | + try { |
|
76 | + $client = $this->clientService->newClient(); |
|
77 | + $response = $client->get( |
|
78 | + $lookupServerUrl . '/users?search=' . urlencode($search), |
|
79 | + [ |
|
80 | + 'timeout' => 10, |
|
81 | + 'connect_timeout' => 3, |
|
82 | + ] |
|
83 | + ); |
|
84 | 84 | |
85 | - $body = json_decode($response->getBody(), true); |
|
85 | + $body = json_decode($response->getBody(), true); |
|
86 | 86 | |
87 | - foreach ($body as $lookup) { |
|
88 | - try { |
|
89 | - $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
|
90 | - } catch (\Exception $e) { |
|
91 | - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
|
92 | - $this->logger->error($e->getMessage()); |
|
93 | - continue; |
|
94 | - } |
|
95 | - if ($this->currentUserRemote === $remote) { |
|
96 | - continue; |
|
97 | - } |
|
98 | - $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
|
99 | - $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
100 | - $result[] = [ |
|
101 | - 'label' => $label, |
|
102 | - 'value' => [ |
|
103 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
104 | - 'shareWith' => $lookup['federationId'], |
|
105 | - ], |
|
106 | - 'extra' => $lookup, |
|
107 | - ]; |
|
108 | - } |
|
109 | - } catch (\Exception $e) { |
|
110 | - } |
|
87 | + foreach ($body as $lookup) { |
|
88 | + try { |
|
89 | + $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
|
90 | + } catch (\Exception $e) { |
|
91 | + $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
|
92 | + $this->logger->error($e->getMessage()); |
|
93 | + continue; |
|
94 | + } |
|
95 | + if ($this->currentUserRemote === $remote) { |
|
96 | + continue; |
|
97 | + } |
|
98 | + $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
|
99 | + $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
100 | + $result[] = [ |
|
101 | + 'label' => $label, |
|
102 | + 'value' => [ |
|
103 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
104 | + 'shareWith' => $lookup['federationId'], |
|
105 | + ], |
|
106 | + 'extra' => $lookup, |
|
107 | + ]; |
|
108 | + } |
|
109 | + } catch (\Exception $e) { |
|
110 | + } |
|
111 | 111 | |
112 | - $type = new SearchResultType('lookup'); |
|
113 | - $searchResult->addResultSet($type, $result, []); |
|
112 | + $type = new SearchResultType('lookup'); |
|
113 | + $searchResult->addResultSet($type, $result, []); |
|
114 | 114 | |
115 | - return false; |
|
116 | - } |
|
115 | + return false; |
|
116 | + } |
|
117 | 117 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | try { |
76 | 76 | $client = $this->clientService->newClient(); |
77 | 77 | $response = $client->get( |
78 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
78 | + $lookupServerUrl.'/users?search='.urlencode($search), |
|
79 | 79 | [ |
80 | 80 | 'timeout' => 10, |
81 | 81 | 'connect_timeout' => 3, |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | try { |
89 | 89 | $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
90 | 90 | } catch (\Exception $e) { |
91 | - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
|
91 | + $this->logger->error('Can not parse federated cloud ID "'.$lookup['federationId'].'"'); |
|
92 | 92 | $this->logger->error($e->getMessage()); |
93 | 93 | continue; |
94 | 94 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
99 | - $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
99 | + $label = empty($name) ? $lookup['federationId'] : $name.' ('.$lookup['federationId'].')'; |
|
100 | 100 | $result[] = [ |
101 | 101 | 'label' => $label, |
102 | 102 | 'value' => [ |