##// END OF EJS Templates
Removes all #verify calls in controllers. Verification is handled at routing level now that the default route is removed....
Jean-Philippe Lang -
r8941:b3866b05c14b
parent child
Show More
@@ -0,0 +1,29
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../test_helper', __FILE__)
19
20 class USersTest < ActionController::IntegrationTest
21 fixtures :users
22
23 def test_destroy_should_not_accept_get_requests
24 assert_no_difference 'User.count' do
25 get '/users/destroy/2', {}, credentials('admin')
26 assert_response 404
27 end
28 end
29 end
@@ -82,7 +82,6 class AttachmentsController < ApplicationController
82 82 end
83 83 end
84 84
85 verify :method => :delete, :only => :destroy
86 85 def destroy
87 86 # Make sure association callbacks are called
88 87 @attachment.container.attachments.delete(@attachment)
@@ -20,10 +20,6 class AuthSourcesController < ApplicationController
20 20
21 21 before_filter :require_admin
22 22
23 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
24 verify :method => :post, :only => [ :destroy, :create, :update ],
25 :redirect_to => { :template => :index }
26
27 23 def index
28 24 @auth_source_pages, @auth_sources = paginate auth_source_class.name.tableize, :per_page => 10
29 25 render "auth_sources/index"
@@ -63,7 +63,6 class BoardsController < ApplicationController
63 63 @board = @project.boards.build(params[:board])
64 64 end
65 65
66 verify :method => :post, :only => :create, :redirect_to => { :action => :index }
67 66 def create
68 67 @board = @project.boards.build(params[:board])
69 68 if @board.save
@@ -77,7 +76,6 class BoardsController < ApplicationController
77 76 def edit
78 77 end
79 78
80 verify :method => :put, :only => :update, :redirect_to => { :action => :index }
81 79 def update
82 80 if @board.update_attributes(params[:board])
83 81 redirect_to_settings_in_projects
@@ -86,7 +84,6 class BoardsController < ApplicationController
86 84 end
87 85 end
88 86
89 verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
90 87 def destroy
91 88 @board.destroy
92 89 redirect_to_settings_in_projects
@@ -22,7 +22,6 class CommentsController < ApplicationController
22 22 before_filter :find_project_from_association
23 23 before_filter :authorize
24 24
25 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
26 25 def create
27 26 raise Unauthorized unless @news.commentable?
28 27
@@ -35,7 +34,6 class CommentsController < ApplicationController
35 34 redirect_to :controller => 'news', :action => 'show', :id => @news
36 35 end
37 36
38 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
39 37 def destroy
40 38 @news.comments.find(params[:comment_id]).destroy
41 39 redirect_to :controller => 'news', :action => 'show', :id => @news
@@ -51,7 +51,6 class EnumerationsController < ApplicationController
51 51 end
52 52 end
53 53
54 verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
55 54 def destroy
56 55 if !@enumeration.in_use?
57 56 # No associated objects
@@ -42,7 +42,6 class IssueCategoriesController < ApplicationController
42 42 @category = @project.issue_categories.build(params[:issue_category])
43 43 end
44 44
45 verify :method => :post, :only => :create
46 45 def create
47 46 @category = @project.issue_categories.build(params[:issue_category])
48 47 if @category.save
@@ -73,7 +72,6 class IssueCategoriesController < ApplicationController
73 72 def edit
74 73 end
75 74
76 verify :method => :put, :only => :update
77 75 def update
78 76 if @category.update_attributes(params[:issue_category])
79 77 respond_to do |format|
@@ -91,7 +89,6 class IssueCategoriesController < ApplicationController
91 89 end
92 90 end
93 91
94 verify :method => :delete, :only => :destroy
95 92 def destroy
96 93 @issue_count = @category.issues.size
97 94 if @issue_count == 0 || params[:todo] || api_request?
@@ -39,7 +39,6 class IssueRelationsController < ApplicationController
39 39 end
40 40 end
41 41
42 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
43 42 def create
44 43 @relation = IssueRelation.new(params[:relation])
45 44 @relation.issue_from = @issue
@@ -70,7 +69,6 class IssueRelationsController < ApplicationController
70 69 end
71 70 end
72 71
73 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
74 72 def destroy
75 73 raise Unauthorized unless @relation.deletable?
76 74 @relation.destroy
@@ -62,7 +62,6 class IssueStatusesController < ApplicationController
62 62 end
63 63 end
64 64
65 verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
66 65 def destroy
67 66 IssueStatus.find(params[:id]).destroy
68 67 redirect_to :action => 'index'
@@ -53,10 +53,6 class IssuesController < ApplicationController
53 53 helper :gantt
54 54 include Redmine::Export::PDF
55 55
56 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
57 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
58 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
59
60 56 def index
61 57 retrieve_query
62 58 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
@@ -275,7 +271,6 class IssuesController < ApplicationController
275 271 end
276 272 end
277 273
278 verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
279 274 def destroy
280 275 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
281 276 if @hours > 0
@@ -18,10 +18,6
18 18 class MailHandlerController < ActionController::Base
19 19 before_filter :check_credential
20 20
21 verify :method => :post,
22 :only => :index,
23 :render => { :nothing => true, :status => 405 }
24
25 21 # Submits an incoming email to MailHandler
26 22 def index
27 23 options = params.dup
@@ -22,9 +22,6 class MessagesController < ApplicationController
22 22 before_filter :find_message, :except => [:new, :preview]
23 23 before_filter :authorize, :except => [:preview, :edit, :destroy]
24 24
25 verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
26 verify :xhr => true, :only => :quote
27
28 25 helper :watchers
29 26 helper :attachments
30 27 include AttachmentsHelper
@@ -35,9 +35,6 class MyController < ApplicationController
35 35 'right' => ['issuesreportedbyme']
36 36 }.freeze
37 37
38 verify :xhr => true,
39 :only => [:add_block, :remove_block, :order_blocks]
40
41 38 def index
42 39 page
43 40 render :action => 'page'
@@ -69,7 +69,6 class ProjectsController < ApplicationController
69 69 @project = Project.new(params[:project])
70 70 end
71 71
72 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
73 72 def create
74 73 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
75 74 @trackers = Tracker.all
@@ -182,8 +181,6 class ProjectsController < ApplicationController
182 181 def edit
183 182 end
184 183
185 # TODO: convert to PUT only
186 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
187 184 def update
188 185 @project.safe_attributes = params[:project]
189 186 if validate_parent_id && @project.save
@@ -206,7 +203,6 class ProjectsController < ApplicationController
206 203 end
207 204 end
208 205
209 verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed }
210 206 def modules
211 207 @project.enabled_module_names = params[:enabled_module_names]
212 208 flash[:notice] = l(:notice_successful_update)
@@ -227,7 +223,6 class ProjectsController < ApplicationController
227 223 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
228 224 end
229 225
230 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
231 226 # Delete @project
232 227 def destroy
233 228 @project_to_destroy = @project
@@ -50,7 +50,6 class QueriesController < ApplicationController
50 50 build_query_from_params
51 51 end
52 52
53 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
54 53 def create
55 54 @query = Query.new(params[:query])
56 55 @query.user = User.current
@@ -70,7 +69,6 class QueriesController < ApplicationController
70 69 def edit
71 70 end
72 71
73 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
74 72 def update
75 73 @query.attributes = params[:query]
76 74 @query.project = nil if params[:query_is_for_all]
@@ -86,7 +84,6 class QueriesController < ApplicationController
86 84 end
87 85 end
88 86
89 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
90 87 def destroy
91 88 @query.destroy
92 89 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
@@ -68,7 +68,6 class RolesController < ApplicationController
68 68 end
69 69 end
70 70
71 verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
72 71 def destroy
73 72 @role.destroy
74 73 redirect_to :action => 'index'
@@ -121,7 +121,6 class TimelogController < ApplicationController
121 121 @time_entry.attributes = params[:time_entry]
122 122 end
123 123
124 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
125 124 def create
126 125 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
127 126 @time_entry.attributes = params[:time_entry]
@@ -156,7 +155,6 class TimelogController < ApplicationController
156 155 @time_entry.attributes = params[:time_entry]
157 156 end
158 157
159 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
160 158 def update
161 159 @time_entry.attributes = params[:time_entry]
162 160
@@ -200,7 +198,6 class TimelogController < ApplicationController
200 198 redirect_back_or_default({:controller => 'timelog', :action => 'index', :project_id => @projects.first})
201 199 end
202 200
203 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
204 201 def destroy
205 202 @time_entries.each do |t|
206 203 begin
@@ -71,7 +71,6 class TrackersController < ApplicationController
71 71 render :action => 'edit'
72 72 end
73 73
74 verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
75 74 def destroy
76 75 @tracker = Tracker.find(params[:id])
77 76 unless @tracker.issues.empty?
@@ -86,7 +86,6 class UsersController < ApplicationController
86 86 @auth_sources = AuthSource.find(:all)
87 87 end
88 88
89 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
90 89 def create
91 90 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
92 91 @user.safe_attributes = params[:user]
@@ -131,7 +130,6 class UsersController < ApplicationController
131 130 @membership ||= Member.new
132 131 end
133 132
134 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
135 133 def update
136 134 @user.admin = params[:user][:admin] if params[:user][:admin]
137 135 @user.login = params[:user][:login] if params[:user][:login]
@@ -177,7 +175,6 class UsersController < ApplicationController
177 175 redirect_to :controller => 'users', :action => 'edit', :id => @user
178 176 end
179 177
180 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
181 178 def destroy
182 179 @user.destroy
183 180 respond_to do |format|
@@ -186,7 +183,6 class UsersController < ApplicationController
186 183 end
187 184 end
188 185
189 verify :method => [:post, :put], :only => :edit_membership, :render => {:nothing => true, :status => :method_not_allowed }
190 186 def edit_membership
191 187 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
192 188 @membership.save
@@ -209,7 +205,6 class UsersController < ApplicationController
209 205 end
210 206 end
211 207
212 verify :method => :delete, :only => :destroy_membership, :render => {:nothing => true, :status => :method_not_allowed }
213 208 def destroy_membership
214 209 @membership = Member.find(params[:membership_id])
215 210 if @membership.deletable?
@@ -160,7 +160,6 class VersionsController < ApplicationController
160 160 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
161 161 end
162 162
163 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
164 163 def destroy
165 164 if @version.fixed_issues.empty?
166 165 @version.destroy
@@ -20,10 +20,6 class WatchersController < ApplicationController
20 20 before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
21 21 before_filter :authorize, :only => [:new, :destroy]
22 22
23 verify :method => :post,
24 :only => [ :watch, :unwatch ],
25 :render => { :nothing => true, :status => :method_not_allowed }
26
27 23 def watch
28 24 if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
29 25 render_403
@@ -118,7 +118,6 class WikiController < ApplicationController
118 118 end
119 119 end
120 120
121 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
122 121 # Creates a new page or updates an existing one
123 122 def update
124 123 return render_403 unless editable?
@@ -178,7 +177,6 class WikiController < ApplicationController
178 177 end
179 178 end
180 179
181 verify :method => :post, :only => :protect, :redirect_to => { :action => :show }
182 180 def protect
183 181 @page.update_attribute :protected, params[:protected]
184 182 redirect_to :action => 'show', :project_id => @project, :id => @page.title
@@ -208,7 +206,6 class WikiController < ApplicationController
208 206 render_404 unless @annotate
209 207 end
210 208
211 verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
212 209 # Removes a wiki page and its history
213 210 # Children can be either set as root pages, removed or reassigned to another parent page
214 211 def destroy
@@ -2138,20 +2138,6 class IssuesControllerTest < ActionController::TestCase
2138 2138 assert_equal 'This is the test_new issue', issue.subject
2139 2139 end
2140 2140
2141 def test_update_using_invalid_http_verbs
2142 @request.session[:user_id] = 2
2143 subject = 'Updated by an invalid http verb'
2144
2145 get :update, :id => 1, :issue => {:subject => subject}
2146 assert_not_equal subject, Issue.find(1).subject
2147
2148 post :update, :id => 1, :issue => {:subject => subject}
2149 assert_not_equal subject, Issue.find(1).subject
2150
2151 delete :update, :id => 1, :issue => {:subject => subject}
2152 assert_not_equal subject, Issue.find(1).subject
2153 end
2154
2155 2141 def test_put_update_without_custom_fields_param
2156 2142 @request.session[:user_id] = 2
2157 2143 ActionMailer::Base.deliveries.clear
@@ -311,12 +311,6 class ProjectsControllerTest < ActionController::TestCase
311 311 end
312 312 end
313 313
314 def test_create_should_not_accept_get
315 @request.session[:user_id] = 1
316 get :create
317 assert_response :method_not_allowed
318 end
319
320 314 def test_show_by_id
321 315 get :show, :id => 1
322 316 assert_response :success
@@ -412,12 +406,6 class ProjectsControllerTest < ActionController::TestCase
412 406 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
413 407 end
414 408
415 def test_modules_should_not_allow_get
416 @request.session[:user_id] = 1
417 get :modules, :id => 1
418 assert_response :method_not_allowed
419 end
420
421 409 def test_destroy_without_confirmation
422 410 @request.session[:user_id] = 1 # admin
423 411 delete :destroy, :id => 1
@@ -289,13 +289,6 class UsersControllerTest < ActionController::TestCase
289 289 assert_nil User.find_by_id(2)
290 290 end
291 291
292 def test_destroy_should_not_accept_get_requests
293 assert_no_difference 'User.count' do
294 get :destroy, :id => 2
295 end
296 assert_response 405
297 end
298
299 292 def test_destroy_should_be_denied_for_non_admin_users
300 293 @request.session[:user_id] = 3
301 294
@@ -32,12 +32,6 class WatchersControllerTest < ActionController::TestCase
32 32 User.current = nil
33 33 end
34 34
35 def test_get_watch_should_be_invalid
36 @request.session[:user_id] = 3
37 get :watch, :object_type => 'issue', :object_id => '1'
38 assert_response 405
39 end
40
41 35 def test_watch
42 36 @request.session[:user_id] = 3
43 37 assert_difference('Watcher.count') do
@@ -206,4 +206,23 class IssuesTest < ActionController::IntegrationTest
206 206 }
207 207 }
208 208 end
209
210 def test_update_using_invalid_http_verbs
211 subject = 'Updated by an invalid http verb'
212
213 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
214 assert_response 404
215 assert_not_equal subject, Issue.find(1).subject
216
217 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
218 assert_response 405
219 assert_not_equal subject, Issue.find(1).subject
220 end
221
222 def test_get_watch_should_be_invalid
223 assert_no_difference 'Watcher.count' do
224 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
225 assert_response 405
226 end
227 end
209 228 end
@@ -18,7 +18,7
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class ProjectsTest < ActionController::IntegrationTest
21 fixtures :projects, :users, :members
21 fixtures :projects, :users, :members, :enabled_modules
22 22
23 23 def test_archive_project
24 24 subproject = Project.find(1).children.first
@@ -41,4 +41,11 class ProjectsTest < ActionController::IntegrationTest
41 41 get "projects/1"
42 42 assert_response :success
43 43 end
44
45 def test_modules_should_not_allow_get
46 assert_no_difference 'EnabledModule.count' do
47 get '/projects/1/modules', {:enabled_module_names => ['']}, credentials('jsmith')
48 assert_response :method_not_allowed
49 end
50 end
44 51 end
General Comments 0
You need to be logged in to leave comments. Login now