##// END OF EJS Templates
Introduce virtual MenuNodes (#15880)....
Introduce virtual MenuNodes (#15880). They are characterized by having a blank url. they will only be rendered if the user is authorized to see at least one of its children. they render as links which do nothing when clicked. Patch by Jan Schulz-Hofen. git-svn-id: http://svn.redmine.org/redmine/trunk@15501 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r14856:cda9c63d9c21
r15119:53710d80fc88
Show More
setting.rb
293 lines | 8.2 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 Jean-Philippe Lang
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
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.
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 #
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
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.
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 #
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
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 Setting < ActiveRecord::Base
Jean-Philippe Lang
Added a couple of new formats for the 'date format' setting....
r892 DATE_FORMATS = [
Toshi MARUYAMA
replace tabs to spaces at app/models/setting.rb...
r11191 '%Y-%m-%d',
'%d/%m/%Y',
'%d.%m.%Y',
'%d-%m-%Y',
'%m/%d/%Y',
'%d %b %Y',
'%d %B %Y',
'%b %d, %Y',
'%B %d, %Y'
Jean-Philippe Lang
Added a couple of new formats for the 'date format' setting....
r892 ]
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Added a couple of new formats for the 'date format' setting....
r892 TIME_FORMATS = [
'%H:%M',
'%I:%M %p'
]
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Adds support for commit logs reencoding to UTF-8 before insertion in the database (#834, #917, #1663)....
r1766 ENCODINGS = %w(US-ASCII
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
windows-31j
ISO-2022-JP
ISO-2022-KR
ISO-8859-1
ISO-8859-2
ISO-8859-3
ISO-8859-4
ISO-8859-5
ISO-8859-6
ISO-8859-7
ISO-8859-8
ISO-8859-9
ISO-8859-13
ISO-8859-15
KOI8-R
UTF-8
UTF-16
UTF-16BE
UTF-16LE
EUC-JP
Shift_JIS
Toshi MARUYAMA
scm: add CP932 at Setting::ENCODINGS (#2664, #2274)....
r4779 CP932
Jean-Philippe Lang
Adds support for commit logs reencoding to UTF-8 before insertion in the database (#834, #917, #1663)....
r1766 GB18030
GBK
ISCII91
EUC-KR
Big5
Big5-HKSCS
TIS-620)
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 cattr_accessor :available_settings
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 self.available_settings ||= {}
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Skip uniqueness validation when updating a setting without changing its name....
r13338 validates_uniqueness_of :name, :if => Proc.new {|setting| setting.new_record? || setting.name_changed?}
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 validates_inclusion_of :name, :in => Proc.new {available_settings.keys}
Jean-Philippe Lang
Fixed that validating a Setting with invalid name triggers an error (#15551)....
r12097 validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting|
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 (s = available_settings[setting.name]) && s['format'] == 'int'
Jean-Philippe Lang
Fixed that validating a Setting with invalid name triggers an error (#15551)....
r12097 }
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 attr_protected :id
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674
# Hash used to cache setting values
@cached_settings = {}
@cached_cleared_on = Time.now
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 def value
v = read_attribute(:value)
# Unserialize serialized settings
Jean-Philippe Lang
Make sure that settings are unserialized as UTF-8 encoded strings (#19305)....
r13730 if available_settings[name]['serialized'] && v.is_a?(String)
v = YAML::load(v)
v = force_utf8_strings(v)
end
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank?
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 v
end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Fixed: Oracle error when saving serialized setting (eg. mail notifications)...
r731 def value=(v)
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 v = v.to_yaml if v && available_settings[name] && available_settings[name]['serialized']
Jean-Philippe Lang
User display format is now configurable in administration settings....
r1089 write_attribute(:value, v.to_s)
Jean-Philippe Lang
Fixed: Oracle error when saving serialized setting (eg. mail notifications)...
r731 end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 # Returns the value of the setting named name
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 def self.[](name)
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 v = @cached_settings[name]
v ? v : (@cached_settings[name] = find_or_default(name).value)
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 def self.[]=(name, v)
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 setting = find_or_default(name)
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 setting.value = (v ? v : "")
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 @cached_settings[name] = nil
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 setting.save
setting.value
end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Send a notification when security settings are changed (#21421)....
r14766 # Updates multiple settings from params and sends a security notification if needed
def self.set_all_from_params(settings)
settings = (settings || {}).dup.symbolize_keys
changes = []
settings.each do |name, value|
previous_value = Setting[name]
set_from_params name, value
if available_settings[name.to_s]['security_notifications'] && Setting[name] != previous_value
changes << name
end
end
if changes.any?
Mailer.security_settings_updated(changes)
end
true
end
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 # Sets a setting value from params
def self.set_from_params(name, params)
params = params.dup
params.delete_if {|v| v.blank? } if params.is_a?(Array)
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 params.symbolize_keys! if params.is_a?(Hash)
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967
m = "#{name}_from_params"
if respond_to? m
self[name.to_sym] = send m, params
else
self[name.to_sym] = params
end
end
# Returns a hash suitable for commit_update_keywords setting
#
# Example:
# params = {:keywords => ['fixes', 'closes'], :status_id => ["3", "5"], :done_ratio => ["", "100"]}
# Setting.commit_update_keywords_from_params(params)
Jean-Philippe Lang
Ability to define commit keywords per tracker (#7590)....
r11978 # # => [{'keywords => 'fixes', 'status_id' => "3"}, {'keywords => 'closes', 'status_id' => "5", 'done_ratio' => "100"}]
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 def self.commit_update_keywords_from_params(params)
Jean-Philippe Lang
Ability to define commit keywords per tracker (#7590)....
r11978 s = []
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 if params.is_a?(Hash) && params.key?(:keywords) && params.values.all? {|v| v.is_a? Array}
attributes = params.except(:keywords).keys
params[:keywords].each_with_index do |keywords, i|
next if keywords.blank?
Jean-Philippe Lang
Ability to define commit keywords per tracker (#7590)....
r11978 s << attributes.inject({}) {|h, a|
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 value = params[a][i].to_s
h[a.to_s] = value if value.present?
h
Jean-Philippe Lang
Ability to define commit keywords per tracker (#7590)....
r11978 }.merge('keywords' => keywords)
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 end
end
s
end
Jean-Philippe Lang
New setting added to specify how many objects should be displayed on most paginated lists....
r1013 # Helper that returns an array based on per_page_options setting
def self.per_page_options_array
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 # Helper that returns a Hash with single update keywords as keys
Jean-Philippe Lang
Ability to define commit keywords per tracker (#7590)....
r11978 def self.commit_update_keywords_array
a = []
if commit_update_keywords.is_a?(Array)
commit_update_keywords.each do |rule|
next unless rule.is_a?(Hash)
rule = rule.dup
rule.delete_if {|k, v| v.blank?}
keywords = rule['keywords'].to_s.downcase.split(",").map(&:strip).reject(&:blank?)
next if keywords.empty?
a << rule.merge('keywords' => keywords)
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 end
end
Jean-Philippe Lang
Ability to define commit keywords per tracker (#7590)....
r11978 a
Jean-Philippe Lang
Support for multiple issue update keywords/rules in commit messages (#4911)....
r11967 end
Jean-Philippe Lang
Removes the fat ruby-openid gem. Simply use 'gem install ruby-openid' to enable openid support....
r2397 def self.openid?
Jean-Philippe Lang
Fixes Setting.openid? (#2764)....
r2419 Object.const_defined?(:OpenID) && self[:openid].to_i > 0
Jean-Philippe Lang
Removes the fat ruby-openid gem. Simply use 'gem install ruby-openid' to enable openid support....
r2397 end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 # Checks if settings have changed since the values were read
# and clears the cache hash if it's the case
# Called once per request
def self.check_cache
settings_updated_on = Setting.maximum(:updated_on)
if settings_updated_on && @cached_cleared_on <= settings_updated_on
Jean-Philippe Lang
Adds a method to clear the settings cache....
r7684 clear_cache
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 end
end
Toshi MARUYAMA
remove trailing white-space from app/models/setting.rb...
r11458
Jean-Philippe Lang
Adds a method to clear the settings cache....
r7684 # Clears the settings cache
def self.clear_cache
@cached_settings.clear
@cached_cleared_on = Time.now
logger.info "Settings cache cleared." if logger
end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 def self.define_plugin_setting(plugin)
if plugin.settings
name = "plugin_#{plugin.id}"
define_setting name, {'default' => plugin.settings[:default], 'serialized' => true}
end
end
# Defines getter and setter for each setting
# Then setting values can be read using: Setting.some_setting_name
# or set using Setting.some_setting_name = "some value"
def self.define_setting(name, options={})
available_settings[name.to_s] = options
src = <<-END_SRC
def self.#{name}
self[:#{name}]
end
def self.#{name}?
self[:#{name}].to_i > 0
end
def self.#{name}=(value)
self[:#{name}] = value
end
END_SRC
class_eval src, __FILE__, __LINE__
end
def self.load_available_settings
YAML::load(File.open("#{Rails.root}/config/settings.yml")).each do |name, options|
define_setting name, options
end
end
def self.load_plugin_settings
Redmine::Plugin.all.each do |plugin|
define_plugin_setting(plugin)
end
end
load_available_settings
load_plugin_settings
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 private
Jean-Philippe Lang
Make sure that settings are unserialized as UTF-8 encoded strings (#19305)....
r13730
def force_utf8_strings(arg)
Jean-Philippe Lang
Reverts r14115 in trunk....
r13735 if arg.is_a?(String)
Jean-Philippe Lang
Make sure that settings are unserialized as UTF-8 encoded strings (#19305)....
r13730 arg.dup.force_encoding('UTF-8')
elsif arg.is_a?(Array)
arg.map do |a|
force_utf8_strings(a)
end
elsif arg.is_a?(Hash)
arg = arg.dup
arg.each do |k,v|
arg[k] = force_utf8_strings(v)
end
arg
else
arg
end
end
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 # Returns the Setting instance for the setting named name
# (record found in database or new record with default value)
def self.find_or_default(name)
name = name.to_s
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 raise "There's no setting named #{name}" unless available_settings.has_key?(name)
Jean-Philippe Lang
Specify the order for finding a setting....
r13339 setting = where(:name => name).order(:id => :desc).first
Jean-Philippe Lang
Fixed random failures in RepositoriesControllerTest with ruby-1.8.7-p358....
r8789 unless setting
Toshi MARUYAMA
Rails4 compatibility of Setting model...
r12148 setting = new
setting.name = name
Jean-Philippe Lang
Adds methods for loading and adding settings....
r13337 setting.value = available_settings[name]['default']
Jean-Philippe Lang
Fixed random failures in RepositoriesControllerTest with ruby-1.8.7-p358....
r8789 end
setting
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 end
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 end