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 e4fdd86bfee..4e4a21860a7 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; @@ -126,6 +127,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; } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index bbc55fa6fde..0d96970da95 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -49,6 +49,8 @@ class FeatureContext implements Context, SnippetAcceptingContext { protected static $userToAttendeeId; /** @var array[] */ protected static $messages; + /** @var int[] */ + protected static $textToMessageId; protected static $permissionsMap = [ @@ -1489,6 +1491,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 "([^"]*)" received a system messages in room "([^"]*)" to delete "([^"]*)"(?: \((v1)\))?$/ * @@ -1587,6 +1610,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::$messages[$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