Project

General

Profile

Actions

Defect #44361

closed

Preview returns a 404 error on the cross-project news form

Defect #44361: Preview returns a 404 error on the cross-project news form

Added by Vincent Robert 3 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Category:
News
Target version:
Resolution:
Fixed
Affected version:

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 3 months ago Actions #1

  • Status changed from New to Confirmed
  • Target version set to 6.1.5

Setting the target version to 6.1.5.

Updated by Go MAEDA 3 months ago Actions #2

  • 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 months ago Actions #3

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

Updated by Marius BĂLTEANU 2 months ago Actions #4

  • Target version changed from Candidate for next minor release to 6.1.6

Updated by Marius BĂLTEANU about 2 months ago Actions #5

  • Status changed from Confirmed to Resolved
  • Assignee set to Marius BĂLTEANU
  • Resolution set to Fixed

Committed the fix, thanks!

Updated by Marius BĂLTEANU about 2 months ago Actions #6

  • Status changed from Resolved to Closed
Actions

Also available in: PDF Atom