@@ -1,92 +1,92 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class AdminController < ApplicationController |
|
18 | class AdminController < ApplicationController | |
19 | before_filter :require_admin |
|
19 | before_filter :require_admin | |
20 |
|
20 | |||
21 | helper :sort |
|
21 | helper :sort | |
22 | include SortHelper |
|
22 | include SortHelper | |
23 |
|
23 | |||
24 | def index |
|
24 | def index | |
25 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? |
|
25 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def projects |
|
28 | def projects | |
29 | sort_init 'name', 'asc' |
|
29 | sort_init 'name', 'asc' | |
30 | sort_update |
|
30 | sort_update | |
31 |
|
31 | |||
32 | @status = params[:status] ? params[:status].to_i : 1 |
|
32 | @status = params[:status] ? params[:status].to_i : 1 | |
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
34 |
|
34 | |||
35 | unless params[:name].blank? |
|
35 | unless params[:name].blank? | |
36 | name = "%#{params[:name].strip.downcase}%" |
|
36 | name = "%#{params[:name].strip.downcase}%" | |
37 | c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name] |
|
37 | c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name] | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | @project_count = Project.count(:conditions => c.conditions) |
|
40 | @project_count = Project.count(:conditions => c.conditions) | |
41 | @project_pages = Paginator.new self, @project_count, |
|
41 | @project_pages = Paginator.new self, @project_count, | |
42 | per_page_option, |
|
42 | per_page_option, | |
43 | params['page'] |
|
43 | params['page'] | |
44 | @projects = Project.find :all, :order => sort_clause, |
|
44 | @projects = Project.find :all, :order => sort_clause, | |
45 | :conditions => c.conditions, |
|
45 | :conditions => c.conditions, | |
46 | :limit => @project_pages.items_per_page, |
|
46 | :limit => @project_pages.items_per_page, | |
47 | :offset => @project_pages.current.offset |
|
47 | :offset => @project_pages.current.offset | |
48 |
|
48 | |||
49 | render :action => "projects", :layout => false if request.xhr? |
|
49 | render :action => "projects", :layout => false if request.xhr? | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def plugins |
|
52 | def plugins | |
53 |
@plugins = Redmine::Plugin. |
|
53 | @plugins = Redmine::Plugin.all | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | # Loads the default configuration |
|
56 | # Loads the default configuration | |
57 | # (roles, trackers, statuses, workflow, enumerations) |
|
57 | # (roles, trackers, statuses, workflow, enumerations) | |
58 | def default_configuration |
|
58 | def default_configuration | |
59 | if request.post? |
|
59 | if request.post? | |
60 | begin |
|
60 | begin | |
61 | Redmine::DefaultData::Loader::load(params[:lang]) |
|
61 | Redmine::DefaultData::Loader::load(params[:lang]) | |
62 | flash[:notice] = l(:notice_default_data_loaded) |
|
62 | flash[:notice] = l(:notice_default_data_loaded) | |
63 | rescue Exception => e |
|
63 | rescue Exception => e | |
64 | flash[:error] = l(:error_can_t_load_default_data, e.message) |
|
64 | flash[:error] = l(:error_can_t_load_default_data, e.message) | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 | redirect_to :action => 'index' |
|
67 | redirect_to :action => 'index' | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_email |
|
70 | def test_email | |
71 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors |
|
71 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors | |
72 | # Force ActionMailer to raise delivery errors so we can catch it |
|
72 | # Force ActionMailer to raise delivery errors so we can catch it | |
73 | ActionMailer::Base.raise_delivery_errors = true |
|
73 | ActionMailer::Base.raise_delivery_errors = true | |
74 | begin |
|
74 | begin | |
75 | @test = Mailer.deliver_test(User.current) |
|
75 | @test = Mailer.deliver_test(User.current) | |
76 | flash[:notice] = l(:notice_email_sent, User.current.mail) |
|
76 | flash[:notice] = l(:notice_email_sent, User.current.mail) | |
77 | rescue Exception => e |
|
77 | rescue Exception => e | |
78 | flash[:error] = l(:notice_email_error, e.message) |
|
78 | flash[:error] = l(:notice_email_error, e.message) | |
79 | end |
|
79 | end | |
80 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors |
|
80 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors | |
81 | redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' |
|
81 | redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def info |
|
84 | def info | |
85 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name |
|
85 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name | |
86 | @flags = { |
|
86 | @flags = { | |
87 | :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?, |
|
87 | :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?, | |
88 | :file_repository_writable => File.writable?(Attachment.storage_path), |
|
88 | :file_repository_writable => File.writable?(Attachment.storage_path), | |
89 | :rmagick_available => Object.const_defined?(:Magick) |
|
89 | :rmagick_available => Object.const_defined?(:Magick) | |
90 | } |
|
90 | } | |
91 | end |
|
91 | end | |
92 | end |
|
92 | end |
@@ -1,58 +1,59 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class SettingsController < ApplicationController |
|
18 | class SettingsController < ApplicationController | |
19 | before_filter :require_admin |
|
19 | before_filter :require_admin | |
20 |
|
20 | |||
21 | def index |
|
21 | def index | |
22 | edit |
|
22 | edit | |
23 | render :action => 'edit' |
|
23 | render :action => 'edit' | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def edit |
|
26 | def edit | |
27 | @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted) |
|
27 | @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted) | |
28 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) |
|
28 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) | |
29 | settings = (params[:settings] || {}).dup.symbolize_keys |
|
29 | settings = (params[:settings] || {}).dup.symbolize_keys | |
30 | settings.each do |name, value| |
|
30 | settings.each do |name, value| | |
31 | # remove blank values in array settings |
|
31 | # remove blank values in array settings | |
32 | value.delete_if {|v| v.blank? } if value.is_a?(Array) |
|
32 | value.delete_if {|v| v.blank? } if value.is_a?(Array) | |
33 | Setting[name] = value |
|
33 | Setting[name] = value | |
34 | end |
|
34 | end | |
35 | flash[:notice] = l(:notice_successful_update) |
|
35 | flash[:notice] = l(:notice_successful_update) | |
36 | redirect_to :action => 'edit', :tab => params[:tab] |
|
36 | redirect_to :action => 'edit', :tab => params[:tab] | |
37 | return |
|
37 | return | |
38 | end |
|
38 | end | |
39 | @options = {} |
|
39 | @options = {} | |
40 | @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] } |
|
40 | @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] } | |
41 | @deliveries = ActionMailer::Base.perform_deliveries |
|
41 | @deliveries = ActionMailer::Base.perform_deliveries | |
42 |
|
42 | |||
43 | @guessed_host_and_path = request.host_with_port |
|
43 | @guessed_host_and_path = request.host_with_port | |
44 | @guessed_host_and_path << ('/'+ request.relative_url_root.gsub(%r{^\/}, '')) unless request.relative_url_root.blank? |
|
44 | @guessed_host_and_path << ('/'+ request.relative_url_root.gsub(%r{^\/}, '')) unless request.relative_url_root.blank? | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def plugin |
|
47 | def plugin | |
48 | plugin_id = params[:id].to_sym |
|
48 | @plugin = Redmine::Plugin.find(params[:id]) | |
49 | @plugin = Redmine::Plugin.registered_plugins[plugin_id] |
|
|||
50 | if request.post? |
|
49 | if request.post? | |
51 |
Setting["plugin_#{plugin |
|
50 | Setting["plugin_#{@plugin.id}"] = params[:settings] | |
52 | flash[:notice] = l(:notice_successful_update) |
|
51 | flash[:notice] = l(:notice_successful_update) | |
53 |
redirect_to :action => 'plugin', :id => |
|
52 | redirect_to :action => 'plugin', :id => @plugin.id | |
54 | end |
|
53 | end | |
55 | @partial = @plugin.settings[:partial] |
|
54 | @partial = @plugin.settings[:partial] | |
56 |
@settings = Setting["plugin_#{plugin |
|
55 | @settings = Setting["plugin_#{@plugin.id}"] | |
|
56 | rescue Redmine::PluginNotFound | |||
|
57 | render_404 | |||
57 | end |
|
58 | end | |
58 | end |
|
59 | end |
@@ -1,164 +1,164 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Setting < ActiveRecord::Base |
|
18 | class Setting < ActiveRecord::Base | |
19 |
|
19 | |||
20 | DATE_FORMATS = [ |
|
20 | DATE_FORMATS = [ | |
21 | '%Y-%m-%d', |
|
21 | '%Y-%m-%d', | |
22 | '%d/%m/%Y', |
|
22 | '%d/%m/%Y', | |
23 | '%d.%m.%Y', |
|
23 | '%d.%m.%Y', | |
24 | '%d-%m-%Y', |
|
24 | '%d-%m-%Y', | |
25 | '%m/%d/%Y', |
|
25 | '%m/%d/%Y', | |
26 | '%d %b %Y', |
|
26 | '%d %b %Y', | |
27 | '%d %B %Y', |
|
27 | '%d %B %Y', | |
28 | '%b %d, %Y', |
|
28 | '%b %d, %Y', | |
29 | '%B %d, %Y' |
|
29 | '%B %d, %Y' | |
30 | ] |
|
30 | ] | |
31 |
|
31 | |||
32 | TIME_FORMATS = [ |
|
32 | TIME_FORMATS = [ | |
33 | '%H:%M', |
|
33 | '%H:%M', | |
34 | '%I:%M %p' |
|
34 | '%I:%M %p' | |
35 | ] |
|
35 | ] | |
36 |
|
36 | |||
37 | ENCODINGS = %w(US-ASCII |
|
37 | ENCODINGS = %w(US-ASCII | |
38 | windows-1250 |
|
38 | windows-1250 | |
39 | windows-1251 |
|
39 | windows-1251 | |
40 | windows-1252 |
|
40 | windows-1252 | |
41 | windows-1253 |
|
41 | windows-1253 | |
42 | windows-1254 |
|
42 | windows-1254 | |
43 | windows-1255 |
|
43 | windows-1255 | |
44 | windows-1256 |
|
44 | windows-1256 | |
45 | windows-1257 |
|
45 | windows-1257 | |
46 | windows-1258 |
|
46 | windows-1258 | |
47 | windows-31j |
|
47 | windows-31j | |
48 | ISO-2022-JP |
|
48 | ISO-2022-JP | |
49 | ISO-2022-KR |
|
49 | ISO-2022-KR | |
50 | ISO-8859-1 |
|
50 | ISO-8859-1 | |
51 | ISO-8859-2 |
|
51 | ISO-8859-2 | |
52 | ISO-8859-3 |
|
52 | ISO-8859-3 | |
53 | ISO-8859-4 |
|
53 | ISO-8859-4 | |
54 | ISO-8859-5 |
|
54 | ISO-8859-5 | |
55 | ISO-8859-6 |
|
55 | ISO-8859-6 | |
56 | ISO-8859-7 |
|
56 | ISO-8859-7 | |
57 | ISO-8859-8 |
|
57 | ISO-8859-8 | |
58 | ISO-8859-9 |
|
58 | ISO-8859-9 | |
59 | ISO-8859-13 |
|
59 | ISO-8859-13 | |
60 | ISO-8859-15 |
|
60 | ISO-8859-15 | |
61 | KOI8-R |
|
61 | KOI8-R | |
62 | UTF-8 |
|
62 | UTF-8 | |
63 | UTF-16 |
|
63 | UTF-16 | |
64 | UTF-16BE |
|
64 | UTF-16BE | |
65 | UTF-16LE |
|
65 | UTF-16LE | |
66 | EUC-JP |
|
66 | EUC-JP | |
67 | Shift_JIS |
|
67 | Shift_JIS | |
68 | GB18030 |
|
68 | GB18030 | |
69 | GBK |
|
69 | GBK | |
70 | ISCII91 |
|
70 | ISCII91 | |
71 | EUC-KR |
|
71 | EUC-KR | |
72 | Big5 |
|
72 | Big5 | |
73 | Big5-HKSCS |
|
73 | Big5-HKSCS | |
74 | TIS-620) |
|
74 | TIS-620) | |
75 |
|
75 | |||
76 | cattr_accessor :available_settings |
|
76 | cattr_accessor :available_settings | |
77 | @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml")) |
|
77 | @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml")) | |
78 |
Redmine::Plugin. |
|
78 | Redmine::Plugin.all.each do |plugin| | |
79 | next unless plugin.settings |
|
79 | next unless plugin.settings | |
80 | @@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true} |
|
80 | @@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true} | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | validates_uniqueness_of :name |
|
83 | validates_uniqueness_of :name | |
84 | validates_inclusion_of :name, :in => @@available_settings.keys |
|
84 | validates_inclusion_of :name, :in => @@available_settings.keys | |
85 | validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' } |
|
85 | validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' } | |
86 |
|
86 | |||
87 | # Hash used to cache setting values |
|
87 | # Hash used to cache setting values | |
88 | @cached_settings = {} |
|
88 | @cached_settings = {} | |
89 | @cached_cleared_on = Time.now |
|
89 | @cached_cleared_on = Time.now | |
90 |
|
90 | |||
91 | def value |
|
91 | def value | |
92 | v = read_attribute(:value) |
|
92 | v = read_attribute(:value) | |
93 | # Unserialize serialized settings |
|
93 | # Unserialize serialized settings | |
94 | v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String) |
|
94 | v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String) | |
95 | v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank? |
|
95 | v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank? | |
96 | v |
|
96 | v | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def value=(v) |
|
99 | def value=(v) | |
100 | v = v.to_yaml if v && @@available_settings[name]['serialized'] |
|
100 | v = v.to_yaml if v && @@available_settings[name]['serialized'] | |
101 | write_attribute(:value, v.to_s) |
|
101 | write_attribute(:value, v.to_s) | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | # Returns the value of the setting named name |
|
104 | # Returns the value of the setting named name | |
105 | def self.[](name) |
|
105 | def self.[](name) | |
106 | v = @cached_settings[name] |
|
106 | v = @cached_settings[name] | |
107 | v ? v : (@cached_settings[name] = find_or_default(name).value) |
|
107 | v ? v : (@cached_settings[name] = find_or_default(name).value) | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def self.[]=(name, v) |
|
110 | def self.[]=(name, v) | |
111 | setting = find_or_default(name) |
|
111 | setting = find_or_default(name) | |
112 | setting.value = (v ? v : "") |
|
112 | setting.value = (v ? v : "") | |
113 | @cached_settings[name] = nil |
|
113 | @cached_settings[name] = nil | |
114 | setting.save |
|
114 | setting.save | |
115 | setting.value |
|
115 | setting.value | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | # Defines getter and setter for each setting |
|
118 | # Defines getter and setter for each setting | |
119 | # Then setting values can be read using: Setting.some_setting_name |
|
119 | # Then setting values can be read using: Setting.some_setting_name | |
120 | # or set using Setting.some_setting_name = "some value" |
|
120 | # or set using Setting.some_setting_name = "some value" | |
121 | @@available_settings.each do |name, params| |
|
121 | @@available_settings.each do |name, params| | |
122 | src = <<-END_SRC |
|
122 | src = <<-END_SRC | |
123 | def self.#{name} |
|
123 | def self.#{name} | |
124 | self[:#{name}] |
|
124 | self[:#{name}] | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def self.#{name}? |
|
127 | def self.#{name}? | |
128 | self[:#{name}].to_i > 0 |
|
128 | self[:#{name}].to_i > 0 | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def self.#{name}=(value) |
|
131 | def self.#{name}=(value) | |
132 | self[:#{name}] = value |
|
132 | self[:#{name}] = value | |
133 | end |
|
133 | end | |
134 | END_SRC |
|
134 | END_SRC | |
135 | class_eval src, __FILE__, __LINE__ |
|
135 | class_eval src, __FILE__, __LINE__ | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | # Helper that returns an array based on per_page_options setting |
|
138 | # Helper that returns an array based on per_page_options setting | |
139 | def self.per_page_options_array |
|
139 | def self.per_page_options_array | |
140 | per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort |
|
140 | per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | # Checks if settings have changed since the values were read |
|
143 | # Checks if settings have changed since the values were read | |
144 | # and clears the cache hash if it's the case |
|
144 | # and clears the cache hash if it's the case | |
145 | # Called once per request |
|
145 | # Called once per request | |
146 | def self.check_cache |
|
146 | def self.check_cache | |
147 | settings_updated_on = Setting.maximum(:updated_on) |
|
147 | settings_updated_on = Setting.maximum(:updated_on) | |
148 | if settings_updated_on && @cached_cleared_on <= settings_updated_on |
|
148 | if settings_updated_on && @cached_cleared_on <= settings_updated_on | |
149 | @cached_settings.clear |
|
149 | @cached_settings.clear | |
150 | @cached_cleared_on = Time.now |
|
150 | @cached_cleared_on = Time.now | |
151 | logger.info "Settings cache cleared." if logger |
|
151 | logger.info "Settings cache cleared." if logger | |
152 | end |
|
152 | end | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | private |
|
155 | private | |
156 | # Returns the Setting instance for the setting named name |
|
156 | # Returns the Setting instance for the setting named name | |
157 | # (record found in database or new record with default value) |
|
157 | # (record found in database or new record with default value) | |
158 | def self.find_or_default(name) |
|
158 | def self.find_or_default(name) | |
159 | name = name.to_s |
|
159 | name = name.to_s | |
160 | raise "There's no setting named #{name}" unless @@available_settings.has_key?(name) |
|
160 | raise "There's no setting named #{name}" unless @@available_settings.has_key?(name) | |
161 | setting = find_by_name(name) |
|
161 | setting = find_by_name(name) | |
162 | setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name |
|
162 | setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name | |
163 | end |
|
163 | end | |
164 | end |
|
164 | end |
@@ -1,176 +1,188 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine #:nodoc: |
|
18 | module Redmine #:nodoc: | |
19 |
|
19 | |||
|
20 | class PluginNotFound < StandardError; end | |||
|
21 | ||||
20 | # Base class for Redmine plugins. |
|
22 | # Base class for Redmine plugins. | |
21 | # Plugins are registered using the <tt>register</tt> class method that acts as the public constructor. |
|
23 | # Plugins are registered using the <tt>register</tt> class method that acts as the public constructor. | |
22 | # |
|
24 | # | |
23 | # Redmine::Plugin.register :example do |
|
25 | # Redmine::Plugin.register :example do | |
24 | # name 'Example plugin' |
|
26 | # name 'Example plugin' | |
25 | # author 'John Smith' |
|
27 | # author 'John Smith' | |
26 | # description 'This is an example plugin for Redmine' |
|
28 | # description 'This is an example plugin for Redmine' | |
27 | # version '0.0.1' |
|
29 | # version '0.0.1' | |
28 | # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings' |
|
30 | # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings' | |
29 | # end |
|
31 | # end | |
30 | # |
|
32 | # | |
31 | # === Plugin attributes |
|
33 | # === Plugin attributes | |
32 | # |
|
34 | # | |
33 | # +settings+ is an optional attribute that let the plugin be configurable. |
|
35 | # +settings+ is an optional attribute that let the plugin be configurable. | |
34 | # It must be a hash with the following keys: |
|
36 | # It must be a hash with the following keys: | |
35 | # * <tt>:default</tt>: default value for the plugin settings |
|
37 | # * <tt>:default</tt>: default value for the plugin settings | |
36 | # * <tt>:partial</tt>: path of the configuration partial view, relative to the plugin <tt>app/views</tt> directory |
|
38 | # * <tt>:partial</tt>: path of the configuration partial view, relative to the plugin <tt>app/views</tt> directory | |
37 | # Example: |
|
39 | # Example: | |
38 | # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings' |
|
40 | # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings' | |
39 | # In this example, the settings partial will be found here in the plugin directory: <tt>app/views/settings/_settings.rhtml</tt>. |
|
41 | # In this example, the settings partial will be found here in the plugin directory: <tt>app/views/settings/_settings.rhtml</tt>. | |
40 | # |
|
42 | # | |
41 | # When rendered, the plugin settings value is available as the local variable +settings+ |
|
43 | # When rendered, the plugin settings value is available as the local variable +settings+ | |
42 | class Plugin |
|
44 | class Plugin | |
43 | @registered_plugins = {} |
|
45 | @registered_plugins = {} | |
44 | class << self |
|
46 | class << self | |
45 | attr_reader :registered_plugins |
|
47 | attr_reader :registered_plugins | |
46 | private :new |
|
48 | private :new | |
47 |
|
49 | |||
48 | def def_field(*names) |
|
50 | def def_field(*names) | |
49 | class_eval do |
|
51 | class_eval do | |
50 | names.each do |name| |
|
52 | names.each do |name| | |
51 | define_method(name) do |*args| |
|
53 | define_method(name) do |*args| | |
52 | args.empty? ? instance_variable_get("@#{name}") : instance_variable_set("@#{name}", *args) |
|
54 | args.empty? ? instance_variable_get("@#{name}") : instance_variable_set("@#{name}", *args) | |
53 | end |
|
55 | end | |
54 | end |
|
56 | end | |
55 | end |
|
57 | end | |
56 | end |
|
58 | end | |
57 | end |
|
59 | end | |
58 | def_field :name, :description, :author, :version, :settings |
|
60 | def_field :name, :description, :author, :version, :settings | |
59 | attr_reader :id |
|
61 | attr_reader :id | |
60 |
|
62 | |||
61 | # Plugin constructor |
|
63 | # Plugin constructor | |
62 | def self.register(id, &block) |
|
64 | def self.register(id, &block) | |
63 | p = new(id) |
|
65 | p = new(id) | |
64 | p.instance_eval(&block) |
|
66 | p.instance_eval(&block) | |
65 |
|
|
67 | registered_plugins[id] = p | |
|
68 | end | |||
|
69 | ||||
|
70 | # Returns an array off all registered plugins | |||
|
71 | def self.all | |||
|
72 | registered_plugins.values.sort | |||
|
73 | end | |||
|
74 | ||||
|
75 | # Finds a plugin by its id | |||
|
76 | def self.find(id) | |||
|
77 | registered_plugins[id.to_sym] || raise(PluginNotFound) | |||
66 | end |
|
78 | end | |
67 |
|
79 | |||
68 | def initialize(id) |
|
80 | def initialize(id) | |
69 | @id = id.to_sym |
|
81 | @id = id.to_sym | |
70 | end |
|
82 | end | |
71 |
|
83 | |||
72 | def <=>(plugin) |
|
84 | def <=>(plugin) | |
73 | self.id.to_s <=> plugin.id.to_s |
|
85 | self.id.to_s <=> plugin.id.to_s | |
74 | end |
|
86 | end | |
75 |
|
87 | |||
76 | # Adds an item to the given +menu+. |
|
88 | # Adds an item to the given +menu+. | |
77 | # The +id+ parameter (equals to the project id) is automatically added to the url. |
|
89 | # The +id+ parameter (equals to the project id) is automatically added to the url. | |
78 | # menu :project_menu, :plugin_example, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample' |
|
90 | # menu :project_menu, :plugin_example, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample' | |
79 | # |
|
91 | # | |
80 | # +name+ parameter can be: :top_menu, :account_menu, :application_menu or :project_menu |
|
92 | # +name+ parameter can be: :top_menu, :account_menu, :application_menu or :project_menu | |
81 | # |
|
93 | # | |
82 | def menu(menu, item, url, options={}) |
|
94 | def menu(menu, item, url, options={}) | |
83 | Redmine::MenuManager.map(menu).push(item, url, options) |
|
95 | Redmine::MenuManager.map(menu).push(item, url, options) | |
84 | end |
|
96 | end | |
85 | alias :add_menu_item :menu |
|
97 | alias :add_menu_item :menu | |
86 |
|
98 | |||
87 | # Removes +item+ from the given +menu+. |
|
99 | # Removes +item+ from the given +menu+. | |
88 | def delete_menu_item(menu, item) |
|
100 | def delete_menu_item(menu, item) | |
89 | Redmine::MenuManager.map(menu).delete(item) |
|
101 | Redmine::MenuManager.map(menu).delete(item) | |
90 | end |
|
102 | end | |
91 |
|
103 | |||
92 | # Defines a permission called +name+ for the given +actions+. |
|
104 | # Defines a permission called +name+ for the given +actions+. | |
93 | # |
|
105 | # | |
94 | # The +actions+ argument is a hash with controllers as keys and actions as values (a single value or an array): |
|
106 | # The +actions+ argument is a hash with controllers as keys and actions as values (a single value or an array): | |
95 | # permission :destroy_contacts, { :contacts => :destroy } |
|
107 | # permission :destroy_contacts, { :contacts => :destroy } | |
96 | # permission :view_contacts, { :contacts => [:index, :show] } |
|
108 | # permission :view_contacts, { :contacts => [:index, :show] } | |
97 | # |
|
109 | # | |
98 | # The +options+ argument can be used to make the permission public (implicitly given to any user) |
|
110 | # The +options+ argument can be used to make the permission public (implicitly given to any user) | |
99 | # or to restrict users the permission can be given to. |
|
111 | # or to restrict users the permission can be given to. | |
100 | # |
|
112 | # | |
101 | # Examples |
|
113 | # Examples | |
102 | # # A permission that is implicitly given to any user |
|
114 | # # A permission that is implicitly given to any user | |
103 | # # This permission won't appear on the Roles & Permissions setup screen |
|
115 | # # This permission won't appear on the Roles & Permissions setup screen | |
104 | # permission :say_hello, { :example => :say_hello }, :public => true |
|
116 | # permission :say_hello, { :example => :say_hello }, :public => true | |
105 | # |
|
117 | # | |
106 | # # A permission that can be given to any user |
|
118 | # # A permission that can be given to any user | |
107 | # permission :say_hello, { :example => :say_hello } |
|
119 | # permission :say_hello, { :example => :say_hello } | |
108 | # |
|
120 | # | |
109 | # # A permission that can be given to registered users only |
|
121 | # # A permission that can be given to registered users only | |
110 | # permission :say_hello, { :example => :say_hello }, :require => loggedin |
|
122 | # permission :say_hello, { :example => :say_hello }, :require => loggedin | |
111 | # |
|
123 | # | |
112 | # # A permission that can be given to project members only |
|
124 | # # A permission that can be given to project members only | |
113 | # permission :say_hello, { :example => :say_hello }, :require => member |
|
125 | # permission :say_hello, { :example => :say_hello }, :require => member | |
114 | def permission(name, actions, options = {}) |
|
126 | def permission(name, actions, options = {}) | |
115 | if @project_module |
|
127 | if @project_module | |
116 | Redmine::AccessControl.map {|map| map.project_module(@project_module) {|map|map.permission(name, actions, options)}} |
|
128 | Redmine::AccessControl.map {|map| map.project_module(@project_module) {|map|map.permission(name, actions, options)}} | |
117 | else |
|
129 | else | |
118 | Redmine::AccessControl.map {|map| map.permission(name, actions, options)} |
|
130 | Redmine::AccessControl.map {|map| map.permission(name, actions, options)} | |
119 | end |
|
131 | end | |
120 | end |
|
132 | end | |
121 |
|
133 | |||
122 | # Defines a project module, that can be enabled/disabled for each project. |
|
134 | # Defines a project module, that can be enabled/disabled for each project. | |
123 | # Permissions defined inside +block+ will be bind to the module. |
|
135 | # Permissions defined inside +block+ will be bind to the module. | |
124 | # |
|
136 | # | |
125 | # project_module :things do |
|
137 | # project_module :things do | |
126 | # permission :view_contacts, { :contacts => [:list, :show] }, :public => true |
|
138 | # permission :view_contacts, { :contacts => [:list, :show] }, :public => true | |
127 | # permission :destroy_contacts, { :contacts => :destroy } |
|
139 | # permission :destroy_contacts, { :contacts => :destroy } | |
128 | # end |
|
140 | # end | |
129 | def project_module(name, &block) |
|
141 | def project_module(name, &block) | |
130 | @project_module = name |
|
142 | @project_module = name | |
131 | self.instance_eval(&block) |
|
143 | self.instance_eval(&block) | |
132 | @project_module = nil |
|
144 | @project_module = nil | |
133 | end |
|
145 | end | |
134 |
|
146 | |||
135 | # Registers an activity provider. |
|
147 | # Registers an activity provider. | |
136 | # |
|
148 | # | |
137 | # Options: |
|
149 | # Options: | |
138 | # * <tt>:class_name</tt> - one or more model(s) that provide these events (inferred from event_type by default) |
|
150 | # * <tt>:class_name</tt> - one or more model(s) that provide these events (inferred from event_type by default) | |
139 | # * <tt>:default</tt> - setting this option to false will make the events not displayed by default |
|
151 | # * <tt>:default</tt> - setting this option to false will make the events not displayed by default | |
140 | # |
|
152 | # | |
141 | # A model can provide several activity event types. |
|
153 | # A model can provide several activity event types. | |
142 | # |
|
154 | # | |
143 | # Examples: |
|
155 | # Examples: | |
144 | # register :news |
|
156 | # register :news | |
145 | # register :scrums, :class_name => 'Meeting' |
|
157 | # register :scrums, :class_name => 'Meeting' | |
146 | # register :issues, :class_name => ['Issue', 'Journal'] |
|
158 | # register :issues, :class_name => ['Issue', 'Journal'] | |
147 | # |
|
159 | # | |
148 | # Retrieving events: |
|
160 | # Retrieving events: | |
149 | # Associated model(s) must implement the find_events class method. |
|
161 | # Associated model(s) must implement the find_events class method. | |
150 | # ActiveRecord models can use acts_as_activity_provider as a way to implement this class method. |
|
162 | # ActiveRecord models can use acts_as_activity_provider as a way to implement this class method. | |
151 | # |
|
163 | # | |
152 | # The following call should return all the scrum events visible by current user that occured in the 5 last days: |
|
164 | # The following call should return all the scrum events visible by current user that occured in the 5 last days: | |
153 | # Meeting.find_events('scrums', User.current, 5.days.ago, Date.today) |
|
165 | # Meeting.find_events('scrums', User.current, 5.days.ago, Date.today) | |
154 | # Meeting.find_events('scrums', User.current, 5.days.ago, Date.today, :project => foo) # events for project foo only |
|
166 | # Meeting.find_events('scrums', User.current, 5.days.ago, Date.today, :project => foo) # events for project foo only | |
155 | # |
|
167 | # | |
156 | # Note that :view_scrums permission is required to view these events in the activity view. |
|
168 | # Note that :view_scrums permission is required to view these events in the activity view. | |
157 | def activity_provider(*args) |
|
169 | def activity_provider(*args) | |
158 | Redmine::Activity.register(*args) |
|
170 | Redmine::Activity.register(*args) | |
159 | end |
|
171 | end | |
160 |
|
172 | |||
161 | # Registers a wiki formatter. |
|
173 | # Registers a wiki formatter. | |
162 | # |
|
174 | # | |
163 | # Parameters: |
|
175 | # Parameters: | |
164 | # * +name+ - human-readable name |
|
176 | # * +name+ - human-readable name | |
165 | # * +formatter+ - formatter class, which should have an instance method +to_html+ |
|
177 | # * +formatter+ - formatter class, which should have an instance method +to_html+ | |
166 | # * +helper+ - helper module, which will be included by wiki pages |
|
178 | # * +helper+ - helper module, which will be included by wiki pages | |
167 | def wiki_format_provider(name, formatter, helper) |
|
179 | def wiki_format_provider(name, formatter, helper) | |
168 | Redmine::WikiFormatting.register(name, formatter, helper) |
|
180 | Redmine::WikiFormatting.register(name, formatter, helper) | |
169 | end |
|
181 | end | |
170 |
|
182 | |||
171 | # Returns +true+ if the plugin can be configured. |
|
183 | # Returns +true+ if the plugin can be configured. | |
172 | def configurable? |
|
184 | def configurable? | |
173 | settings && settings.is_a?(Hash) && !settings[:partial].blank? |
|
185 | settings && settings.is_a?(Hash) && !settings[:partial].blank? | |
174 | end |
|
186 | end | |
175 | end |
|
187 | end | |
176 | end |
|
188 | end |
General Comments 0
You need to be logged in to leave comments.
Login now