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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class SettingsController < ApplicationController
  19. layout 'admin'
  20. self.main_menu = false
  21. menu_item :plugins, :only => :plugin
  22. helper :queries
  23. before_action :require_admin
  24. require_sudo_mode :index, :edit, :plugin
  25. def index
  26. edit
  27. render :action => 'edit'
  28. end
  29. def edit
  30. @notifiables = Redmine::Notifiable.all
  31. if request.post?
  32. errors = Setting.set_all_from_params(params[:settings].to_unsafe_hash)
  33. if errors.blank?
  34. flash[:notice] = l(:notice_successful_update)
  35. redirect_to settings_path(:tab => params[:tab])
  36. return
  37. else
  38. @setting_errors = errors
  39. # render the edit form with error messages
  40. end
  41. end
  42. @options = {}
  43. user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort_by{|f| f[1]}
  44. @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
  45. @deliveries = ActionMailer::Base.perform_deliveries
  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?
  48. @commit_update_keywords = Setting.commit_update_keywords.dup
  49. @commit_update_keywords = [{}] unless @commit_update_keywords.is_a?(Array) && @commit_update_keywords.any?
  50. Redmine::Themes.rescan
  51. end
  52. def plugin
  53. @plugin = Redmine::Plugin.find(params[:id])
  54. unless @plugin.configurable?
  55. render_404
  56. return
  57. end
  58. if request.post?
  59. setting = params[:settings] ? params[:settings].permit!.to_h : {}
  60. Setting.send "plugin_#{@plugin.id}=", setting
  61. flash[:notice] = l(:notice_successful_update)
  62. redirect_to plugin_settings_path(@plugin)
  63. else
  64. @partial = @plugin.settings[:partial]
  65. @settings = Setting.send "plugin_#{@plugin.id}"
  66. end
  67. rescue Redmine::PluginNotFound
  68. render_404
  69. end
  70. end