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

[stable30] fix(teams): Filter out already added teams from invite suggestions #14348

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
18 changes: 18 additions & 0 deletions lib/Collaboration/Collaborators/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ protected function filterExistingParticipants(string $token, array $results): ar
$results['exact']['users'] = array_filter($results['exact']['users'], [$this, 'filterParticipantUserResult']);
}

if (!empty($results['circles'])) {
$results['circles'] = array_filter($results['circles'], [$this, 'filterParticipantTeamResult']);
}
if (!empty($results['exact']['circles'])) {
$results['exact']['circles'] = array_filter($results['exact']['circles'], [$this, 'filterParticipantTeamResult']);
}

return $results;
}

Expand Down Expand Up @@ -166,4 +173,15 @@ protected function filterParticipantGroupResult(array $result): bool {
return true;
}
}

protected function filterParticipantTeamResult(array $result): bool {
$circleId = $result['value']['shareWith'];

try {
$this->participantService->getParticipantByActor($this->room, Attendee::ACTOR_CIRCLES, $circleId);
return false;
} catch (ParticipantNotFoundException $e) {
return true;
}
}
}
27 changes: 17 additions & 10 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3479,12 +3479,18 @@ public function userGetsTheFollowingCandidateMentionsInRoomFor($user, $identifie
* @param string $apiVersion
* @param TableNode|null $formData
*/
public function userGetsTheFollowingCollaboratorSuggestions($user, $identifier, $search, $statusCode, $apiVersion = 'v1', ?TableNode $formData = null) {
public function userGetsTheFollowingCollaboratorSuggestions($user, $identifier, $search, $statusCode, ?TableNode $formData = null) {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/core/autocomplete/get?search=' . $search . '&itemType=call&itemId=' . self::$identifierToToken[$identifier] . '&shareTypes[]=0&shareTypes[]=1&shareTypes[]=7&shareTypes[]=4');
$this->assertStatusCode($this->response, $statusCode);

$mentions = $this->getDataFromResponse($this->response);
$mentions = array_map(static function (array $mention): array {
unset($mention['icon']);
unset($mention['status']);
unset($mention['subline']);
unset($mention['shareWithDisplayNameUnique']);
return $mention;
}, $this->getDataFromResponse($this->response));

if ($formData === null) {
Assert::assertEmpty($mentions);
Expand All @@ -3500,21 +3506,22 @@ public function userGetsTheFollowingCollaboratorSuggestions($user, $identifier,
return $a['source'] <=> $b['source'];
});

$expected = $formData->getHash();
$expected = array_map(function (array $mention): array {
$result = preg_match('/TEAM_ID\(([^)]+)\)/', $mention['id'], $matches);
if ($result) {
$mention['id'] = self::$createdTeams[$this->currentServer][$matches[1]];
}
return $mention;
}, $formData->getHash());

usort($expected, function ($a, $b) {
if ($a['source'] === $b['source']) {
return $a['label'] <=> $b['label'];
}
return $a['source'] <=> $b['source'];
});

foreach ($expected as $key => $row) {
unset($mentions[$key]['icon']);
unset($mentions[$key]['status']);
unset($mentions[$key]['subline']);
unset($mentions[$key]['shareWithDisplayNameUnique']);
Assert::assertEquals($row, $mentions[$key]);
}
Assert::assertEquals($expected, $mentions);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/features/conversation-1/add-participant.feature
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ Feature: conversation/add-participant
| source | id | label |
| users | participant2 | participant2-displayname |

Scenario: Filter out already added entries
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
And group "Filtered group" exists
And team "Filtered team" exists
And add user "participant1" to team "Filtered team"
When user "participant1" gets the following collaborator suggestions in room "room" for "Filtered" with 200
| source | id | label |
| circles | TEAM_ID(Filtered team) | Filtered team |
| groups | Filtered group | Filtered group |
And user "participant1" adds group "Filtered group" to room "room" with 200 (v4)
And user "participant1" adds team "Filtered team" to room "room" with 200 (v4)
When user "participant1" gets the following collaborator suggestions in room "room" for "Filtered" with 200
| source | id | label |

Scenario: Getting participant suggestions in a public room
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
Expand Down
Loading