##// END OF EJS Templates
Check that wiki page exists before processing (#2360)....
Jean-Philippe Lang -
r2143:ede011243b0e
parent child
Show More
@@ -19,6 +19,7 require 'diff'
19
19
20 class WikiController < ApplicationController
20 class WikiController < ApplicationController
21 before_filter :find_wiki, :authorize
21 before_filter :find_wiki, :authorize
22 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
22
23
23 verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
24 verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
24
25
@@ -91,8 +92,7 class WikiController < ApplicationController
91
92
92 # rename a page
93 # rename a page
93 def rename
94 def rename
94 @page = @wiki.find_page(params[:page])
95 return render_403 unless editable?
95 return render_403 unless editable?
96 @page.redirect_existing_links = true
96 @page.redirect_existing_links = true
97 # used to display the *original* title if some AR validation errors occur
97 # used to display the *original* title if some AR validation errors occur
98 @original_title = @page.pretty_title
98 @original_title = @page.pretty_title
@@ -103,15 +103,12 class WikiController < ApplicationController
103 end
103 end
104
104
105 def protect
105 def protect
106 page = @wiki.find_page(params[:page])
106 @page.update_attribute :protected, params[:protected]
107 page.update_attribute :protected, params[:protected]
107 redirect_to :action => 'index', :id => @project, :page => @page.title
108 redirect_to :action => 'index', :id => @project, :page => page.title
109 end
108 end
110
109
111 # show page history
110 # show page history
112 def history
111 def history
113 @page = @wiki.find_page(params[:page])
114
115 @version_count = @page.content.versions.count
112 @version_count = @page.content.versions.count
116 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
113 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
117 # don't load text
114 # don't load text
@@ -125,21 +122,19 class WikiController < ApplicationController
125 end
122 end
126
123
127 def diff
124 def diff
128 @page = @wiki.find_page(params[:page])
129 @diff = @page.diff(params[:version], params[:version_from])
125 @diff = @page.diff(params[:version], params[:version_from])
130 render_404 unless @diff
126 render_404 unless @diff
131 end
127 end
132
128
133 def annotate
129 def annotate
134 @page = @wiki.find_page(params[:page])
135 @annotate = @page.annotate(params[:version])
130 @annotate = @page.annotate(params[:version])
131 render_404 unless @annotate
136 end
132 end
137
133
138 # remove a wiki page and its history
134 # remove a wiki page and its history
139 def destroy
135 def destroy
140 @page = @wiki.find_page(params[:page])
136 return render_403 unless editable?
141 return render_403 unless editable?
137 @page.destroy
142 @page.destroy if @page
143 redirect_to :action => 'special', :id => @project, :page => 'Page_index'
138 redirect_to :action => 'special', :id => @project, :page => 'Page_index'
144 end
139 end
145
140
@@ -181,7 +176,6 class WikiController < ApplicationController
181 end
176 end
182
177
183 def add_attachment
178 def add_attachment
184 @page = @wiki.find_page(params[:page])
185 return render_403 unless editable?
179 return render_403 unless editable?
186 attach_files(@page, params[:attachments])
180 attach_files(@page, params[:attachments])
187 redirect_to :action => 'index', :page => @page.title
181 redirect_to :action => 'index', :page => @page.title
@@ -197,6 +191,12 private
197 render_404
191 render_404
198 end
192 end
199
193
194 # Finds the requested page and returns a 404 error if it doesn't exist
195 def find_existing_page
196 @page = @wiki.find_page(params[:page])
197 render_404 if @page.nil?
198 end
199
200 # Returns true if the current user is allowed to edit the page, otherwise false
200 # Returns true if the current user is allowed to edit the page, otherwise false
201 def editable?(page = @page)
201 def editable?(page = @page)
202 page.editable_by?(User.current)
202 page.editable_by?(User.current)
@@ -251,4 +251,9 class WikiControllerTest < Test::Unit::TestCase
251 assert_response :success
251 assert_response :success
252 assert_template 'edit'
252 assert_template 'edit'
253 end
253 end
254
255 def test_history_of_non_existing_page_should_return_404
256 get :history, :id => 1, :page => 'Unknown_page'
257 assert_response 404
258 end
254 end
259 end
General Comments 0
You need to be logged in to leave comments. Login now