@@ -123,6 +123,7 class WikiController < ApplicationController | |||||
123 | def update |
|
123 | def update | |
124 | return render_403 unless editable? |
|
124 | return render_403 unless editable? | |
125 | @page.content = WikiContent.new(:page => @page) if @page.new_record? |
|
125 | @page.content = WikiContent.new(:page => @page) if @page.new_record? | |
|
126 | @page.safe_attributes = params[:wiki_page] | |||
126 |
|
127 | |||
127 | @content = @page.content_for_version(params[:version]) |
|
128 | @content = @page.content_for_version(params[:version]) | |
128 | @content.text = initial_page_content(@page) if @content.text.blank? |
|
129 | @content.text = initial_page_content(@page) if @content.text.blank? | |
@@ -132,11 +133,12 class WikiController < ApplicationController | |||||
132 | if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text] |
|
133 | if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text] | |
133 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
134 | attachments = Attachment.attach_files(@page, params[:attachments]) | |
134 | render_attachment_warning_if_needed(@page) |
|
135 | render_attachment_warning_if_needed(@page) | |
135 | # don't save if text wasn't changed |
|
136 | # don't save content if text wasn't changed | |
|
137 | @page.save | |||
136 | redirect_to :action => 'show', :project_id => @project, :id => @page.title |
|
138 | redirect_to :action => 'show', :project_id => @project, :id => @page.title | |
137 | return |
|
139 | return | |
138 | end |
|
140 | end | |
139 |
|
141 | |||
140 | @content.comments = params[:content][:comments] |
|
142 | @content.comments = params[:content][:comments] | |
141 | @text = params[:content][:text] |
|
143 | @text = params[:content][:text] | |
142 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? |
|
144 | if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? | |
@@ -148,11 +150,8 class WikiController < ApplicationController | |||||
148 | @content.text = @text |
|
150 | @content.text = @text | |
149 | end |
|
151 | end | |
150 | @content.author = User.current |
|
152 | @content.author = User.current | |
151 | if @page.new_record? && params[:page] |
|
153 | @page.content = @content | |
152 | @page.parent_id = params[:page][:parent_id] |
|
154 | if @page.save | |
153 | end |
|
|||
154 | # if page is new @page.save will also save content, but not if page isn't a new record |
|
|||
155 | if (@page.new_record? ? @page.save : @content.save) |
|
|||
156 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
155 | attachments = Attachment.attach_files(@page, params[:attachments]) | |
157 | render_attachment_warning_if_needed(@page) |
|
156 | render_attachment_warning_if_needed(@page) | |
158 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
|
157 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
@@ -19,6 +19,8 require 'diff' | |||||
19 | require 'enumerator' |
|
19 | require 'enumerator' | |
20 |
|
20 | |||
21 | class WikiPage < ActiveRecord::Base |
|
21 | class WikiPage < ActiveRecord::Base | |
|
22 | include Redmine::SafeAttributes | |||
|
23 | ||||
22 | belongs_to :wiki |
|
24 | belongs_to :wiki | |
23 | has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy |
|
25 | has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy | |
24 | acts_as_attachable :delete_permission => :delete_wiki_pages_attachments |
|
26 | acts_as_attachable :delete_permission => :delete_wiki_pages_attachments | |
@@ -55,6 +57,9 class WikiPage < ActiveRecord::Base | |||||
55 | # Wiki pages that are protected by default |
|
57 | # Wiki pages that are protected by default | |
56 | DEFAULT_PROTECTED_PAGES = %w(sidebar) |
|
58 | DEFAULT_PROTECTED_PAGES = %w(sidebar) | |
57 |
|
59 | |||
|
60 | safe_attributes 'parent_id', | |||
|
61 | :if => lambda {|page, user| page.new_record? || user.allowed_to?(:rename_wiki_pages, page.project)} | |||
|
62 | ||||
58 | def initialize(attributes=nil, *args) |
|
63 | def initialize(attributes=nil, *args) | |
59 | super |
|
64 | super | |
60 | if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase) |
|
65 | if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase) |
@@ -13,8 +13,13 | |||||
13 | <div class="box tabular"> |
|
13 | <div class="box tabular"> | |
14 | <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %> |
|
14 | <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %> | |
15 |
|
15 | |||
16 | <% if @page.new_record? && @page.parent %> |
|
16 | <% if @page.safe_attribute_names.include?('parent_id') && @wiki.pages.any? %> | |
17 | <p><label><%= check_box_tag 'page[parent_id]', @page.parent.id, true %> <%= l(:field_parent_title) %></label> <%=h @page.parent.pretty_title %></p> |
|
17 | <% fields_for @page do |fp| %> | |
|
18 | <p> | |||
|
19 | <label><%= l(:field_parent_title) %></label> | |||
|
20 | <%= fp.select :parent_id, "<option value=''></option>" + wiki_page_options_for_select(@wiki.pages.all(:include => :parent) - @page.self_and_descendants, @page.parent) %> | |||
|
21 | </p> | |||
|
22 | <% end %> | |||
18 | <% end %> |
|
23 | <% end %> | |
19 |
|
24 | |||
20 | <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p> |
|
25 | <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p> |
@@ -124,15 +124,15 class WikiControllerTest < ActionController::TestCase | |||||
124 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
124 | get :show, :project_id => 1, :id => 'Unexistent page' | |
125 | assert_response :success |
|
125 | assert_response :success | |
126 | assert_template 'edit' |
|
126 | assert_template 'edit' | |
127 | assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'} |
|
|||
128 | end |
|
127 | end | |
129 |
|
128 | |||
130 | def test_show_unexistent_page_with_parent |
|
129 | def test_show_unexistent_page_with_parent_should_preselect_parent | |
131 | @request.session[:user_id] = 2 |
|
130 | @request.session[:user_id] = 2 | |
132 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' |
|
131 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' | |
133 | assert_response :success |
|
132 | assert_response :success | |
134 | assert_template 'edit' |
|
133 | assert_template 'edit' | |
135 |
assert_tag ' |
|
134 | assert_tag 'select', :attributes => {:name => 'wiki_page[parent_id]'}, | |
|
135 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}} | |||
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def test_show_should_not_show_history_without_permission |
|
138 | def test_show_should_not_show_history_without_permission | |
@@ -183,7 +183,7 class WikiControllerTest < ActionController::TestCase | |||||
183 | assert_difference 'WikiPage.count' do |
|
183 | assert_difference 'WikiPage.count' do | |
184 | put :update, :project_id => 1, :id => 'New page', |
|
184 | put :update, :project_id => 1, :id => 'New page', | |
185 | :content => {:text => "h1. New page\n\nThis is a new page", :version => 0}, |
|
185 | :content => {:text => "h1. New page\n\nThis is a new page", :version => 0}, | |
186 | :page => {:parent_id => 2} |
|
186 | :wiki_page => {:parent_id => 2} | |
187 | end |
|
187 | end | |
188 | page = Project.find(1).wiki.find_page('New page') |
|
188 | page = Project.find(1).wiki.find_page('New page') | |
189 | assert_equal WikiPage.find(2), page.parent |
|
189 | assert_equal WikiPage.find(2), page.parent | |
@@ -250,6 +250,31 class WikiControllerTest < ActionController::TestCase | |||||
250 | assert_equal "my comments", page.content.comments |
|
250 | assert_equal "my comments", page.content.comments | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
|
253 | def test_update_page_with_parent | |||
|
254 | @request.session[:user_id] = 2 | |||
|
255 | assert_no_difference 'WikiPage.count' do | |||
|
256 | assert_no_difference 'WikiContent.count' do | |||
|
257 | assert_difference 'WikiContent::Version.count' do | |||
|
258 | put :update, :project_id => 1, | |||
|
259 | :id => 'Another_page', | |||
|
260 | :content => { | |||
|
261 | :comments => "my comments", | |||
|
262 | :text => "edited", | |||
|
263 | :version => 1 | |||
|
264 | }, | |||
|
265 | :wiki_page => {:parent_id => '1'} | |||
|
266 | end | |||
|
267 | end | |||
|
268 | end | |||
|
269 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |||
|
270 | ||||
|
271 | page = Wiki.find(1).pages.find_by_title('Another_page') | |||
|
272 | assert_equal "edited", page.content.text | |||
|
273 | assert_equal 2, page.content.version | |||
|
274 | assert_equal "my comments", page.content.comments | |||
|
275 | assert_equal WikiPage.find(1), page.parent | |||
|
276 | end | |||
|
277 | ||||
253 | def test_update_page_with_failure |
|
278 | def test_update_page_with_failure | |
254 | @request.session[:user_id] = 2 |
|
279 | @request.session[:user_id] = 2 | |
255 | assert_no_difference 'WikiPage.count' do |
|
280 | assert_no_difference 'WikiPage.count' do | |
@@ -273,6 +298,27 class WikiControllerTest < ActionController::TestCase | |||||
273 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} |
|
298 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} | |
274 | end |
|
299 | end | |
275 |
|
300 | |||
|
301 | def test_update_page_with_parent_change_only_should_not_create_content_version | |||
|
302 | @request.session[:user_id] = 2 | |||
|
303 | assert_no_difference 'WikiPage.count' do | |||
|
304 | assert_no_difference 'WikiContent.count' do | |||
|
305 | assert_no_difference 'WikiContent::Version.count' do | |||
|
306 | put :update, :project_id => 1, | |||
|
307 | :id => 'Another_page', | |||
|
308 | :content => { | |||
|
309 | :comments => '', | |||
|
310 | :text => Wiki.find(1).find_page('Another_page').content.text, | |||
|
311 | :version => 1 | |||
|
312 | }, | |||
|
313 | :wiki_page => {:parent_id => '1'} | |||
|
314 | end | |||
|
315 | end | |||
|
316 | end | |||
|
317 | page = Wiki.find(1).pages.find_by_title('Another_page') | |||
|
318 | assert_equal 1, page.content.version | |||
|
319 | assert_equal WikiPage.find(1), page.parent | |||
|
320 | end | |||
|
321 | ||||
276 | def test_update_page_with_attachments_only_should_not_create_content_version |
|
322 | def test_update_page_with_attachments_only_should_not_create_content_version | |
277 | @request.session[:user_id] = 2 |
|
323 | @request.session[:user_id] = 2 | |
278 | assert_no_difference 'WikiPage.count' do |
|
324 | assert_no_difference 'WikiPage.count' do | |
@@ -291,6 +337,8 class WikiControllerTest < ActionController::TestCase | |||||
291 | end |
|
337 | end | |
292 | end |
|
338 | end | |
293 | end |
|
339 | end | |
|
340 | page = Wiki.find(1).pages.find_by_title('Another_page') | |||
|
341 | assert_equal 1, page.content.version | |||
294 | end |
|
342 | end | |
295 |
|
343 | |||
296 | def test_update_stale_page_should_not_raise_an_error |
|
344 | def test_update_stale_page_should_not_raise_an_error |
General Comments 0
You need to be logged in to leave comments.
Login now