@@ -62,7 +62,12 class WikiController < ApplicationController | |||
|
62 | 62 | |
|
63 | 63 | # display a page (in editing mode if it doesn't exist) |
|
64 | 64 | def show |
|
65 | if @page.new_record? | |
|
65 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) | |
|
66 | deny_access | |
|
67 | return | |
|
68 | end | |
|
69 | @content = @page.content_for_version(params[:version]) | |
|
70 | if @content.nil? | |
|
66 | 71 | if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request? |
|
67 | 72 | edit |
|
68 | 73 | render :action => 'edit' |
@@ -71,11 +76,6 class WikiController < ApplicationController | |||
|
71 | 76 | end |
|
72 | 77 | return |
|
73 | 78 | end |
|
74 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) | |
|
75 | deny_access | |
|
76 | return | |
|
77 | end | |
|
78 | @content = @page.content_for_version(params[:version]) | |
|
79 | 79 | if User.current.allowed_to?(:export_wiki_pages, @project) |
|
80 | 80 | if params[:format] == 'pdf' |
|
81 | 81 | send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf") |
@@ -104,19 +104,19 class WikiController < ApplicationController | |||
|
104 | 104 | def edit |
|
105 | 105 | return render_403 unless editable? |
|
106 | 106 | if @page.new_record? |
|
107 | @page.content = WikiContent.new(:page => @page) | |
|
108 | 107 | if params[:parent].present? |
|
109 | 108 | @page.parent = @page.wiki.find_page(params[:parent].to_s) |
|
110 | 109 | end |
|
111 | 110 | end |
|
112 | 111 | |
|
113 | 112 | @content = @page.content_for_version(params[:version]) |
|
113 | @content ||= WikiContent.new(:page => @page) | |
|
114 | 114 | @content.text = initial_page_content(@page) if @content.text.blank? |
|
115 | 115 | # don't keep previous comment |
|
116 | 116 | @content.comments = nil |
|
117 | 117 | |
|
118 | 118 | # To prevent StaleObjectError exception when reverting to a previous version |
|
119 | @content.version = @page.content.version | |
|
119 | @content.version = @page.content.version if @page.content | |
|
120 | 120 | |
|
121 | 121 | @text = @content.text |
|
122 | 122 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? |
@@ -130,10 +130,9 class WikiController < ApplicationController | |||
|
130 | 130 | def update |
|
131 | 131 | return render_403 unless editable? |
|
132 | 132 | was_new_page = @page.new_record? |
|
133 | @page.content = WikiContent.new(:page => @page) if @page.new_record? | |
|
134 | 133 | @page.safe_attributes = params[:wiki_page] |
|
135 | 134 | |
|
136 | @content = @page.content | |
|
135 | @content = @page.content || WikiContent.new(:page => @page) | |
|
137 | 136 | content_params = params[:content] |
|
138 | 137 | if content_params.nil? && params[:wiki_page].is_a?(Hash) |
|
139 | 138 | content_params = params[:wiki_page].slice(:text, :comments, :version) |
@@ -152,7 +151,7 class WikiController < ApplicationController | |||
|
152 | 151 | end |
|
153 | 152 | @content.author = User.current |
|
154 | 153 | |
|
155 | if @page.save_with_content | |
|
154 | if @page.save_with_content(@content) | |
|
156 | 155 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
157 | 156 | render_attachment_warning_if_needed(@page) |
|
158 | 157 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
@@ -175,9 +175,10 class WikiPage < ActiveRecord::Base | |||
|
175 | 175 | end |
|
176 | 176 | |
|
177 | 177 | # Saves the page and its content if text was changed |
|
178 | def save_with_content | |
|
178 | def save_with_content(content) | |
|
179 | 179 | ret = nil |
|
180 | 180 | transaction do |
|
181 | self.content = content | |
|
181 | 182 | if new_record? |
|
182 | 183 | # Rails automatically saves associated content |
|
183 | 184 | ret = save |
@@ -177,6 +177,16 class WikiControllerTest < ActionController::TestCase | |||
|
177 | 177 | assert_response 302 |
|
178 | 178 | end |
|
179 | 179 | |
|
180 | def test_show_page_without_content_should_display_the_edit_form | |
|
181 | @request.session[:user_id] = 2 | |
|
182 | WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) | |
|
183 | ||
|
184 | get :show, :project_id => 1, :id => 'NoContent' | |
|
185 | assert_response :success | |
|
186 | assert_template 'edit' | |
|
187 | assert_select 'textarea[name=?]', 'content[text]' | |
|
188 | end | |
|
189 | ||
|
180 | 190 | def test_create_page |
|
181 | 191 | @request.session[:user_id] = 2 |
|
182 | 192 | assert_difference 'WikiPage.count' do |
@@ -412,6 +422,19 class WikiControllerTest < ActionController::TestCase | |||
|
412 | 422 | assert_equal 2, c.version |
|
413 | 423 | end |
|
414 | 424 | |
|
425 | def test_update_page_without_content_should_create_content | |
|
426 | @request.session[:user_id] = 2 | |
|
427 | page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) | |
|
428 | ||
|
429 | assert_no_difference 'WikiPage.count' do | |
|
430 | assert_difference 'WikiContent.count' do | |
|
431 | put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'} | |
|
432 | assert_response 302 | |
|
433 | end | |
|
434 | end | |
|
435 | assert_equal 'Some content', page.reload.content.text | |
|
436 | end | |
|
437 | ||
|
415 | 438 | def test_update_section |
|
416 | 439 | @request.session[:user_id] = 2 |
|
417 | 440 | page = WikiPage.find_by_title('Page_with_sections') |
General Comments 0
You need to be logged in to leave comments.
Login now