##// END OF EJS Templates
set default category_id instead of the object (#11665)...
set default category_id instead of the object (#11665) Rails 2.3 still has issues with synchronizing the association_id and association attributes of an object. That means, if you set the association with an object first and then just set the id afterwards, the object wins and the setting of the id gets lost. This is not an issue in Rails >= 3.1 anymore. Contributed by Holger Just. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@10226 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r8789:59c2530001b4
r10043:14dcefaa97f9
Show More
setting.rb
178 lines | 5.1 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 # Redmine - project management software
# Copyright (C) 2006-2011 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 = [
'%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'
]
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
Toshi MARUYAMA
replace RAILS_ROOT to Rails.root in setting model....
r5956 @@available_settings = YAML::load(File.open("#{Rails.root}/config/settings.yml"))
Jean-Philippe Lang
Adds .find and .all Plugin class methods....
r2037 Redmine::Plugin.all.each do |plugin|
Jean-Philippe Lang
Basic plugin support....
r741 next unless plugin.settings
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 @@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
Jean-Philippe Lang
Basic plugin support....
r741 end
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 validates_uniqueness_of :name
validates_inclusion_of :name, :in => @@available_settings.keys
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
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
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
Jean-Philippe Lang
User display format is now configurable in administration settings....
r1089 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)
Eric Davis
Fixed a nil method error in Setting#value=...
r3303 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
Added cache for application settings (Setting model)....
r674 # 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"
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 @@available_settings.each do |name, params|
src = <<-END_SRC
def self.#{name}
self[:#{name}]
end
def self.#{name}?
Jean-Philippe Lang
Added autologin feature (disabled by default)....
r511 self[:#{name}].to_i > 0
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
def self.#{name}=(value)
Jean-Philippe Lang
* fixed a variable name error in Setting...
r210 self[:#{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
END_SRC
class_eval src, __FILE__, __LINE__
end
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708
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
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
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
Added cache for application settings (Setting model)....
r674 private
# 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
Toshi MARUYAMA
remove trailing white-spaces from setting model source....
r5708 raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 setting = find_by_name(name)
Jean-Philippe Lang
Fixed random failures in RepositoriesControllerTest with ruby-1.8.7-p358....
r8789 unless setting
setting = new(:name => name)
setting.value = @@available_settings[name]['default']
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