summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-10-13 11:19:47 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-10-13 11:19:47 +0000
commit5f747faa58c0756827bc13276954136451f6bbc2 (patch)
tree1d59e9fc42694dec6a85ec4b25a20742f625369b /app/controllers
parent94e7df78ca5265b20d97487a5ba8465644d72710 (diff)
downloadredmine-5f747faa58c0756827bc13276954136451f6bbc2.tar.gz
redmine-5f747faa58c0756827bc13276954136451f6bbc2.zip
Fixed that viewing/editing a wiki page without WikiContent raises an error (#14986).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12220 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/wiki_controller.rb21
1 files changed, 10 insertions, 11 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 17faf2a74..8c3011510 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -62,7 +62,12 @@ class WikiController < ApplicationController
# display a page (in editing mode if it doesn't exist)
def show
- if @page.new_record?
+ if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
+ deny_access
+ return
+ end
+ @content = @page.content_for_version(params[:version])
+ if @content.nil?
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request?
edit
render :action => 'edit'
@@ -71,11 +76,6 @@ class WikiController < ApplicationController
end
return
end
- if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
- deny_access
- return
- end
- @content = @page.content_for_version(params[:version])
if User.current.allowed_to?(:export_wiki_pages, @project)
if params[:format] == 'pdf'
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
@@ -104,19 +104,19 @@ class WikiController < ApplicationController
def edit
return render_403 unless editable?
if @page.new_record?
- @page.content = WikiContent.new(:page => @page)
if params[:parent].present?
@page.parent = @page.wiki.find_page(params[:parent].to_s)
end
end
@content = @page.content_for_version(params[:version])
+ @content ||= WikiContent.new(:page => @page)
@content.text = initial_page_content(@page) if @content.text.blank?
# don't keep previous comment
@content.comments = nil
# To prevent StaleObjectError exception when reverting to a previous version
- @content.version = @page.content.version
+ @content.version = @page.content.version if @page.content
@text = @content.text
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
@@ -130,10 +130,9 @@ class WikiController < ApplicationController
def update
return render_403 unless editable?
was_new_page = @page.new_record?
- @page.content = WikiContent.new(:page => @page) if @page.new_record?
@page.safe_attributes = params[:wiki_page]
- @content = @page.content
+ @content = @page.content || WikiContent.new(:page => @page)
content_params = params[:content]
if content_params.nil? && params[:wiki_page].is_a?(Hash)
content_params = params[:wiki_page].slice(:text, :comments, :version)
@@ -152,7 +151,7 @@ class WikiController < ApplicationController
end
@content.author = User.current
- if @page.save_with_content
+ if @page.save_with_content(@content)
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})