You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings_controller.rb 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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. class SettingsController < ApplicationController
  18. layout 'admin'
  19. menu_item :plugins, :only => :plugin
  20. before_filter :require_admin
  21. def index
  22. edit
  23. render :action => 'edit'
  24. end
  25. def edit
  26. @notifiables = Redmine::Notifiable.all
  27. if request.post? && params[:settings] && params[:settings].is_a?(Hash)
  28. settings = (params[:settings] || {}).dup.symbolize_keys
  29. settings.each do |name, value|
  30. # remove blank values in array settings
  31. value.delete_if {|v| v.blank? } if value.is_a?(Array)
  32. Setting[name] = value
  33. end
  34. flash[:notice] = l(:notice_successful_update)
  35. redirect_to settings_path(:tab => params[:tab])
  36. else
  37. @options = {}
  38. user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]}
  39. @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
  40. @deliveries = ActionMailer::Base.perform_deliveries
  41. @guessed_host_and_path = request.host_with_port.dup
  42. @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
  43. Redmine::Themes.rescan
  44. end
  45. end
  46. def plugin
  47. @plugin = Redmine::Plugin.find(params[:id])
  48. unless @plugin.configurable?
  49. render_404
  50. return
  51. end
  52. if request.post?
  53. Setting.send "plugin_#{@plugin.id}=", params[:settings]
  54. flash[:notice] = l(:notice_successful_update)
  55. redirect_to plugin_settings_path(@plugin)
  56. else
  57. @partial = @plugin.settings[:partial]
  58. @settings = Setting.send "plugin_#{@plugin.id}"
  59. end
  60. rescue Redmine::PluginNotFound
  61. render_404
  62. end
  63. end