From 8572885da5f8e11dab7f95b0f14784d94baf30d9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 30 Sep 2022 15:33:01 +0200 Subject: [PATCH 1/2] Don't search in lobbied conversations Signed-off-by: Joas Schilling --- lib/Search/CurrentMessageSearch.php | 19 +++++++++++++++++++ lib/Search/MessageSearch.php | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Search/CurrentMessageSearch.php b/lib/Search/CurrentMessageSearch.php index 0b855c166a3..b27c58431d1 100644 --- a/lib/Search/CurrentMessageSearch.php +++ b/lib/Search/CurrentMessageSearch.php @@ -26,6 +26,8 @@ use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Exceptions\UnauthorizedException; +use OCA\Talk\Model\Attendee; +use OCA\Talk\Webinary; use OCP\IUser; use OCP\Search\ISearchQuery; use OCP\Search\SearchResult; @@ -87,6 +89,23 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { ); } + try { + $participant = $room->getParticipant($user->getUID(), false); + } catch (ParticipantNotFoundException $e) { + return SearchResult::complete( + $this->l->t('Messages'), + [] + ); + } + + if ($room->getLobbyState() !== Webinary::LOBBY_NONE && + !($participant->getPermissions() & Attendee::PERMISSIONS_LOBBY_IGNORE)) { + return SearchResult::complete( + $this->l->t('Messages'), + [] + ); + } + $offset = (int) $query->getCursor(); $comments = $this->chatManager->searchForObjects( $query->getTerm(), diff --git a/lib/Search/MessageSearch.php b/lib/Search/MessageSearch.php index bb1cf3c1a9a..6ceabc2ea30 100644 --- a/lib/Search/MessageSearch.php +++ b/lib/Search/MessageSearch.php @@ -31,6 +31,7 @@ use OCA\Talk\Manager as RoomManager; use OCA\Talk\Model\Attendee; use OCA\Talk\Room; +use OCA\Talk\Webinary; use OCP\Comments\IComment; use OCP\IL10N; use OCP\IURLGenerator; @@ -120,6 +121,13 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { continue; } + if ($room->getLobbyState() !== Webinary::LOBBY_NONE) { + $participant = $room->getParticipant($user->getUID(), false); + if (!($participant->getPermissions() & Attendee::PERMISSIONS_LOBBY_IGNORE)) { + continue; + } + } + $roomMap[(string) $room->getId()] = $room; } From e1de8d5f6c0ca3b8c3db65e77c400e93c0d14a12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 30 Sep 2022 17:12:38 +0200 Subject: [PATCH 2/2] Add integration test for search Signed-off-by: Joas Schilling --- .../features/bootstrap/FeatureContext.php | 51 +++++++++++++++++++ .../integration/features/chat/search.feature | 31 +++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tests/integration/features/chat/search.feature diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index ac8aa2a3a2d..7f4ed0482ce 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -1600,6 +1600,27 @@ public function userSeesTheFollowingMessagesInRoom($user, $identifier, $statusCo $this->compareDataResponse($formData); } + /** + * @Then /^user "([^"]*)" searches for "([^"]*)" in room "([^"]*)" with (\d+)(?: \((v1)\))?$/ + * + * @param string $user + * @param string $search + * @param string $identifier + * @param string $statusCode + * @param string $apiVersion + */ + public function userSearchesInRoom(string $user, string $search, string $identifier, $statusCode, string $apiVersion = 'v1', TableNode $formData = null): void { + $this->setCurrentUser($user); + $this->sendRequest('GET', '/search/providers/talk-message-current/search?term=' . $search . '&from=' . '/call/' . self::$identifierToToken[$identifier]); + $this->assertStatusCode($this->response, $statusCode); + + if ($statusCode !== '200') { + return; + } + + $this->compareSearchResponse($formData); + } + /** * @Then /^user "([^"]*)" sees the following shared (media|audio|voice|file|deckcard|location|other) in room "([^"]*)" with (\d+)(?: \((v1)\))?$/ * @@ -1730,6 +1751,36 @@ protected function compareDataResponse(TableNode $formData = null) { }, $messages)); } + /** + * @param TableNode|null $formData + */ + protected function compareSearchResponse(TableNode $formData = null) { + $messages = $this->getDataFromResponse($this->response)['entries']; + + if ($formData === null) { + Assert::assertEmpty($messages); + return; + } + + $expected = array_map(static function (array $message) { + $message['attributes.conversation'] = self::$identifierToToken[$message['attributes.conversation']]; + $message['attributes.messageId'] = self::$textToMessageId[$message['attributes.messageId']]; + return $message; + }, $formData->getHash()); + + $count = count($expected); + Assert::assertCount($count, $messages, 'Message count does not match'); + + Assert::assertEquals($expected, array_map(static function ($message) { + return [ + 'title' => $message['title'], + 'subline' => $message['subline'], + 'attributes.conversation' => $message['attributes']['conversation'], + 'attributes.messageId' => $message['attributes']['messageId'], + ]; + }, $messages)); + } + /** * @Then /^user "([^"]*)" sees the following system messages in room "([^"]*)" with (\d+)(?: \((v1)\))?$/ * diff --git a/tests/integration/features/chat/search.feature b/tests/integration/features/chat/search.feature new file mode 100644 index 00000000000..5dcdbad210d --- /dev/null +++ b/tests/integration/features/chat/search.feature @@ -0,0 +1,31 @@ + +Feature: chat/search + Background: + Given user "participant1" exists + Given user "participant2" exists + + Scenario: Can not search when not a participant + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "participant1" sends message "Message 1" to room "room" with 201 + When user "participant2" searches for "essa" in room "room" with 200 + + Scenario: Search for message when being a participant + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + And user "participant1" sends message "Message 1" to room "room" with 201 + When user "participant2" searches for "essa" in room "room" with 200 + | title | subline | attributes.conversation | attributes.messageId | + | participant1-displayname | Message 1 | room | Message 1 | + + Scenario: Can not search when being blocked by the lobby + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + And user "participant1" sends message "Message 1" to room "room" with 201 + And user "participant1" sets lobby state for room "room" to "non moderators" with 200 (v4) + When user "participant2" searches for "essa" in room "room" with 200