From 0b4d4db131304eac84dc90b289a95db3410a2bfe Mon Sep 17 00:00:00 2001
From: Jean-Philippe Lang
Date: Sun, 21 Jan 2007 11:50:22 +0000
Subject: [PATCH] settings are now stored in the database (config_custom.rb no
more used) and editable through the application in: Admin -> Settings
git-svn-id: http://redmine.rubyforge.org/svn/trunk@167 e93f8b46-1217-0410-a6f0-8f06a7374b81
---
app/controllers/account_controller.rb | 6 +--
app/controllers/application.rb | 6 +--
app/controllers/settings_controller.rb | 33 ++++++++++++
app/controllers/users_controller.rb | 4 +-
app/helpers/application_helper.rb | 9 ++--
app/helpers/settings_helper.rb | 19 +++++++
app/models/attachment.rb | 15 +++---
app/models/mailer.rb | 11 ++--
app/models/setting.rb | 61 +++++++++++++++++++++
app/models/user.rb | 4 +-
app/views/account/login.rhtml | 2 +-
app/views/admin/index.rhtml | 4 ++
app/views/documents/_form.rhtml | 2 +-
app/views/documents/show.rhtml | 2 +-
app/views/feeds/news.rxml | 4 +-
app/views/issues/edit.rhtml | 2 +-
app/views/issues/show.rhtml | 2 +-
app/views/layouts/base.rhtml | 12 ++---
app/views/mailer/_issue.rhtml | 2 +-
app/views/mailer/lost_password_de.rhtml | 2 +-
app/views/mailer/lost_password_en.rhtml | 2 +-
app/views/mailer/lost_password_es.rhtml | 2 +-
app/views/mailer/lost_password_fr.rhtml | 2 +-
app/views/mailer/register_de.rhtml | 2 +-
app/views/mailer/register_en.rhtml | 2 +-
app/views/mailer/register_es.rhtml | 2 +-
app/views/mailer/register_fr.rhtml | 2 +-
app/views/news/_form.rhtml | 2 +-
app/views/projects/add_document.rhtml | 2 +-
app/views/projects/add_file.rhtml | 2 +-
app/views/projects/add_issue.rhtml | 4 +-
app/views/settings/edit.rhtml | 37 +++++++++++++
app/views/welcome/index.rhtml | 4 +-
config/config_custom.example.rb | 69 ------------------------
config/environment.rb | 38 +------------
config/settings.yml | 42 +++++++++++++++
db/migrate/017_create_settings.rb | 12 +++++
doc/CHANGELOG | 11 +++-
doc/INSTALL | 7 ++-
doc/UPGRADING | 8 +--
lib/tasks/load_default_data.rake | 2 +-
public/images/22x22/settings.png | Bin 0 -> 772 bytes
public/stylesheets/application.css | 1 +
test/unit/project_test.rb | 2 +-
44 files changed, 286 insertions(+), 173 deletions(-)
create mode 100644 app/controllers/settings_controller.rb
create mode 100644 app/helpers/settings_helper.rb
create mode 100644 app/models/setting.rb
create mode 100644 app/views/settings/edit.rhtml
delete mode 100644 config/config_custom.example.rb
create mode 100644 config/settings.yml
create mode 100644 db/migrate/017_create_settings.rb
create mode 100644 public/images/22x22/settings.png
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index fb775d19..c3b0ebd7 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -95,7 +95,7 @@ class AccountController < ApplicationController
# User self-registration
def register
- redirect_to :controller => '' and return if $RDM_SELF_REGISTRATION == false
+ redirect_to :controller => '' and return unless Setting.self_registration?
if params[:token]
token = Token.find_by_action_and_value("register", params[:token])
redirect_to :controller => '' and return unless token and !token.expired?
@@ -110,7 +110,7 @@ class AccountController < ApplicationController
end
else
if request.get?
- @user = User.new(:language => $RDM_DEFAULT_LANG)
+ @user = User.new(:language => Setting.default_language)
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
else
@user = User.new(params[:user])
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index da01e09c..bae05ce1 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -33,7 +33,7 @@ class ApplicationController < ActionController::Base
# check if login is globally required to access the application
def check_if_login_required
- require_login if $RDM_LOGIN_REQUIRED
+ require_login if Setting.login_required?
end
def set_localization
@@ -48,7 +48,7 @@ class ApplicationController < ActionController::Base
end
rescue
nil
- end || $RDM_DEFAULT_LANG
+ end || Setting.default_language
set_language_if_valid(lang)
end
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
new file mode 100644
index 00000000..229a4ab3
--- /dev/null
+++ b/app/controllers/settings_controller.rb
@@ -0,0 +1,33 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# 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.
+#
+# 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.
+#
+# 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
+ layout 'base'
+ before_filter :require_admin
+
+ def index
+ edit
+ render :action => 'edit'
+ end
+
+ def edit
+ if request.post? and params[:settings] and params[:settings].is_a? Hash
+ params[:settings].each { |name, value| Setting[name] = value }
+ redirect_to :action => 'edit' and return
+ end
+ end
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 4c403a8d..14f8ecff 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -45,7 +45,7 @@ class UsersController < ApplicationController
def add
if request.get?
- @user = User.new(:language => $RDM_DEFAULT_LANG)
+ @user = User.new(:language => Setting.default_language)
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
else
@user = User.new(params[:user])
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0f0d577e..748a1d7e 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -93,7 +93,7 @@ module ApplicationHelper
end
def textilizable(text)
- $RDM_TEXTILE_DISABLED ? simple_format(auto_link(h(text))) : RedCloth.new(h(text)).to_html
+ (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") ? RedCloth.new(h(text)).to_html : simple_format(auto_link(h(text)))
end
def error_messages_for(object_name, options = {})
@@ -131,8 +131,9 @@ module ApplicationHelper
end
end
- def lang_options_for_select
- [["(auto)", ""]] + (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
+ def lang_options_for_select(blank=true)
+ (blank ? [["(auto)", ""]] : []) +
+ (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
end
def label_tag_for(name, option_tags = nil, options = {})
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
new file mode 100644
index 00000000..f53314c4
--- /dev/null
+++ b/app/helpers/settings_helper.rb
@@ -0,0 +1,19 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# 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.
+#
+# 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.
+#
+# 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.
+
+module SettingsHelper
+end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index cdf5a3e4..773f2ebe 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -21,12 +21,15 @@ class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
- @@max_size = $RDM_ATTACHMENT_MAX_SIZE || 5*1024*1024
- cattr_reader :max_size
-
validates_presence_of :container, :filename
- validates_inclusion_of :filesize, :in => 1..@@max_size
+ cattr_accessor :storage_path
+ @@storage_path = "#{RAILS_ROOT}/files"
+
+ def validate
+ errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes
+ end
+
def file=(incomming_file)
unless incomming_file.nil?
@temp_file = incomming_file
@@ -63,7 +66,7 @@ class Attachment < ActiveRecord::Base
# Returns file's location on disk
def diskfile
- "#{$RDM_STORAGE_PATH}/#{self.disk_filename}"
+ "#{@@storage_path}/#{self.disk_filename}"
end
def increment_download
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index 968beb49..ba93b5bc 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,13 +16,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Mailer < ActionMailer::Base
-
helper IssuesHelper
def issue_add(issue)
# Sends to all project members
@recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
- @from = $RDM_MAIL_FROM
+ @from = Setting.mail_from
@subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
@body['issue'] = issue
end
@@ -31,7 +30,7 @@ class Mailer < ActionMailer::Base
# Sends to all project members
issue = journal.journalized
@recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
- @from = $RDM_MAIL_FROM
+ @from = Setting.mail_from
@subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
@body['issue'] = issue
@body['journal']= journal
@@ -39,14 +38,14 @@ class Mailer < ActionMailer::Base
def lost_password(token)
@recipients = token.user.mail
- @from = $RDM_MAIL_FROM
+ @from = Setting.mail_from
@subject = l(:mail_subject_lost_password)
@body['token'] = token
end
def register(token)
@recipients = token.user.mail
- @from = $RDM_MAIL_FROM
+ @from = Setting.mail_from
@subject = l(:mail_subject_register)
@body['token'] = token
end
diff --git a/app/models/setting.rb b/app/models/setting.rb
new file mode 100644
index 00000000..7350d912
--- /dev/null
+++ b/app/models/setting.rb
@@ -0,0 +1,61 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# 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.
+#
+# 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.
+#
+# 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
+
+ cattr_accessor :available_settings
+ @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
+
+ validates_uniqueness_of :name
+ validates_inclusion_of :name, :in => @@available_settings.keys
+ validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
+
+ def self.get(name)
+ name = name.to_s
+ setting = find_by_name(name)
+ setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name
+ setting
+ end
+
+ def self.[](name)
+ get(name).value
+ end
+
+ def self.[]=(name, value)
+ setting = get(name)
+ setting.value = value
+ setting.save
+ setting.value
+ end
+
+ @@available_settings.each do |name, params|
+ src = <<-END_SRC
+ def self.#{name}
+ self[:#{name}]
+ end
+
+ def self.#{name}?
+ self[:#{name}].to_s == "1"
+ end
+
+ def self.#{name}=(value)
+ self[:#{name}] = values
+ end
+ END_SRC
+ class_eval src, __FILE__, __LINE__
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index b798860d..8a596168 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -69,7 +69,7 @@ class User < ActiveRecord::Base
if attrs
onthefly = new(*attrs)
onthefly.login = login
- onthefly.language = $RDM_DEFAULT_LANG
+ onthefly.language = Setting.default_language
if onthefly.save
user = find(:first, :conditions => ["login=?", login])
logger.info("User '#{user.login}' created on the fly.") if logger
diff --git a/app/views/account/login.rhtml b/app/views/account/login.rhtml
index 8f092b52..346f7d52 100644
--- a/app/views/account/login.rhtml
+++ b/app/views/account/login.rhtml
@@ -12,7 +12,7 @@