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 @@
+<%= link_to l(:label_settings), :controller => 'settings' %> +
+<%= link_to l(:label_information_plural), :controller => 'admin', :action => 'info' %>
\ No newline at end of file diff --git a/app/views/documents/_form.rhtml b/app/views/documents/_form.rhtml index 873c9632..b075b465 100644 --- a/app/views/documents/_form.rhtml +++ b/app/views/documents/_form.rhtml @@ -14,7 +14,7 @@ -<% unless $RDM_TEXTILE_DISABLED %> +<% if Setting.text_formatting == 'textile' %> <%= javascript_include_tag 'jstoolbar' %>