Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit ab67299

Browse files
authored
FIX: Invalid access error should be populated to user (#1303)
Invalid access error should be populated to user when trying to search for something they do not have permissions for (i.e. anons searching `in:messages`
1 parent 1e32416 commit ab67299

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

app/controllers/discourse_ai/embeddings/embeddings_controller.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@ def search
4646
end
4747

4848
hijack do
49-
semantic_search
50-
.search_for_topics(query, _page = 1, hyde: !skip_hyde)
51-
.each { |topic_post| grouped_results.add(topic_post) }
52-
53-
render_serialized(grouped_results, GroupedSearchResultSerializer, result: grouped_results)
49+
begin
50+
semantic_search
51+
.search_for_topics(query, _page = 1, hyde: !skip_hyde)
52+
.each { |topic_post| grouped_results.add(topic_post) }
53+
54+
render_serialized(
55+
grouped_results,
56+
GroupedSearchResultSerializer,
57+
result: grouped_results,
58+
)
59+
rescue Discourse::InvalidAccess
60+
render_json_error(I18n.t("invalid_access"), status: 403)
61+
end
5462
end
5563
end
5664

assets/javascripts/discourse/components/ai-full-page-search.gjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SEARCH_TYPE_DEFAULT } from "discourse/controllers/full-page-search";
99
import concatClass from "discourse/helpers/concat-class";
1010
import icon from "discourse/helpers/d-icon";
1111
import { ajax } from "discourse/lib/ajax";
12+
import { popupAjaxError } from "discourse/lib/ajax-error";
1213
import { isValidSearchTerm, translateResults } from "discourse/lib/search";
1314
import { i18n } from "discourse-i18n";
1415
import DTooltip from "float-kit/components/d-tooltip";
@@ -193,6 +194,7 @@ export default class AiFullPageSearch extends Component {
193194

194195
this.AiResults = model.posts;
195196
})
197+
.catch(popupAjaxError)
196198
.finally(() => {
197199
this.searching = false;
198200
});

0 commit comments

Comments
 (0)