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