Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Collaboration): Deduplicate email shares if remote share with same label exists #50466

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function registerPlugin(array $pluginInfo): void {
$this->pluginList[$shareType][] = $pluginInfo['class'];
}

/**
* Removes all mail shares where a remote share with the same label exists.
* Remote shares are considered "better" than mail shares, so we hide the "worse" shares in case both are possible.
*/
protected function dropMailSharesWhereRemoteShareIsPossible(ISearchResult $searchResult): void {
$allResults = $searchResult->asArray();

Expand All @@ -98,21 +102,14 @@ protected function dropMailSharesWhereRemoteShareIsPossible(ISearchResult $searc
return;
}

$mailIdMap = [];
$mails = [];
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'];
$mails[] = $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']]);
foreach ($allResults[$remoteType->getLabel()] as $remoteRow) {
if (in_array($remoteRow['value']['shareWith'], $mails, true)) {
$searchResult->removeCollaboratorResult($emailType, $remoteRow['value']['shareWith']);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Collaboration/Collaborators/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function removeCollaboratorResult(SearchResultType $type, string $collabo
foreach ($resultArray as $k => $result) {
if ($result['value']['shareWith'] === $collaboratorId) {
unset($resultArray[$k]);
// Ensure no gaps after removing the result
$resultArray = array_values($resultArray);
$actionDone = true;
}
}
Expand Down
36 changes: 36 additions & 0 deletions tests/lib/Collaboration/Collaborators/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,42 @@ public function dataSearchSharees() {
],
false, // expected more results indicator
],
// Remove emails if there is a remote with same label even if non exact match
[
'test@example',
[IShare::TYPE_REMOTE, IShare::TYPE_EMAIL],
1,
10,
[],
[],
[
'results' => [
['label' => 'remote', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => '[email protected]']],
['label' => 'remote', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => '[email protected]']],
],
'exact' => [],
'exactIdMatch' => false,
],
[
['label' => 'email', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
['label' => 'email', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
],
[
'exact' => [
'remotes' => [],
'emails' => [],
],
'remotes' => [
['label' => 'remote', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => '[email protected]']],
['label' => 'remote', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => '[email protected]']],
],
'emails' => [
// [email protected] email is not present
['label' => 'email', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
]
],
false,
],
];
}
}
Loading