Defect #44361
openPreview returns a 404 error on the cross-project news form
Description
On the cross-project news form, clicking Preview returns a 404 instead of the preview.
The toolbar builds preview URL with preview_news_path(:project_id => @project, :id => @news). Outside a project @project is nil, so the URL is /news/preview with no project_id, and PreviewsController#find_project runs Project.find(nil), which raises ActiveRecord::RecordNotFound and renders a 404.
Steps to reproduce¶
- open
/news/new - type something in the description
- click Preview
The preview is blank.
You can see a 404 error in the browser console.
Patch¶
The attached patch looks the project up only when an id is given:
def find_project project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] @project = Project.find(project_id) if project_id.present? rescue ActiveRecord::RecordNotFound render_404 end
A nil project is already a supported state of this controller. A preview can be rendered without project context
Files
Updated by Go MAEDA 14 days ago
- Target version changed from 6.1.5 to Candidate for next minor release
Thank you for posting the patch.
The patch fixes the 404, but the preview on the cross-project news form is still rendered without a project, so project-scoped syntax does not work. This happens even when a project is selected in the form.
I tested the same input by previewing it on /news/new, then saving and viewing the news and comparing the results:
| Input | Preview on /news/new (with the patch) | Saved news |
|---|---|---|
[[CookBook documentation]] |
rendered as plain text | link to the wiki page |
{{include(Another page)}} |
"Error executing the include macro (Page not found)" | the page content is inserted |
Updated by Vincent Robert 3 days ago
Thank you for the review.
The 404 and the missing project have two different causes. This updated patch fixes the preview context as well.
The project selected in the drop-down was never sent. The patch adds a data-preview-param marker to specify the fields to carry with the text.
The controller guard is kept: the drop-down is empty for an administrator on an instance without any project