mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-24 08:07:14 +00:00
Don't use SudoMode.disable! to skip API requests (#19851).
git-svn-id: http://svn.redmine.org/redmine/trunk@14338 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
fe9eec19c5
commit
c2fca37999
@ -61,9 +61,7 @@ module Redmine
|
|||||||
# After the request refreshes the timestamp if sudo mode was used during
|
# After the request refreshes the timestamp if sudo mode was used during
|
||||||
# this request.
|
# this request.
|
||||||
def sudo_mode
|
def sudo_mode
|
||||||
if api_request?
|
if sudo_timestamp_valid?
|
||||||
SudoMode.disable!
|
|
||||||
elsif sudo_timestamp_valid?
|
|
||||||
SudoMode.active!
|
SudoMode.active!
|
||||||
end
|
end
|
||||||
yield
|
yield
|
||||||
@ -145,7 +143,9 @@ module Redmine
|
|||||||
class SudoRequestFilter < Struct.new(:parameters, :request_methods)
|
class SudoRequestFilter < Struct.new(:parameters, :request_methods)
|
||||||
def before(controller)
|
def before(controller)
|
||||||
method_matches = request_methods.blank? || request_methods.include?(controller.request.method_symbol)
|
method_matches = request_methods.blank? || request_methods.include?(controller.request.method_symbol)
|
||||||
if SudoMode.possible? && method_matches
|
if controller.api_request?
|
||||||
|
true
|
||||||
|
elsif SudoMode.possible? && method_matches
|
||||||
controller.require_sudo_mode( *parameters )
|
controller.require_sudo_mode( *parameters )
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
|
|||||||
@ -143,4 +143,19 @@ class SudoTest < Redmine::IntegrationTest
|
|||||||
assert_equal 'even.newer.mail@test.com', User.find_by_login('jsmith').mail
|
assert_equal 'even.newer.mail@test.com', User.find_by_login('jsmith').mail
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sudo_mode_should_skip_api_requests
|
||||||
|
with_settings :rest_api_enabled => '1' do
|
||||||
|
assert_difference('User.count') do
|
||||||
|
post '/users.json', {
|
||||||
|
:user => {
|
||||||
|
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
|
||||||
|
:mail => 'foo@example.net', :password => 'secret123',
|
||||||
|
:mail_notification => 'only_assigned'}
|
||||||
|
},
|
||||||
|
credentials('admin')
|
||||||
|
|
||||||
|
assert_response :created
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user