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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. self.main_menu = false
  20. menu_item :plugins, :only => :plugin
  21. helper :queries
  22. before_action :require_admin
  23. require_sudo_mode :index, :edit, :plugin
  24. def index
  25. edit
  26. render :action => 'edit'
  27. end
  28. def edit
  29. @notifiables = Redmine::Notifiable.all
  30. if request.post?
  31. errors = Setting.set_all_from_params(params[:settings].to_unsafe_hash)
  32. if errors.blank?
  33. flash[:notice] = l(:notice_successful_update)
  34. redirect_to settings_path(:tab => params[:tab])
  35. return
  36. else
  37. @setting_errors = errors
  38. # render the edit form with error messages
  39. end
  40. end
  41. @options = {}
  42. user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort_by{|f| f[1]}
  43. @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
  44. @deliveries = ActionMailer::Base.perform_deliveries
  45. @guessed_host_and_path = request.host_with_port.dup
  46. @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
  47. @commit_update_keywords = Setting.commit_update_keywords.dup
  48. @commit_update_keywords = [{}] unless @commit_update_keywords.is_a?(Array) && @commit_update_keywords.any?
  49. Redmine::Themes.rescan
  50. end
  51. def plugin
  52. @plugin = Redmine::Plugin.find(params[:id])
  53. unless @plugin.configurable?
  54. render_404
  55. return
  56. end
  57. if request.post?
  58. setting = params[:settings] ? params[:settings].permit!.to_h : {}
  59. Setting.send "plugin_#{@plugin.id}=", setting
  60. flash[:notice] = l(:notice_successful_update)
  61. redirect_to plugin_settings_path(@plugin)
  62. else
  63. @partial = @plugin.settings[:partial]
  64. @settings = Setting.send "plugin_#{@plugin.id}"
  65. end
  66. rescue Redmine::PluginNotFound
  67. render_404
  68. end
  69. end