Fixes #3931 - Changing the category of a Knowledge Base answer leads to alternative translation loop
This commit is contained in:
parent
cadb462208
commit
76fe4ce0e7
2 changed files with 38 additions and 1 deletions
|
@ -13,7 +13,9 @@ class KnowledgeBase::Public::AnswersController < KnowledgeBase::Public::BaseCont
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_alternative
|
def render_alternative
|
||||||
@alternative = find_answer @knowledge_base.answers.eager_load(translations: :kb_locale), params[:answer], locale: false
|
answers = @knowledge_base.answers.where(category: params[:category]).eager_load(translations: :kb_locale)
|
||||||
|
|
||||||
|
@alternative = find_answer(answers, params[:answer], locale: false)
|
||||||
|
|
||||||
raise ActiveRecord::RecordNotFound if !@alternative&.translations&.any?
|
raise ActiveRecord::RecordNotFound if !@alternative&.translations&.any?
|
||||||
|
|
||||||
|
|
|
@ -35,4 +35,39 @@ RSpec.describe 'KnowledgeBase public answers', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#render_alternative' do
|
||||||
|
context 'when a translation is available' do
|
||||||
|
before { create(:knowledge_base_translation, kb_locale: alternative_locale) }
|
||||||
|
|
||||||
|
it 'returns OK for published answer' do
|
||||||
|
get help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
|
||||||
|
expect(response).to have_http_status :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns NOT FOUND for draft answer' do
|
||||||
|
get help_answer_path(alternative_locale.system_locale.locale, category, draft_answer)
|
||||||
|
expect(response).to have_http_status :not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
# https://github.com/zammad/zammad/issues/3931
|
||||||
|
context 'when the category has been updated' do
|
||||||
|
let(:new_category) { create(:knowledge_base_category, knowledge_base: knowledge_base) }
|
||||||
|
|
||||||
|
it 'returns NOT FOUND for published answer if old category is used' do
|
||||||
|
published_answer.update! category_id: new_category.id
|
||||||
|
|
||||||
|
get help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
|
||||||
|
expect(response).to have_http_status :not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns OK for published answer if new category is used' do
|
||||||
|
published_answer.update! category_id: new_category.id
|
||||||
|
|
||||||
|
get help_answer_path(alternative_locale.system_locale.locale, new_category, published_answer)
|
||||||
|
expect(response).to have_http_status :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue