##// END OF EJS Templates
Fix 500 error for requests to the settings path for non-configurable plugins (#12911)....
Jean-Philippe Lang -
r10986:bb314029391d
parent child
Show More
@@ -1,66 +1,71
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class SettingsController < ApplicationController
18 class SettingsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 menu_item :plugins, :only => :plugin
20 menu_item :plugins, :only => :plugin
21
21
22 before_filter :require_admin
22 before_filter :require_admin
23
23
24 def index
24 def index
25 edit
25 edit
26 render :action => 'edit'
26 render :action => 'edit'
27 end
27 end
28
28
29 def edit
29 def edit
30 @notifiables = Redmine::Notifiable.all
30 @notifiables = Redmine::Notifiable.all
31 if request.post? && params[:settings] && params[:settings].is_a?(Hash)
31 if request.post? && params[:settings] && params[:settings].is_a?(Hash)
32 settings = (params[:settings] || {}).dup.symbolize_keys
32 settings = (params[:settings] || {}).dup.symbolize_keys
33 settings.each do |name, value|
33 settings.each do |name, value|
34 # remove blank values in array settings
34 # remove blank values in array settings
35 value.delete_if {|v| v.blank? } if value.is_a?(Array)
35 value.delete_if {|v| v.blank? } if value.is_a?(Array)
36 Setting[name] = value
36 Setting[name] = value
37 end
37 end
38 flash[:notice] = l(:notice_successful_update)
38 flash[:notice] = l(:notice_successful_update)
39 redirect_to settings_path(:tab => params[:tab])
39 redirect_to settings_path(:tab => params[:tab])
40 else
40 else
41 @options = {}
41 @options = {}
42 user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]}
42 user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]}
43 @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
43 @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
44 @deliveries = ActionMailer::Base.perform_deliveries
44 @deliveries = ActionMailer::Base.perform_deliveries
45
45
46 @guessed_host_and_path = request.host_with_port.dup
46 @guessed_host_and_path = request.host_with_port.dup
47 @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
47 @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
48
48
49 Redmine::Themes.rescan
49 Redmine::Themes.rescan
50 end
50 end
51 end
51 end
52
52
53 def plugin
53 def plugin
54 @plugin = Redmine::Plugin.find(params[:id])
54 @plugin = Redmine::Plugin.find(params[:id])
55 unless @plugin.configurable?
56 render_404
57 return
58 end
59
55 if request.post?
60 if request.post?
56 Setting.send "plugin_#{@plugin.id}=", params[:settings]
61 Setting.send "plugin_#{@plugin.id}=", params[:settings]
57 flash[:notice] = l(:notice_successful_update)
62 flash[:notice] = l(:notice_successful_update)
58 redirect_to plugin_settings_path(@plugin)
63 redirect_to plugin_settings_path(@plugin)
59 else
64 else
60 @partial = @plugin.settings[:partial]
65 @partial = @plugin.settings[:partial]
61 @settings = Setting.send "plugin_#{@plugin.id}"
66 @settings = Setting.send "plugin_#{@plugin.id}"
62 end
67 end
63 rescue Redmine::PluginNotFound
68 rescue Redmine::PluginNotFound
64 render_404
69 render_404
65 end
70 end
66 end
71 end
@@ -1,111 +1,131
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class SettingsControllerTest < ActionController::TestCase
20 class SettingsControllerTest < ActionController::TestCase
21 fixtures :users
21 fixtures :users
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 @request.session[:user_id] = 1 # admin
25 @request.session[:user_id] = 1 # admin
26 end
26 end
27
27
28 def test_index
28 def test_index
29 get :index
29 get :index
30 assert_response :success
30 assert_response :success
31 assert_template 'edit'
31 assert_template 'edit'
32 end
32 end
33
33
34 def test_get_edit
34 def test_get_edit
35 get :edit
35 get :edit
36 assert_response :success
36 assert_response :success
37 assert_template 'edit'
37 assert_template 'edit'
38
38
39 assert_tag 'input', :attributes => {:name => 'settings[enabled_scm][]', :value => ''}
39 assert_tag 'input', :attributes => {:name => 'settings[enabled_scm][]', :value => ''}
40 end
40 end
41
41
42 def test_get_edit_should_preselect_default_issue_list_columns
42 def test_get_edit_should_preselect_default_issue_list_columns
43 with_settings :issue_list_default_columns => %w(tracker subject status updated_on) do
43 with_settings :issue_list_default_columns => %w(tracker subject status updated_on) do
44 get :edit
44 get :edit
45 assert_response :success
45 assert_response :success
46 end
46 end
47
47
48 assert_select 'select[id=selected_columns][name=?]', 'settings[issue_list_default_columns][]' do
48 assert_select 'select[id=selected_columns][name=?]', 'settings[issue_list_default_columns][]' do
49 assert_select 'option', 4
49 assert_select 'option', 4
50 assert_select 'option[value=tracker]', :text => 'Tracker'
50 assert_select 'option[value=tracker]', :text => 'Tracker'
51 assert_select 'option[value=subject]', :text => 'Subject'
51 assert_select 'option[value=subject]', :text => 'Subject'
52 assert_select 'option[value=status]', :text => 'Status'
52 assert_select 'option[value=status]', :text => 'Status'
53 assert_select 'option[value=updated_on]', :text => 'Updated'
53 assert_select 'option[value=updated_on]', :text => 'Updated'
54 end
54 end
55
55
56 assert_select 'select[id=available_columns]' do
56 assert_select 'select[id=available_columns]' do
57 assert_select 'option[value=tracker]', 0
57 assert_select 'option[value=tracker]', 0
58 assert_select 'option[value=priority]', :text => 'Priority'
58 assert_select 'option[value=priority]', :text => 'Priority'
59 end
59 end
60 end
60 end
61
61
62 def test_get_edit_without_trackers_should_succeed
62 def test_get_edit_without_trackers_should_succeed
63 Tracker.delete_all
63 Tracker.delete_all
64
64
65 get :edit
65 get :edit
66 assert_response :success
66 assert_response :success
67 end
67 end
68
68
69 def test_post_edit_notifications
69 def test_post_edit_notifications
70 post :edit, :settings => {:mail_from => 'functional@test.foo',
70 post :edit, :settings => {:mail_from => 'functional@test.foo',
71 :bcc_recipients => '0',
71 :bcc_recipients => '0',
72 :notified_events => %w(issue_added issue_updated news_added),
72 :notified_events => %w(issue_added issue_updated news_added),
73 :emails_footer => 'Test footer'
73 :emails_footer => 'Test footer'
74 }
74 }
75 assert_redirected_to '/settings'
75 assert_redirected_to '/settings'
76 assert_equal 'functional@test.foo', Setting.mail_from
76 assert_equal 'functional@test.foo', Setting.mail_from
77 assert !Setting.bcc_recipients?
77 assert !Setting.bcc_recipients?
78 assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
78 assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
79 assert_equal 'Test footer', Setting.emails_footer
79 assert_equal 'Test footer', Setting.emails_footer
80 Setting.clear_cache
80 Setting.clear_cache
81 end
81 end
82
82
83 def test_get_plugin_settings
83 def test_get_plugin_settings
84 Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'})
84 Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'})
85 ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins"))
85 ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins"))
86 Redmine::Plugin.register :foo do
86 Redmine::Plugin.register :foo do
87 settings :partial => "foo_plugin/foo_plugin_settings"
87 settings :partial => "foo_plugin/foo_plugin_settings"
88 end
88 end
89
89
90 get :plugin, :id => 'foo'
90 get :plugin, :id => 'foo'
91 assert_response :success
91 assert_response :success
92 assert_template 'plugin'
92 assert_template 'plugin'
93 assert_tag 'form', :attributes => {:action => '/settings/plugin/foo'},
93 assert_tag 'form', :attributes => {:action => '/settings/plugin/foo'},
94 :descendant => {:tag => 'input', :attributes => {:name => 'settings[sample_setting]', :value => 'Plugin setting value'}}
94 :descendant => {:tag => 'input', :attributes => {:name => 'settings[sample_setting]', :value => 'Plugin setting value'}}
95
95
96 Redmine::Plugin.clear
96 Redmine::Plugin.clear
97 end
97 end
98
98
99 def test_get_invalid_plugin_settings
99 def test_get_invalid_plugin_settings
100 get :plugin, :id => 'none'
100 get :plugin, :id => 'none'
101 assert_response 404
101 assert_response 404
102 end
102 end
103
103
104 def test_get_non_configurable_plugin_settings
105 Redmine::Plugin.register(:foo) {}
106
107 get :plugin, :id => 'foo'
108 assert_response 404
109
110 Redmine::Plugin.clear
111 end
112
104 def test_post_plugin_settings
113 def test_post_plugin_settings
105 Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true)
114 Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true)
106 Redmine::Plugin.register(:foo) {}
115 Redmine::Plugin.register(:foo) do
116 settings :partial => 'not blank' # so that configurable? is true
117 end
107
118
108 post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'}
119 post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'}
109 assert_redirected_to '/settings/plugin/foo'
120 assert_redirected_to '/settings/plugin/foo'
110 end
121 end
122
123 def test_post_non_configurable_plugin_settings
124 Redmine::Plugin.register(:foo) {}
125
126 post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'}
127 assert_response 404
128
129 Redmine::Plugin.clear
130 end
111 end
131 end
General Comments 0
You need to be logged in to leave comments. Login now