settings_controller.rb
76 lines
| 2.6 KiB
| text/x-ruby
|
RubyLexer
|
r5707 | # Redmine - project management software | ||
|
r13490 | # Copyright (C) 2006-2015 Jean-Philippe Lang | ||
|
r164 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
|
r1987 | # | ||
|
r164 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r1987 | # | ||
|
r164 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
class SettingsController < ApplicationController | ||||
|
r3062 | layout 'admin' | ||
|
r8559 | menu_item :plugins, :only => :plugin | ||
|
r5707 | |||
|
r11221 | helper :queries | ||
|
r164 | before_filter :require_admin | ||
|
r1987 | |||
|
r13951 | require_sudo_mode :index, :edit, :plugin | ||
|
r164 | def index | ||
edit | ||||
render :action => 'edit' | ||||
end | ||||
def edit | ||||
|
r4106 | @notifiables = Redmine::Notifiable.all | ||
|
r1033 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) | ||
settings = (params[:settings] || {}).dup.symbolize_keys | ||||
settings.each do |name, value| | ||||
|
r11967 | Setting.set_from_params name, value | ||
|
r1033 | end | ||
flash[:notice] = l(:notice_successful_update) | ||||
|
r10754 | redirect_to settings_path(:tab => params[:tab]) | ||
|
r5491 | else | ||
@options = {} | ||||
|
r10331 | user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]} | ||
|
r10333 | @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]} | ||
|
r5491 | @deliveries = ActionMailer::Base.perform_deliveries | ||
|
r1987 | |||
|
r5491 | @guessed_host_and_path = request.host_with_port.dup | ||
@guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank? | ||||
|
r5707 | |||
|
r11967 | @commit_update_keywords = Setting.commit_update_keywords.dup | ||
|
r11986 | @commit_update_keywords = [{}] unless @commit_update_keywords.is_a?(Array) && @commit_update_keywords.any? | ||
|
r11967 | |||
|
r5491 | Redmine::Themes.rescan | ||
end | ||||
|
r164 | end | ||
|
r1987 | |||
|
r741 | def plugin | ||
|
r2037 | @plugin = Redmine::Plugin.find(params[:id]) | ||
|
r10986 | unless @plugin.configurable? | ||
render_404 | ||||
return | ||||
end | ||||
|
r741 | if request.post? | ||
|
r7919 | Setting.send "plugin_#{@plugin.id}=", params[:settings] | ||
|
r741 | flash[:notice] = l(:notice_successful_update) | ||
|
r10766 | redirect_to plugin_settings_path(@plugin) | ||
|
r5491 | else | ||
@partial = @plugin.settings[:partial] | ||||
|
r7919 | @settings = Setting.send "plugin_#{@plugin.id}" | ||
|
r741 | end | ||
|
r2037 | rescue Redmine::PluginNotFound | ||
render_404 | ||||
|
r741 | end | ||
|
r164 | end | ||