fix: Remove draft articles from the help center search (#10116)

Limit the API to return only the published articles in public help
center API.

Fixes https://github.com/chatwoot/chatwoot/issues/10026
This commit is contained in:
Pranav
2024-09-16 15:47:44 +05:30
committed by GitHub
parent 73d448a203
commit b9ff164041
2 changed files with 9 additions and 2 deletions

View File

@@ -6,7 +6,7 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B
layout 'portal'
def index
@articles = @portal.articles
@articles = @portal.articles.published
search_articles
order_by_sort_param
@articles.page(list_params[:page]) if list_params[:page].present?

View File

@@ -17,15 +17,22 @@ RSpec.describe 'Public Articles API', type: :request do
create(:article, category: category, portal: portal, account_id: account.id, author_id: agent.id, associated_article_id: article.id, views: 1)
create(:article, category: category_2, portal: portal, account_id: account.id, author_id: agent.id, associated_article_id: article.id, views: 5)
create(:article, category: category_2, portal: portal, account_id: account.id, author_id: agent.id, views: 4)
create(:article, category: category_2, portal: portal, account_id: account.id, author_id: agent.id, status: :draft)
end
describe 'GET /public/api/v1/portals/:slug/articles' do
it 'Fetch all articles in the portal' do
get "/hc/#{portal.slug}/#{category.locale}/categories/#{category.slug}/articles"
expect(response).to have_http_status(:success)
end
it 'Fetches only the published articles in the portal' do
get "/hc/#{portal.slug}/#{category_2.locale}/categories/#{category.slug}/articles.json"
expect(response).to have_http_status(:success)
response_data = JSON.parse(response.body, symbolize_names: true)[:payload]
expect(response_data.length).to eq(2)
end
it 'get all articles with searched text query' do
article2 = create(:article,
account_id: account.id,