diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-04-13 22:49:42 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-04-20 14:02:35 +0200 |
commit | f8d1ee5cfac5405713cc3fdc194cb98d748ec79f (patch) | |
tree | 7f9dae5802e63f4c073bc7ac6ad758efa7fd197d /lib | |
parent | 9d1e2c50823fc2a2a1763e1153c0c18bce8fbddd (diff) | |
download | nextcloud-server-f8d1ee5cfac5405713cc3fdc194cb98d748ec79f.tar.gz nextcloud-server-f8d1ee5cfac5405713cc3fdc194cb98d748ec79f.zip |
ignore mail shares of related remote share results
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Collaboration/Collaborators/Search.php | 36 | ||||
-rw-r--r-- | lib/private/Collaboration/Collaborators/SearchResult.php | 20 | ||||
-rw-r--r-- | lib/public/Collaboration/Collaborators/ISearchResult.php | 8 |
3 files changed, 62 insertions, 2 deletions
diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index 79dfd5e1d82..87463572944 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -81,8 +81,8 @@ class Search implements ISearch { // sanitizing, could go into the plugins as well - // if we have a exact match, either for the federated cloud id or for the - // email address we only return the exact match. It is highly unlikely + // if we have an exact match, either for the federated cloud id or for the + // email address, we only return the exact match. It is highly unlikely // that the exact same email address and federated cloud id exists $emailType = new SearchResultType('emails'); $remoteType = new SearchResultType('remotes'); @@ -92,6 +92,8 @@ class Search implements ISearch { $searchResult->unsetResult($emailType); } + $this->dropMailSharesWhereRemoteShareIsPossible($searchResult); + // if we have an exact local user match with an email-a-like query, // there is no need to show the remote and email matches. $userType = new SearchResultType('users'); @@ -110,4 +112,34 @@ class Search implements ISearch { } $this->pluginList[$shareType][] = $pluginInfo['class']; } + + protected function dropMailSharesWhereRemoteShareIsPossible(ISearchResult $searchResult): void { + $allResults = $searchResult->asArray(); + + $emailType = new SearchResultType('emails'); + $remoteType = new SearchResultType('remotes'); + + if (!isset($allResults[$remoteType->getLabel()]) + || !isset($allResults[$emailType->getLabel()])) { + return; + } + + $mailIdMap = []; + foreach ($allResults[$emailType->getLabel()] as $mailRow) { + // sure, array_reduce looks nicer, but foreach needs less resources and is faster + if (!isset($mailRow['uuid'])) { + continue; + } + $mailIdMap[$mailRow['uuid']] = $mailRow['value']['shareWith']; + } + + foreach ($allResults[$remoteType->getLabel()] as $resultRow) { + if (!isset($resultRow['uuid'])) { + continue; + } + if (isset($mailIdMap[$resultRow['uuid']])) { + $searchResult->removeCollaboratorResult($emailType, $mailIdMap[$resultRow['uuid']]); + } + } + } } diff --git a/lib/private/Collaboration/Collaborators/SearchResult.php b/lib/private/Collaboration/Collaborators/SearchResult.php index 8e2c5a1ff39..e9511f869fa 100644 --- a/lib/private/Collaboration/Collaborators/SearchResult.php +++ b/lib/private/Collaboration/Collaborators/SearchResult.php @@ -85,4 +85,24 @@ class SearchResult implements ISearchResult { $this->result['exact'][$type] = []; } } + + public function removeCollaboratorResult(SearchResultType $type, string $collaboratorId): bool { + $type = $type->getLabel(); + if (!isset($this->result[$type])) { + return false; + } + + $actionDone = false; + $resultArrays = [&$this->result['exact'][$type], &$this->result[$type]]; + foreach ($resultArrays as &$resultArray) { + foreach ($resultArray as $k => $result) { + if ($result['value']['shareWith'] === $collaboratorId) { + unset($resultArray[$k]); + $actionDone = true; + } + } + } + + return $actionDone; + } } diff --git a/lib/public/Collaboration/Collaborators/ISearchResult.php b/lib/public/Collaboration/Collaborators/ISearchResult.php index d0d61ccfb28..a559892bb47 100644 --- a/lib/public/Collaboration/Collaborators/ISearchResult.php +++ b/lib/public/Collaboration/Collaborators/ISearchResult.php @@ -46,6 +46,14 @@ interface ISearchResult { public function hasResult(SearchResultType $type, $collaboratorId); /** + * Removes all result where $collaborationId exactly matches shareWith of + * any of wide and exact result matches of the given type. + * + * @since 22.0.0 + */ + public function removeCollaboratorResult(SearchResultType $type, string $collaboratorId): bool; + + /** * @param SearchResultType $type * @since 13.0.0 */ |