Check that wiki page exists before processing (#2360).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2145 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
4ec5b1600a
commit
ede011243b
@ -19,6 +19,7 @@ require 'diff'
|
|||||||
|
|
||||||
class WikiController < ApplicationController
|
class WikiController < ApplicationController
|
||||||
before_filter :find_wiki, :authorize
|
before_filter :find_wiki, :authorize
|
||||||
|
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
|
||||||
|
|
||||||
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
|
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
|
||||||
|
|
||||||
@ -91,7 +92,6 @@ class WikiController < ApplicationController
|
|||||||
|
|
||||||
# rename a page
|
# rename a page
|
||||||
def rename
|
def rename
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
return render_403 unless editable?
|
return render_403 unless editable?
|
||||||
@page.redirect_existing_links = true
|
@page.redirect_existing_links = true
|
||||||
# used to display the *original* title if some AR validation errors occur
|
# used to display the *original* title if some AR validation errors occur
|
||||||
@ -103,15 +103,12 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def protect
|
def protect
|
||||||
page = @wiki.find_page(params[:page])
|
@page.update_attribute :protected, params[:protected]
|
||||||
page.update_attribute :protected, params[:protected]
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||||
redirect_to :action => 'index', :id => @project, :page => page.title
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# show page history
|
# show page history
|
||||||
def history
|
def history
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
|
|
||||||
@version_count = @page.content.versions.count
|
@version_count = @page.content.versions.count
|
||||||
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
|
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
|
||||||
# don't load text
|
# don't load text
|
||||||
@ -125,21 +122,19 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def diff
|
def diff
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
@diff = @page.diff(params[:version], params[:version_from])
|
@diff = @page.diff(params[:version], params[:version_from])
|
||||||
render_404 unless @diff
|
render_404 unless @diff
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotate
|
def annotate
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
@annotate = @page.annotate(params[:version])
|
@annotate = @page.annotate(params[:version])
|
||||||
|
render_404 unless @annotate
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove a wiki page and its history
|
# remove a wiki page and its history
|
||||||
def destroy
|
def destroy
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
return render_403 unless editable?
|
return render_403 unless editable?
|
||||||
@page.destroy if @page
|
@page.destroy
|
||||||
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -181,7 +176,6 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_attachment
|
def add_attachment
|
||||||
@page = @wiki.find_page(params[:page])
|
|
||||||
return render_403 unless editable?
|
return render_403 unless editable?
|
||||||
attach_files(@page, params[:attachments])
|
attach_files(@page, params[:attachments])
|
||||||
redirect_to :action => 'index', :page => @page.title
|
redirect_to :action => 'index', :page => @page.title
|
||||||
@ -197,6 +191,12 @@ private
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Finds the requested page and returns a 404 error if it doesn't exist
|
||||||
|
def find_existing_page
|
||||||
|
@page = @wiki.find_page(params[:page])
|
||||||
|
render_404 if @page.nil?
|
||||||
|
end
|
||||||
|
|
||||||
# Returns true if the current user is allowed to edit the page, otherwise false
|
# Returns true if the current user is allowed to edit the page, otherwise false
|
||||||
def editable?(page = @page)
|
def editable?(page = @page)
|
||||||
page.editable_by?(User.current)
|
page.editable_by?(User.current)
|
||||||
|
@ -251,4 +251,9 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'edit'
|
assert_template 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_history_of_non_existing_page_should_return_404
|
||||||
|
get :history, :id => 1, :page => 'Unknown_page'
|
||||||
|
assert_response 404
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user