@@ -71,34 +71,48 class WikiController < ApplicationController | |||||
71 | @content.text = initial_page_content(@page) if @content.text.blank? |
|
71 | @content.text = initial_page_content(@page) if @content.text.blank? | |
72 | # don't keep previous comment |
|
72 | # don't keep previous comment | |
73 | @content.comments = nil |
|
73 | @content.comments = nil | |
74 | if request.get? |
|
74 | ||
75 |
|
|
75 | # To prevent StaleObjectError exception when reverting to a previous version | |
76 |
|
|
76 | @content.version = @page.content.version | |
77 | else |
|
77 | rescue ActiveRecord::StaleObjectError | |
78 | if !@page.new_record? && @content.text == params[:content][:text] |
|
78 | # Optimistic locking exception | |
79 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
79 | flash[:error] = l(:notice_locking_conflict) | |
80 | render_attachment_warning_if_needed(@page) |
|
80 | end | |
81 | # don't save if text wasn't changed |
|
81 | ||
82 | redirect_to :action => 'show', :project_id => @project, :page => @page.title |
|
82 | verify :method => :post, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
83 | return |
|
83 | # Creates a new page or updates an existing one | |
84 | end |
|
84 | def update | |
85 | #@content.text = params[:content][:text] |
|
85 | @page = @wiki.find_or_new_page(params[:page]) | |
86 | #@content.comments = params[:content][:comments] |
|
86 | return render_403 unless editable? | |
87 | @content.attributes = params[:content] |
|
87 | @page.content = WikiContent.new(:page => @page) if @page.new_record? | |
88 | @content.author = User.current |
|
88 | ||
89 | # if page is new @page.save will also save content, but not if page isn't a new record |
|
89 | @content = @page.content_for_version(params[:version]) | |
90 | if (@page.new_record? ? @page.save : @content.save) |
|
90 | @content.text = initial_page_content(@page) if @content.text.blank? | |
91 | attachments = Attachment.attach_files(@page, params[:attachments]) |
|
91 | # don't keep previous comment | |
92 | render_attachment_warning_if_needed(@page) |
|
92 | @content.comments = nil | |
93 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
|
93 | ||
94 | redirect_to :action => 'show', :project_id => @project, :page => @page.title |
|
94 | if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text] | |
95 | end |
|
95 | attachments = Attachment.attach_files(@page, params[:attachments]) | |
|
96 | render_attachment_warning_if_needed(@page) | |||
|
97 | # don't save if text wasn't changed | |||
|
98 | redirect_to :action => 'show', :project_id => @project, :page => @page.title | |||
|
99 | return | |||
|
100 | end | |||
|
101 | @content.attributes = params[:content] | |||
|
102 | @content.author = User.current | |||
|
103 | # if page is new @page.save will also save content, but not if page isn't a new record | |||
|
104 | if (@page.new_record? ? @page.save : @content.save) | |||
|
105 | attachments = Attachment.attach_files(@page, params[:attachments]) | |||
|
106 | render_attachment_warning_if_needed(@page) | |||
|
107 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) | |||
|
108 | redirect_to :action => 'show', :project_id => @project, :page => @page.title | |||
96 | end |
|
109 | end | |
|
110 | ||||
97 | rescue ActiveRecord::StaleObjectError |
|
111 | rescue ActiveRecord::StaleObjectError | |
98 | # Optimistic locking exception |
|
112 | # Optimistic locking exception | |
99 | flash[:error] = l(:notice_locking_conflict) |
|
113 | flash[:error] = l(:notice_locking_conflict) | |
100 | end |
|
114 | end | |
101 |
|
115 | |||
102 | # rename a page |
|
116 | # rename a page | |
103 | def rename |
|
117 | def rename | |
104 | return render_403 unless editable? |
|
118 | return render_403 unless editable? |
@@ -1,6 +1,6 | |||||
1 | <h2><%=h @page.pretty_title %></h2> |
|
1 | <h2><%=h @page.pretty_title %></h2> | |
2 |
|
2 | |||
3 |
<% form_for :content, @content, :url => {:action => ' |
|
3 | <% form_for :content, @content, :url => {:action => 'update', :page => @page.title}, :html => {:multipart => true, :id => 'wiki_form'} do |f| %> | |
4 | <%= f.hidden_field :version %> |
|
4 | <%= f.hidden_field :version %> | |
5 | <%= error_messages_for 'content' %> |
|
5 | <%= error_messages_for 'content' %> | |
6 |
|
6 |
@@ -41,8 +41,10 ActionController::Routing::Routes.draw do |map| | |||||
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | wiki_routes.connect 'projects/:project_id/wiki/:page/:action', |
|
43 | wiki_routes.connect 'projects/:project_id/wiki/:page/:action', | |
44 |
:action => / |
|
44 | :action => /rename|destroy|preview|protect/, | |
45 | :conditions => {:method => :post} |
|
45 | :conditions => {:method => :post} | |
|
46 | ||||
|
47 | wiki_routes.connect 'projects/:project_id/wiki/:page/edit', :action => 'update', :conditions => {:method => :post} | |||
46 | end |
|
48 | end | |
47 |
|
49 | |||
48 | map.with_options :controller => 'messages' do |messages_routes| |
|
50 | map.with_options :controller => 'messages' do |messages_routes| |
@@ -114,7 +114,7 Redmine::AccessControl.map do |map| | |||||
114 | map.permission :view_wiki_pages, :wiki => [:show, :special, :page_index, :date_index] |
|
114 | map.permission :view_wiki_pages, :wiki => [:show, :special, :page_index, :date_index] | |
115 | map.permission :export_wiki_pages, :wiki => [:export] |
|
115 | map.permission :export_wiki_pages, :wiki => [:export] | |
116 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] |
|
116 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] | |
117 | map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment] |
|
117 | map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment] | |
118 | map.permission :delete_wiki_pages_attachments, {} |
|
118 | map.permission :delete_wiki_pages_attachments, {} | |
119 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member |
|
119 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member | |
120 | end |
|
120 | end |
@@ -80,7 +80,7 class WikiControllerTest < ActionController::TestCase | |||||
80 |
|
80 | |||
81 | def test_create_page |
|
81 | def test_create_page | |
82 | @request.session[:user_id] = 2 |
|
82 | @request.session[:user_id] = 2 | |
83 |
post : |
|
83 | post :update, :project_id => 1, | |
84 | :page => 'New page', |
|
84 | :page => 'New page', | |
85 | :content => {:comments => 'Created the page', |
|
85 | :content => {:comments => 'Created the page', | |
86 | :text => "h1. New page\n\nThis is a new page", |
|
86 | :text => "h1. New page\n\nThis is a new page", | |
@@ -96,7 +96,7 class WikiControllerTest < ActionController::TestCase | |||||
96 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
97 | assert_difference 'WikiPage.count' do |
|
97 | assert_difference 'WikiPage.count' do | |
98 | assert_difference 'Attachment.count' do |
|
98 | assert_difference 'Attachment.count' do | |
99 |
post : |
|
99 | post :update, :project_id => 1, | |
100 | :page => 'New page', |
|
100 | :page => 'New page', | |
101 | :content => {:comments => 'Created the page', |
|
101 | :content => {:comments => 'Created the page', | |
102 | :text => "h1. New page\n\nThis is a new page", |
|
102 | :text => "h1. New page\n\nThis is a new page", |
@@ -322,7 +322,7 class RoutingTest < ActionController::IntegrationTest | |||||
322 | should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :project_id => '567' |
|
322 | should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :project_id => '567' | |
323 | should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :project_id => '567' |
|
323 | should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :project_id => '567' | |
324 |
|
324 | |||
325 |
should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => ' |
|
325 | should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :page => 'my_page' | |
326 | should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation' |
|
326 | should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation' | |
327 | should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida' |
|
327 | should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida' | |
328 | should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida' |
|
328 | should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida' |
General Comments 0
You need to be logged in to leave comments.
Login now