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`
This commit is contained in:
Keegan George 2025-04-30 12:10:10 -07:00 committed by GitHub
parent 1e32416eaa
commit ab67299acb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -46,11 +46,19 @@ module DiscourseAi
end end
hijack do hijack do
semantic_search begin
.search_for_topics(query, _page = 1, hyde: !skip_hyde) semantic_search
.each { |topic_post| grouped_results.add(topic_post) } .search_for_topics(query, _page = 1, hyde: !skip_hyde)
.each { |topic_post| grouped_results.add(topic_post) }
render_serialized(grouped_results, GroupedSearchResultSerializer, result: grouped_results) render_serialized(
grouped_results,
GroupedSearchResultSerializer,
result: grouped_results,
)
rescue Discourse::InvalidAccess
render_json_error(I18n.t("invalid_access"), status: 403)
end
end end
end end

View File

@ -9,6 +9,7 @@ import { SEARCH_TYPE_DEFAULT } from "discourse/controllers/full-page-search";
import concatClass from "discourse/helpers/concat-class"; import concatClass from "discourse/helpers/concat-class";
import icon from "discourse/helpers/d-icon"; import icon from "discourse/helpers/d-icon";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { isValidSearchTerm, translateResults } from "discourse/lib/search"; import { isValidSearchTerm, translateResults } from "discourse/lib/search";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
import DTooltip from "float-kit/components/d-tooltip"; import DTooltip from "float-kit/components/d-tooltip";
@ -193,6 +194,7 @@ export default class AiFullPageSearch extends Component {
this.AiResults = model.posts; this.AiResults = model.posts;
}) })
.catch(popupAjaxError)
.finally(() => { .finally(() => {
this.searching = false; this.searching = false;
}); });