feat: skip inbox filter if the user has access to all inboxes (#12043)

This commit is contained in:
Shivam Mishra
2025-07-25 13:59:10 +04:00
committed by GitHub
parent 87313ecc35
commit c09e875c83
2 changed files with 29 additions and 4 deletions

View File

@@ -213,15 +213,32 @@ describe SearchService do
account_user.update!(role: 'agent')
end
it 'filters by accessible inbox_id' do
# Testing the private method itself seems like the best way to ensure
# that the inboxes are not added to the search query
it 'filters by accessible inbox_id when user has limited access' do
# Create an additional inbox that user is NOT assigned to
create(:inbox, account: account)
base_query = search.send(:message_base_query)
# Should have both time and inbox filters
expect(base_query.to_sql).to include('created_at >= ')
expect(base_query.to_sql).to include('inbox_id')
end
context 'when user has access to all inboxes' do
before do
# Create additional inbox and assign user to all inboxes
other_inbox = create(:inbox, account: account)
create(:inbox_member, user: user, inbox: other_inbox)
end
it 'skips inbox filtering as optimization' do
base_query = search.send(:message_base_query)
# Should only have the time filter, not inbox filter
expect(base_query.to_sql).to include('created_at >= ')
expect(base_query.to_sql).not_to include('inbox_id')
end
end
end
end