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