@@ -0,0 +1,23 | |||||
|
1 | module Redmine | |||
|
2 | module Scm | |||
|
3 | class Base | |||
|
4 | class << self | |||
|
5 | ||||
|
6 | def all | |||
|
7 | @scms | |||
|
8 | end | |||
|
9 | ||||
|
10 | # Add a new SCM adapter and repository | |||
|
11 | def add(scm_name) | |||
|
12 | @scms ||= [] | |||
|
13 | @scms << scm_name | |||
|
14 | end | |||
|
15 | ||||
|
16 | # Remove a SCM adapter from Redmine's list of supported scms | |||
|
17 | def delete(scm_name) | |||
|
18 | @scms.delete(scm_name) | |||
|
19 | end | |||
|
20 | end | |||
|
21 | end | |||
|
22 | end | |||
|
23 | end |
@@ -1,325 +1,325 | |||||
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 | require 'uri' |
|
18 | require 'uri' | |
19 | require 'cgi' |
|
19 | require 'cgi' | |
20 |
|
20 | |||
21 | class ApplicationController < ActionController::Base |
|
21 | class ApplicationController < ActionController::Base | |
22 | include Redmine::I18n |
|
22 | include Redmine::I18n | |
23 |
|
23 | |||
24 | layout 'base' |
|
24 | layout 'base' | |
25 | exempt_from_layout 'builder' |
|
25 | exempt_from_layout 'builder' | |
26 |
|
26 | |||
27 | # Remove broken cookie after upgrade from 0.8.x (#4292) |
|
27 | # Remove broken cookie after upgrade from 0.8.x (#4292) | |
28 | # See https://rails.lighthouseapp.com/projects/8994/tickets/3360 |
|
28 | # See https://rails.lighthouseapp.com/projects/8994/tickets/3360 | |
29 | # TODO: remove it when Rails is fixed |
|
29 | # TODO: remove it when Rails is fixed | |
30 | before_filter :delete_broken_cookies |
|
30 | before_filter :delete_broken_cookies | |
31 | def delete_broken_cookies |
|
31 | def delete_broken_cookies | |
32 | if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/ |
|
32 | if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/ | |
33 | cookies.delete '_redmine_session' |
|
33 | cookies.delete '_redmine_session' | |
34 | redirect_to home_path |
|
34 | redirect_to home_path | |
35 | return false |
|
35 | return false | |
36 | end |
|
36 | end | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | before_filter :user_setup, :check_if_login_required, :set_localization |
|
39 | before_filter :user_setup, :check_if_login_required, :set_localization | |
40 | filter_parameter_logging :password |
|
40 | filter_parameter_logging :password | |
41 | protect_from_forgery |
|
41 | protect_from_forgery | |
42 |
|
42 | |||
43 | rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token |
|
43 | rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token | |
44 |
|
44 | |||
45 | include Redmine::Search::Controller |
|
45 | include Redmine::Search::Controller | |
46 | include Redmine::MenuManager::MenuController |
|
46 | include Redmine::MenuManager::MenuController | |
47 | helper Redmine::MenuManager::MenuHelper |
|
47 | helper Redmine::MenuManager::MenuHelper | |
48 |
|
48 | |||
49 | REDMINE_SUPPORTED_SCM.each do |scm| |
|
49 | Redmine::Scm::Base.all.each do |scm| | |
50 | require_dependency "repository/#{scm.underscore}" |
|
50 | require_dependency "repository/#{scm.underscore}" | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def user_setup |
|
53 | def user_setup | |
54 | # Check the settings cache for each request |
|
54 | # Check the settings cache for each request | |
55 | Setting.check_cache |
|
55 | Setting.check_cache | |
56 | # Find the current user |
|
56 | # Find the current user | |
57 | User.current = find_current_user |
|
57 | User.current = find_current_user | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | # Returns the current user or nil if no user is logged in |
|
60 | # Returns the current user or nil if no user is logged in | |
61 | # and starts a session if needed |
|
61 | # and starts a session if needed | |
62 | def find_current_user |
|
62 | def find_current_user | |
63 | if session[:user_id] |
|
63 | if session[:user_id] | |
64 | # existing session |
|
64 | # existing session | |
65 | (User.active.find(session[:user_id]) rescue nil) |
|
65 | (User.active.find(session[:user_id]) rescue nil) | |
66 | elsif cookies[:autologin] && Setting.autologin? |
|
66 | elsif cookies[:autologin] && Setting.autologin? | |
67 | # auto-login feature starts a new session |
|
67 | # auto-login feature starts a new session | |
68 | user = User.try_to_autologin(cookies[:autologin]) |
|
68 | user = User.try_to_autologin(cookies[:autologin]) | |
69 | session[:user_id] = user.id if user |
|
69 | session[:user_id] = user.id if user | |
70 | user |
|
70 | user | |
71 | elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action]) |
|
71 | elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action]) | |
72 | # RSS key authentication does not start a session |
|
72 | # RSS key authentication does not start a session | |
73 | User.find_by_rss_key(params[:key]) |
|
73 | User.find_by_rss_key(params[:key]) | |
74 | elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format]) |
|
74 | elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format]) | |
75 | if params[:key].present? && accept_key_auth_actions.include?(params[:action]) |
|
75 | if params[:key].present? && accept_key_auth_actions.include?(params[:action]) | |
76 | # Use API key |
|
76 | # Use API key | |
77 | User.find_by_api_key(params[:key]) |
|
77 | User.find_by_api_key(params[:key]) | |
78 | else |
|
78 | else | |
79 | # HTTP Basic, either username/password or API key/random |
|
79 | # HTTP Basic, either username/password or API key/random | |
80 | authenticate_with_http_basic do |username, password| |
|
80 | authenticate_with_http_basic do |username, password| | |
81 | User.try_to_login(username, password) || User.find_by_api_key(username) |
|
81 | User.try_to_login(username, password) || User.find_by_api_key(username) | |
82 | end |
|
82 | end | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | # Sets the logged in user |
|
87 | # Sets the logged in user | |
88 | def logged_user=(user) |
|
88 | def logged_user=(user) | |
89 | reset_session |
|
89 | reset_session | |
90 | if user && user.is_a?(User) |
|
90 | if user && user.is_a?(User) | |
91 | User.current = user |
|
91 | User.current = user | |
92 | session[:user_id] = user.id |
|
92 | session[:user_id] = user.id | |
93 | else |
|
93 | else | |
94 | User.current = User.anonymous |
|
94 | User.current = User.anonymous | |
95 | end |
|
95 | end | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | # check if login is globally required to access the application |
|
98 | # check if login is globally required to access the application | |
99 | def check_if_login_required |
|
99 | def check_if_login_required | |
100 | # no check needed if user is already logged in |
|
100 | # no check needed if user is already logged in | |
101 | return true if User.current.logged? |
|
101 | return true if User.current.logged? | |
102 | require_login if Setting.login_required? |
|
102 | require_login if Setting.login_required? | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def set_localization |
|
105 | def set_localization | |
106 | lang = nil |
|
106 | lang = nil | |
107 | if User.current.logged? |
|
107 | if User.current.logged? | |
108 | lang = find_language(User.current.language) |
|
108 | lang = find_language(User.current.language) | |
109 | end |
|
109 | end | |
110 | if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE'] |
|
110 | if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE'] | |
111 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase |
|
111 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase | |
112 | if !accept_lang.blank? |
|
112 | if !accept_lang.blank? | |
113 | lang = find_language(accept_lang) || find_language(accept_lang.split('-').first) |
|
113 | lang = find_language(accept_lang) || find_language(accept_lang.split('-').first) | |
114 | end |
|
114 | end | |
115 | end |
|
115 | end | |
116 | lang ||= Setting.default_language |
|
116 | lang ||= Setting.default_language | |
117 | set_language_if_valid(lang) |
|
117 | set_language_if_valid(lang) | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | def require_login |
|
120 | def require_login | |
121 | if !User.current.logged? |
|
121 | if !User.current.logged? | |
122 | # Extract only the basic url parameters on non-GET requests |
|
122 | # Extract only the basic url parameters on non-GET requests | |
123 | if request.get? |
|
123 | if request.get? | |
124 | url = url_for(params) |
|
124 | url = url_for(params) | |
125 | else |
|
125 | else | |
126 | url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id]) |
|
126 | url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id]) | |
127 | end |
|
127 | end | |
128 | respond_to do |format| |
|
128 | respond_to do |format| | |
129 | format.html { redirect_to :controller => "account", :action => "login", :back_url => url } |
|
129 | format.html { redirect_to :controller => "account", :action => "login", :back_url => url } | |
130 | format.atom { redirect_to :controller => "account", :action => "login", :back_url => url } |
|
130 | format.atom { redirect_to :controller => "account", :action => "login", :back_url => url } | |
131 | format.xml { head :unauthorized } |
|
131 | format.xml { head :unauthorized } | |
132 | format.json { head :unauthorized } |
|
132 | format.json { head :unauthorized } | |
133 | end |
|
133 | end | |
134 | return false |
|
134 | return false | |
135 | end |
|
135 | end | |
136 | true |
|
136 | true | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | def require_admin |
|
139 | def require_admin | |
140 | return unless require_login |
|
140 | return unless require_login | |
141 | if !User.current.admin? |
|
141 | if !User.current.admin? | |
142 | render_403 |
|
142 | render_403 | |
143 | return false |
|
143 | return false | |
144 | end |
|
144 | end | |
145 | true |
|
145 | true | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def deny_access |
|
148 | def deny_access | |
149 | User.current.logged? ? render_403 : require_login |
|
149 | User.current.logged? ? render_403 : require_login | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | # Authorize the user for the requested action |
|
152 | # Authorize the user for the requested action | |
153 | def authorize(ctrl = params[:controller], action = params[:action], global = false) |
|
153 | def authorize(ctrl = params[:controller], action = params[:action], global = false) | |
154 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global) |
|
154 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global) | |
155 | allowed ? true : deny_access |
|
155 | allowed ? true : deny_access | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | # Authorize the user for the requested action outside a project |
|
158 | # Authorize the user for the requested action outside a project | |
159 | def authorize_global(ctrl = params[:controller], action = params[:action], global = true) |
|
159 | def authorize_global(ctrl = params[:controller], action = params[:action], global = true) | |
160 | authorize(ctrl, action, global) |
|
160 | authorize(ctrl, action, global) | |
161 | end |
|
161 | end | |
162 |
|
162 | |||
163 | # Find project of id params[:id] |
|
163 | # Find project of id params[:id] | |
164 | def find_project |
|
164 | def find_project | |
165 | @project = Project.find(params[:id]) |
|
165 | @project = Project.find(params[:id]) | |
166 | rescue ActiveRecord::RecordNotFound |
|
166 | rescue ActiveRecord::RecordNotFound | |
167 | render_404 |
|
167 | render_404 | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | # make sure that the user is a member of the project (or admin) if project is private |
|
170 | # make sure that the user is a member of the project (or admin) if project is private | |
171 | # used as a before_filter for actions that do not require any particular permission on the project |
|
171 | # used as a before_filter for actions that do not require any particular permission on the project | |
172 | def check_project_privacy |
|
172 | def check_project_privacy | |
173 | if @project && @project.active? |
|
173 | if @project && @project.active? | |
174 | if @project.is_public? || User.current.member_of?(@project) || User.current.admin? |
|
174 | if @project.is_public? || User.current.member_of?(@project) || User.current.admin? | |
175 | true |
|
175 | true | |
176 | else |
|
176 | else | |
177 | User.current.logged? ? render_403 : require_login |
|
177 | User.current.logged? ? render_403 : require_login | |
178 | end |
|
178 | end | |
179 | else |
|
179 | else | |
180 | @project = nil |
|
180 | @project = nil | |
181 | render_404 |
|
181 | render_404 | |
182 | false |
|
182 | false | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | def redirect_back_or_default(default) |
|
186 | def redirect_back_or_default(default) | |
187 | back_url = CGI.unescape(params[:back_url].to_s) |
|
187 | back_url = CGI.unescape(params[:back_url].to_s) | |
188 | if !back_url.blank? |
|
188 | if !back_url.blank? | |
189 | begin |
|
189 | begin | |
190 | uri = URI.parse(back_url) |
|
190 | uri = URI.parse(back_url) | |
191 | # do not redirect user to another host or to the login or register page |
|
191 | # do not redirect user to another host or to the login or register page | |
192 | if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) |
|
192 | if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) | |
193 | redirect_to(back_url) |
|
193 | redirect_to(back_url) | |
194 | return |
|
194 | return | |
195 | end |
|
195 | end | |
196 | rescue URI::InvalidURIError |
|
196 | rescue URI::InvalidURIError | |
197 | # redirect to default |
|
197 | # redirect to default | |
198 | end |
|
198 | end | |
199 | end |
|
199 | end | |
200 | redirect_to default |
|
200 | redirect_to default | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def render_403 |
|
203 | def render_403 | |
204 | @project = nil |
|
204 | @project = nil | |
205 | respond_to do |format| |
|
205 | respond_to do |format| | |
206 | format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 } |
|
206 | format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 } | |
207 | format.atom { head 403 } |
|
207 | format.atom { head 403 } | |
208 | format.xml { head 403 } |
|
208 | format.xml { head 403 } | |
209 | format.json { head 403 } |
|
209 | format.json { head 403 } | |
210 | end |
|
210 | end | |
211 | return false |
|
211 | return false | |
212 | end |
|
212 | end | |
213 |
|
213 | |||
214 | def render_404 |
|
214 | def render_404 | |
215 | respond_to do |format| |
|
215 | respond_to do |format| | |
216 | format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 } |
|
216 | format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 } | |
217 | format.atom { head 404 } |
|
217 | format.atom { head 404 } | |
218 | format.xml { head 404 } |
|
218 | format.xml { head 404 } | |
219 | format.json { head 404 } |
|
219 | format.json { head 404 } | |
220 | end |
|
220 | end | |
221 | return false |
|
221 | return false | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def render_error(msg) |
|
224 | def render_error(msg) | |
225 | respond_to do |format| |
|
225 | respond_to do |format| | |
226 | format.html { |
|
226 | format.html { | |
227 | flash.now[:error] = msg |
|
227 | flash.now[:error] = msg | |
228 | render :text => '', :layout => !request.xhr?, :status => 500 |
|
228 | render :text => '', :layout => !request.xhr?, :status => 500 | |
229 | } |
|
229 | } | |
230 | format.atom { head 500 } |
|
230 | format.atom { head 500 } | |
231 | format.xml { head 500 } |
|
231 | format.xml { head 500 } | |
232 | format.json { head 500 } |
|
232 | format.json { head 500 } | |
233 | end |
|
233 | end | |
234 | end |
|
234 | end | |
235 |
|
235 | |||
236 | def invalid_authenticity_token |
|
236 | def invalid_authenticity_token | |
237 | if api_request? |
|
237 | if api_request? | |
238 | logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." |
|
238 | logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." | |
239 | end |
|
239 | end | |
240 | render_error "Invalid form authenticity token." |
|
240 | render_error "Invalid form authenticity token." | |
241 | end |
|
241 | end | |
242 |
|
242 | |||
243 | def render_feed(items, options={}) |
|
243 | def render_feed(items, options={}) | |
244 | @items = items || [] |
|
244 | @items = items || [] | |
245 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } |
|
245 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } | |
246 | @items = @items.slice(0, Setting.feeds_limit.to_i) |
|
246 | @items = @items.slice(0, Setting.feeds_limit.to_i) | |
247 | @title = options[:title] || Setting.app_title |
|
247 | @title = options[:title] || Setting.app_title | |
248 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' |
|
248 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' | |
249 | end |
|
249 | end | |
250 |
|
250 | |||
251 | def self.accept_key_auth(*actions) |
|
251 | def self.accept_key_auth(*actions) | |
252 | actions = actions.flatten.map(&:to_s) |
|
252 | actions = actions.flatten.map(&:to_s) | |
253 | write_inheritable_attribute('accept_key_auth_actions', actions) |
|
253 | write_inheritable_attribute('accept_key_auth_actions', actions) | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | def accept_key_auth_actions |
|
256 | def accept_key_auth_actions | |
257 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] |
|
257 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | # TODO: move to model |
|
260 | # TODO: move to model | |
261 | def attach_files(obj, attachments) |
|
261 | def attach_files(obj, attachments) | |
262 | attached = [] |
|
262 | attached = [] | |
263 | unsaved = [] |
|
263 | unsaved = [] | |
264 | if attachments && attachments.is_a?(Hash) |
|
264 | if attachments && attachments.is_a?(Hash) | |
265 | attachments.each_value do |attachment| |
|
265 | attachments.each_value do |attachment| | |
266 | file = attachment['file'] |
|
266 | file = attachment['file'] | |
267 | next unless file && file.size > 0 |
|
267 | next unless file && file.size > 0 | |
268 | a = Attachment.create(:container => obj, |
|
268 | a = Attachment.create(:container => obj, | |
269 | :file => file, |
|
269 | :file => file, | |
270 | :description => attachment['description'].to_s.strip, |
|
270 | :description => attachment['description'].to_s.strip, | |
271 | :author => User.current) |
|
271 | :author => User.current) | |
272 | a.new_record? ? (unsaved << a) : (attached << a) |
|
272 | a.new_record? ? (unsaved << a) : (attached << a) | |
273 | end |
|
273 | end | |
274 | if unsaved.any? |
|
274 | if unsaved.any? | |
275 | flash[:warning] = l(:warning_attachments_not_saved, unsaved.size) |
|
275 | flash[:warning] = l(:warning_attachments_not_saved, unsaved.size) | |
276 | end |
|
276 | end | |
277 | end |
|
277 | end | |
278 | attached |
|
278 | attached | |
279 | end |
|
279 | end | |
280 |
|
280 | |||
281 | # Returns the number of objects that should be displayed |
|
281 | # Returns the number of objects that should be displayed | |
282 | # on the paginated list |
|
282 | # on the paginated list | |
283 | def per_page_option |
|
283 | def per_page_option | |
284 | per_page = nil |
|
284 | per_page = nil | |
285 | if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i) |
|
285 | if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i) | |
286 | per_page = params[:per_page].to_s.to_i |
|
286 | per_page = params[:per_page].to_s.to_i | |
287 | session[:per_page] = per_page |
|
287 | session[:per_page] = per_page | |
288 | elsif session[:per_page] |
|
288 | elsif session[:per_page] | |
289 | per_page = session[:per_page] |
|
289 | per_page = session[:per_page] | |
290 | else |
|
290 | else | |
291 | per_page = Setting.per_page_options_array.first || 25 |
|
291 | per_page = Setting.per_page_options_array.first || 25 | |
292 | end |
|
292 | end | |
293 | per_page |
|
293 | per_page | |
294 | end |
|
294 | end | |
295 |
|
295 | |||
296 | # qvalues http header parser |
|
296 | # qvalues http header parser | |
297 | # code taken from webrick |
|
297 | # code taken from webrick | |
298 | def parse_qvalues(value) |
|
298 | def parse_qvalues(value) | |
299 | tmp = [] |
|
299 | tmp = [] | |
300 | if value |
|
300 | if value | |
301 | parts = value.split(/,\s*/) |
|
301 | parts = value.split(/,\s*/) | |
302 | parts.each {|part| |
|
302 | parts.each {|part| | |
303 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) |
|
303 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) | |
304 | val = m[1] |
|
304 | val = m[1] | |
305 | q = (m[2] or 1).to_f |
|
305 | q = (m[2] or 1).to_f | |
306 | tmp.push([val, q]) |
|
306 | tmp.push([val, q]) | |
307 | end |
|
307 | end | |
308 | } |
|
308 | } | |
309 | tmp = tmp.sort_by{|val, q| -q} |
|
309 | tmp = tmp.sort_by{|val, q| -q} | |
310 | tmp.collect!{|val, q| val} |
|
310 | tmp.collect!{|val, q| val} | |
311 | end |
|
311 | end | |
312 | return tmp |
|
312 | return tmp | |
313 | rescue |
|
313 | rescue | |
314 | nil |
|
314 | nil | |
315 | end |
|
315 | end | |
316 |
|
316 | |||
317 | # Returns a string that can be used as filename value in Content-Disposition header |
|
317 | # Returns a string that can be used as filename value in Content-Disposition header | |
318 | def filename_for_content_disposition(name) |
|
318 | def filename_for_content_disposition(name) | |
319 | request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name |
|
319 | request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name | |
320 | end |
|
320 | end | |
321 |
|
321 | |||
322 | def api_request? |
|
322 | def api_request? | |
323 | %w(xml json).include? params[:format] |
|
323 | %w(xml json).include? params[:format] | |
324 | end |
|
324 | end | |
325 | end |
|
325 | end |
@@ -1,182 +1,182 | |||||
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 | require 'iconv' |
|
18 | require 'iconv' | |
19 |
|
19 | |||
20 | module RepositoriesHelper |
|
20 | module RepositoriesHelper | |
21 | def format_revision(txt) |
|
21 | def format_revision(txt) | |
22 | txt.to_s[0,8] |
|
22 | txt.to_s[0,8] | |
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | def truncate_at_line_break(text, length = 255) |
|
25 | def truncate_at_line_break(text, length = 255) | |
26 | if text |
|
26 | if text | |
27 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
|
27 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def render_properties(properties) |
|
31 | def render_properties(properties) | |
32 | unless properties.nil? || properties.empty? |
|
32 | unless properties.nil? || properties.empty? | |
33 | content = '' |
|
33 | content = '' | |
34 | properties.keys.sort.each do |property| |
|
34 | properties.keys.sort.each do |property| | |
35 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
|
35 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") | |
36 | end |
|
36 | end | |
37 | content_tag('ul', content, :class => 'properties') |
|
37 | content_tag('ul', content, :class => 'properties') | |
38 | end |
|
38 | end | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def render_changeset_changes |
|
41 | def render_changeset_changes | |
42 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
|
42 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| | |
43 | case change.action |
|
43 | case change.action | |
44 | when 'A' |
|
44 | when 'A' | |
45 | # Detects moved/copied files |
|
45 | # Detects moved/copied files | |
46 | if !change.from_path.blank? |
|
46 | if !change.from_path.blank? | |
47 | change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
|
47 | change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' | |
48 | end |
|
48 | end | |
49 | change |
|
49 | change | |
50 | when 'D' |
|
50 | when 'D' | |
51 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
|
51 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change | |
52 | else |
|
52 | else | |
53 | change |
|
53 | change | |
54 | end |
|
54 | end | |
55 | end.compact |
|
55 | end.compact | |
56 |
|
56 | |||
57 | tree = { } |
|
57 | tree = { } | |
58 | changes.each do |change| |
|
58 | changes.each do |change| | |
59 | p = tree |
|
59 | p = tree | |
60 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} |
|
60 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} | |
61 | dirs.each do |dir| |
|
61 | dirs.each do |dir| | |
62 | p[:s] ||= {} |
|
62 | p[:s] ||= {} | |
63 | p = p[:s] |
|
63 | p = p[:s] | |
64 | p[dir] ||= {} |
|
64 | p[dir] ||= {} | |
65 | p = p[dir] |
|
65 | p = p[dir] | |
66 | end |
|
66 | end | |
67 | p[:c] = change |
|
67 | p[:c] = change | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | render_changes_tree(tree[:s]) |
|
70 | render_changes_tree(tree[:s]) | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def render_changes_tree(tree) |
|
73 | def render_changes_tree(tree) | |
74 | return '' if tree.nil? |
|
74 | return '' if tree.nil? | |
75 |
|
75 | |||
76 | output = '' |
|
76 | output = '' | |
77 | output << '<ul>' |
|
77 | output << '<ul>' | |
78 | tree.keys.sort.each do |file| |
|
78 | tree.keys.sort.each do |file| | |
79 | s = !tree[file][:s].nil? |
|
79 | s = !tree[file][:s].nil? | |
80 | c = tree[file][:c] |
|
80 | c = tree[file][:c] | |
81 |
|
81 | |||
82 | style = 'change' |
|
82 | style = 'change' | |
83 | style << ' folder' if s |
|
83 | style << ' folder' if s | |
84 | style << " change-#{c.action}" if c |
|
84 | style << " change-#{c.action}" if c | |
85 |
|
85 | |||
86 | text = h(file) |
|
86 | text = h(file) | |
87 | unless c.nil? |
|
87 | unless c.nil? | |
88 | path_param = to_path_param(@repository.relative_path(c.path)) |
|
88 | path_param = to_path_param(@repository.relative_path(c.path)) | |
89 | text = link_to(text, :controller => 'repositories', |
|
89 | text = link_to(text, :controller => 'repositories', | |
90 | :action => 'entry', |
|
90 | :action => 'entry', | |
91 | :id => @project, |
|
91 | :id => @project, | |
92 | :path => path_param, |
|
92 | :path => path_param, | |
93 | :rev => @changeset.revision) unless s || c.action == 'D' |
|
93 | :rev => @changeset.revision) unless s || c.action == 'D' | |
94 | text << " - #{c.revision}" unless c.revision.blank? |
|
94 | text << " - #{c.revision}" unless c.revision.blank? | |
95 | text << ' (' + link_to('diff', :controller => 'repositories', |
|
95 | text << ' (' + link_to('diff', :controller => 'repositories', | |
96 | :action => 'diff', |
|
96 | :action => 'diff', | |
97 | :id => @project, |
|
97 | :id => @project, | |
98 | :path => path_param, |
|
98 | :path => path_param, | |
99 | :rev => @changeset.revision) + ') ' if c.action == 'M' |
|
99 | :rev => @changeset.revision) + ') ' if c.action == 'M' | |
100 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
|
100 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? | |
101 | end |
|
101 | end | |
102 | output << "<li class='#{style}'>#{text}</li>" |
|
102 | output << "<li class='#{style}'>#{text}</li>" | |
103 | output << render_changes_tree(tree[file][:s]) if s |
|
103 | output << render_changes_tree(tree[file][:s]) if s | |
104 | end |
|
104 | end | |
105 | output << '</ul>' |
|
105 | output << '</ul>' | |
106 | output |
|
106 | output | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 | def to_utf8(str) |
|
109 | def to_utf8(str) | |
110 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
110 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |
111 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
|
111 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) | |
112 | @encodings.each do |encoding| |
|
112 | @encodings.each do |encoding| | |
113 | begin |
|
113 | begin | |
114 | return Iconv.conv('UTF-8', encoding, str) |
|
114 | return Iconv.conv('UTF-8', encoding, str) | |
115 | rescue Iconv::Failure |
|
115 | rescue Iconv::Failure | |
116 | # do nothing here and try the next encoding |
|
116 | # do nothing here and try the next encoding | |
117 | end |
|
117 | end | |
118 | end |
|
118 | end | |
119 | str |
|
119 | str | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def repository_field_tags(form, repository) |
|
122 | def repository_field_tags(form, repository) | |
123 | method = repository.class.name.demodulize.underscore + "_field_tags" |
|
123 | method = repository.class.name.demodulize.underscore + "_field_tags" | |
124 | send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' |
|
124 | send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def scm_select_tag(repository) |
|
127 | def scm_select_tag(repository) | |
128 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
|
128 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] | |
129 | REDMINE_SUPPORTED_SCM.each do |scm| |
|
129 | Redmine::Scm::Base.all.each do |scm| | |
130 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) |
|
130 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | select_tag('repository_scm', |
|
133 | select_tag('repository_scm', | |
134 | options_for_select(scm_options, repository.class.name.demodulize), |
|
134 | options_for_select(scm_options, repository.class.name.demodulize), | |
135 | :disabled => (repository && !repository.new_record?), |
|
135 | :disabled => (repository && !repository.new_record?), | |
136 | :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") |
|
136 | :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") | |
137 | ) |
|
137 | ) | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def with_leading_slash(path) |
|
140 | def with_leading_slash(path) | |
141 | path.to_s.starts_with?('/') ? path : "/#{path}" |
|
141 | path.to_s.starts_with?('/') ? path : "/#{path}" | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def without_leading_slash(path) |
|
144 | def without_leading_slash(path) | |
145 | path.gsub(%r{^/+}, '') |
|
145 | path.gsub(%r{^/+}, '') | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def subversion_field_tags(form, repository) |
|
148 | def subversion_field_tags(form, repository) | |
149 | content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + |
|
149 | content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + | |
150 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + |
|
150 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + | |
151 | content_tag('p', form.text_field(:login, :size => 30)) + |
|
151 | content_tag('p', form.text_field(:login, :size => 30)) + | |
152 | content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', |
|
152 | content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', | |
153 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
153 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), | |
154 | :onfocus => "this.value=''; this.name='repository[password]';", |
|
154 | :onfocus => "this.value=''; this.name='repository[password]';", | |
155 | :onchange => "this.name='repository[password]';")) |
|
155 | :onchange => "this.name='repository[password]';")) | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def darcs_field_tags(form, repository) |
|
158 | def darcs_field_tags(form, repository) | |
159 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
|
159 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) | |
160 | end |
|
160 | end | |
161 |
|
161 | |||
162 | def mercurial_field_tags(form, repository) |
|
162 | def mercurial_field_tags(form, repository) | |
163 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
163 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def git_field_tags(form, repository) |
|
166 | def git_field_tags(form, repository) | |
167 | content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
167 | content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | def cvs_field_tags(form, repository) |
|
170 | def cvs_field_tags(form, repository) | |
171 | content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + |
|
171 | content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + | |
172 | content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) |
|
172 | content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | def bazaar_field_tags(form, repository) |
|
175 | def bazaar_field_tags(form, repository) | |
176 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
|
176 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | def filesystem_field_tags(form, repository) |
|
179 | def filesystem_field_tags(form, repository) | |
180 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
180 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) | |
181 | end |
|
181 | end | |
182 | end |
|
182 | end |
@@ -1,37 +1,37 | |||||
1 | <% form_tag({:action => 'edit', :tab => 'repositories'}) do %> |
|
1 | <% form_tag({:action => 'edit', :tab => 'repositories'}) do %> | |
2 |
|
2 | |||
3 | <div class="box tabular settings"> |
|
3 | <div class="box tabular settings"> | |
4 | <p><%= setting_check_box :autofetch_changesets %></p> |
|
4 | <p><%= setting_check_box :autofetch_changesets %></p> | |
5 |
|
5 | |||
6 | <p><%= setting_check_box :sys_api_enabled, |
|
6 | <p><%= setting_check_box :sys_api_enabled, | |
7 | :onclick => "if (this.checked) { Form.Element.enable('settings_sys_api_key'); } else { Form.Element.disable('settings_sys_api_key'); }" %></p> |
|
7 | :onclick => "if (this.checked) { Form.Element.enable('settings_sys_api_key'); } else { Form.Element.disable('settings_sys_api_key'); }" %></p> | |
8 |
|
8 | |||
9 | <p><%= setting_text_field :sys_api_key, :size => 30, |
|
9 | <p><%= setting_text_field :sys_api_key, :size => 30, | |
10 | :id => 'settings_sys_api_key', |
|
10 | :id => 'settings_sys_api_key', | |
11 | :disabled => !Setting.sys_api_enabled?, |
|
11 | :disabled => !Setting.sys_api_enabled?, | |
12 | :label => :setting_mail_handler_api_key %> |
|
12 | :label => :setting_mail_handler_api_key %> | |
13 | <%= link_to_function l(:label_generate_key), "if ($('settings_sys_api_key').disabled == false) { $('settings_sys_api_key').value = randomKey(20) }" %> |
|
13 | <%= link_to_function l(:label_generate_key), "if ($('settings_sys_api_key').disabled == false) { $('settings_sys_api_key').value = randomKey(20) }" %> | |
14 | </p> |
|
14 | </p> | |
15 |
|
15 | |||
16 |
<p><%= setting_multiselect(:enabled_scm, R |
|
16 | <p><%= setting_multiselect(:enabled_scm, Redmine::Scm::Base.all) %></p> | |
17 |
|
17 | |||
18 | <p><%= setting_text_field :repositories_encodings, :size => 60 %><br /> |
|
18 | <p><%= setting_text_field :repositories_encodings, :size => 60 %><br /> | |
19 | <em><%= l(:text_comma_separated) %></em></p> |
|
19 | <em><%= l(:text_comma_separated) %></em></p> | |
20 |
|
20 | |||
21 | <p><%= setting_select :commit_logs_encoding, Setting::ENCODINGS %></p> |
|
21 | <p><%= setting_select :commit_logs_encoding, Setting::ENCODINGS %></p> | |
22 |
|
22 | |||
23 | <p><%= setting_text_field :repository_log_display_limit, :size => 6 %></p> |
|
23 | <p><%= setting_text_field :repository_log_display_limit, :size => 6 %></p> | |
24 | </div> |
|
24 | </div> | |
25 |
|
25 | |||
26 | <fieldset class="box tabular settings"><legend><%= l(:text_issues_ref_in_commit_messages) %></legend> |
|
26 | <fieldset class="box tabular settings"><legend><%= l(:text_issues_ref_in_commit_messages) %></legend> | |
27 | <p><%= setting_text_field :commit_ref_keywords, :size => 30 %><br /> |
|
27 | <p><%= setting_text_field :commit_ref_keywords, :size => 30 %><br /> | |
28 | <em><%= l(:text_comma_separated) %></em></p> |
|
28 | <em><%= l(:text_comma_separated) %></em></p> | |
29 |
|
29 | |||
30 | <p><%= setting_text_field :commit_fix_keywords, :size => 30 %> |
|
30 | <p><%= setting_text_field :commit_fix_keywords, :size => 30 %> | |
31 | <%= l(:label_applied_status) %>: <%= setting_select :commit_fix_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %> |
|
31 | <%= l(:label_applied_status) %>: <%= setting_select :commit_fix_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %> | |
32 | <%= l(:field_done_ratio) %>: <%= setting_select :commit_fix_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %> |
|
32 | <%= l(:field_done_ratio) %>: <%= setting_select :commit_fix_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %> | |
33 | <br /><em><%= l(:text_comma_separated) %></em></p> |
|
33 | <br /><em><%= l(:text_comma_separated) %></em></p> | |
34 | </fieldset> |
|
34 | </fieldset> | |
35 |
|
35 | |||
36 | <%= submit_tag l(:button_save) %> |
|
36 | <%= submit_tag l(:button_save) %> | |
37 | <% end %> |
|
37 | <% end %> |
@@ -1,176 +1,183 | |||||
1 | require 'redmine/access_control' |
|
1 | require 'redmine/access_control' | |
2 | require 'redmine/menu_manager' |
|
2 | require 'redmine/menu_manager' | |
3 | require 'redmine/activity' |
|
3 | require 'redmine/activity' | |
4 | require 'redmine/mime_type' |
|
4 | require 'redmine/mime_type' | |
5 | require 'redmine/core_ext' |
|
5 | require 'redmine/core_ext' | |
6 | require 'redmine/themes' |
|
6 | require 'redmine/themes' | |
7 | require 'redmine/hook' |
|
7 | require 'redmine/hook' | |
8 | require 'redmine/plugin' |
|
8 | require 'redmine/plugin' | |
9 | require 'redmine/wiki_formatting' |
|
9 | require 'redmine/wiki_formatting' | |
|
10 | require 'redmine/scm/base' | |||
10 |
|
11 | |||
11 | begin |
|
12 | begin | |
12 | require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick) |
|
13 | require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick) | |
13 | rescue LoadError |
|
14 | rescue LoadError | |
14 | # RMagick is not available |
|
15 | # RMagick is not available | |
15 | end |
|
16 | end | |
16 |
|
17 | |||
17 | if RUBY_VERSION < '1.9' |
|
18 | if RUBY_VERSION < '1.9' | |
18 | require 'faster_csv' |
|
19 | require 'faster_csv' | |
19 | else |
|
20 | else | |
20 | require 'csv' |
|
21 | require 'csv' | |
21 | FCSV = CSV |
|
22 | FCSV = CSV | |
22 | end |
|
23 | end | |
23 |
|
24 | |||
24 | REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Bazaar Git Filesystem ) |
|
25 | Redmine::Scm::Base.add "Subversion" | |
|
26 | Redmine::Scm::Base.add "Darcs" | |||
|
27 | Redmine::Scm::Base.add "Mercurial" | |||
|
28 | Redmine::Scm::Base.add "Cvs" | |||
|
29 | Redmine::Scm::Base.add "Bazaar" | |||
|
30 | Redmine::Scm::Base.add "Git" | |||
|
31 | Redmine::Scm::Base.add "Filesystem" | |||
25 |
|
32 | |||
26 | # Permissions |
|
33 | # Permissions | |
27 | Redmine::AccessControl.map do |map| |
|
34 | Redmine::AccessControl.map do |map| | |
28 | map.permission :view_project, {:projects => [:show, :activity]}, :public => true |
|
35 | map.permission :view_project, {:projects => [:show, :activity]}, :public => true | |
29 | map.permission :search_project, {:search => :index}, :public => true |
|
36 | map.permission :search_project, {:search => :index}, :public => true | |
30 | map.permission :add_project, {:projects => :add}, :require => :loggedin |
|
37 | map.permission :add_project, {:projects => :add}, :require => :loggedin | |
31 | map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member |
|
38 | map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member | |
32 | map.permission :select_project_modules, {:projects => :modules}, :require => :member |
|
39 | map.permission :select_project_modules, {:projects => :modules}, :require => :member | |
33 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member |
|
40 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member | |
34 | map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :close_completed, :destroy]}, :require => :member |
|
41 | map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :close_completed, :destroy]}, :require => :member | |
35 | map.permission :add_subprojects, {:projects => :add}, :require => :member |
|
42 | map.permission :add_subprojects, {:projects => :add}, :require => :member | |
36 |
|
43 | |||
37 | map.project_module :issue_tracking do |map| |
|
44 | map.project_module :issue_tracking do |map| | |
38 | # Issue categories |
|
45 | # Issue categories | |
39 | map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member |
|
46 | map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member | |
40 | # Issues |
|
47 | # Issues | |
41 | map.permission :view_issues, {:projects => :roadmap, |
|
48 | map.permission :view_issues, {:projects => :roadmap, | |
42 | :issues => [:index, :changes, :show, :context_menu], |
|
49 | :issues => [:index, :changes, :show, :context_menu], | |
43 | :versions => [:show, :status_by], |
|
50 | :versions => [:show, :status_by], | |
44 | :queries => :index, |
|
51 | :queries => :index, | |
45 | :reports => [:issue_report, :issue_report_details]} |
|
52 | :reports => [:issue_report, :issue_report_details]} | |
46 | map.permission :add_issues, {:issues => [:new, :update_form]} |
|
53 | map.permission :add_issues, {:issues => [:new, :update_form]} | |
47 | map.permission :edit_issues, {:issues => [:edit, :reply, :bulk_edit, :update_form]} |
|
54 | map.permission :edit_issues, {:issues => [:edit, :reply, :bulk_edit, :update_form]} | |
48 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} |
|
55 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} | |
49 | map.permission :add_issue_notes, {:issues => [:edit, :reply]} |
|
56 | map.permission :add_issue_notes, {:issues => [:edit, :reply]} | |
50 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin |
|
57 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin | |
51 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin |
|
58 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin | |
52 | map.permission :move_issues, {:issues => :move}, :require => :loggedin |
|
59 | map.permission :move_issues, {:issues => :move}, :require => :loggedin | |
53 | map.permission :delete_issues, {:issues => :destroy}, :require => :member |
|
60 | map.permission :delete_issues, {:issues => :destroy}, :require => :member | |
54 | # Queries |
|
61 | # Queries | |
55 | map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member |
|
62 | map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member | |
56 | map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin |
|
63 | map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin | |
57 | # Gantt & calendar |
|
64 | # Gantt & calendar | |
58 | map.permission :view_gantt, :issues => :gantt |
|
65 | map.permission :view_gantt, :issues => :gantt | |
59 | map.permission :view_calendar, :issues => :calendar |
|
66 | map.permission :view_calendar, :issues => :calendar | |
60 | # Watchers |
|
67 | # Watchers | |
61 | map.permission :view_issue_watchers, {} |
|
68 | map.permission :view_issue_watchers, {} | |
62 | map.permission :add_issue_watchers, {:watchers => :new} |
|
69 | map.permission :add_issue_watchers, {:watchers => :new} | |
63 | map.permission :delete_issue_watchers, {:watchers => :destroy} |
|
70 | map.permission :delete_issue_watchers, {:watchers => :destroy} | |
64 | end |
|
71 | end | |
65 |
|
72 | |||
66 | map.project_module :time_tracking do |map| |
|
73 | map.project_module :time_tracking do |map| | |
67 | map.permission :log_time, {:timelog => :edit}, :require => :loggedin |
|
74 | map.permission :log_time, {:timelog => :edit}, :require => :loggedin | |
68 | map.permission :view_time_entries, :timelog => [:details, :report] |
|
75 | map.permission :view_time_entries, :timelog => [:details, :report] | |
69 | map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member |
|
76 | map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member | |
70 | map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin |
|
77 | map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin | |
71 | map.permission :manage_project_activities, {:projects => [:save_activities, :reset_activities]}, :require => :member |
|
78 | map.permission :manage_project_activities, {:projects => [:save_activities, :reset_activities]}, :require => :member | |
72 | end |
|
79 | end | |
73 |
|
80 | |||
74 | map.project_module :news do |map| |
|
81 | map.project_module :news do |map| | |
75 | map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member |
|
82 | map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member | |
76 | map.permission :view_news, {:news => [:index, :show]}, :public => true |
|
83 | map.permission :view_news, {:news => [:index, :show]}, :public => true | |
77 | map.permission :comment_news, {:news => :add_comment} |
|
84 | map.permission :comment_news, {:news => :add_comment} | |
78 | end |
|
85 | end | |
79 |
|
86 | |||
80 | map.project_module :documents do |map| |
|
87 | map.project_module :documents do |map| | |
81 | map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin |
|
88 | map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin | |
82 | map.permission :view_documents, :documents => [:index, :show, :download] |
|
89 | map.permission :view_documents, :documents => [:index, :show, :download] | |
83 | end |
|
90 | end | |
84 |
|
91 | |||
85 | map.project_module :files do |map| |
|
92 | map.project_module :files do |map| | |
86 | map.permission :manage_files, {:projects => :add_file}, :require => :loggedin |
|
93 | map.permission :manage_files, {:projects => :add_file}, :require => :loggedin | |
87 | map.permission :view_files, :projects => :list_files, :versions => :download |
|
94 | map.permission :view_files, :projects => :list_files, :versions => :download | |
88 | end |
|
95 | end | |
89 |
|
96 | |||
90 | map.project_module :wiki do |map| |
|
97 | map.project_module :wiki do |map| | |
91 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member |
|
98 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member | |
92 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member |
|
99 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member | |
93 | map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member |
|
100 | map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member | |
94 | map.permission :view_wiki_pages, :wiki => [:index, :special] |
|
101 | map.permission :view_wiki_pages, :wiki => [:index, :special] | |
95 | map.permission :export_wiki_pages, {} |
|
102 | map.permission :export_wiki_pages, {} | |
96 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] |
|
103 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] | |
97 | map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment] |
|
104 | map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment] | |
98 | map.permission :delete_wiki_pages_attachments, {} |
|
105 | map.permission :delete_wiki_pages_attachments, {} | |
99 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member |
|
106 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member | |
100 | end |
|
107 | end | |
101 |
|
108 | |||
102 | map.project_module :repository do |map| |
|
109 | map.project_module :repository do |map| | |
103 | map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member |
|
110 | map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member | |
104 | map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph] |
|
111 | map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph] | |
105 | map.permission :view_changesets, :repositories => [:show, :revisions, :revision] |
|
112 | map.permission :view_changesets, :repositories => [:show, :revisions, :revision] | |
106 | map.permission :commit_access, {} |
|
113 | map.permission :commit_access, {} | |
107 | end |
|
114 | end | |
108 |
|
115 | |||
109 | map.project_module :boards do |map| |
|
116 | map.project_module :boards do |map| | |
110 | map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member |
|
117 | map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member | |
111 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true |
|
118 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true | |
112 | map.permission :add_messages, {:messages => [:new, :reply, :quote]} |
|
119 | map.permission :add_messages, {:messages => [:new, :reply, :quote]} | |
113 | map.permission :edit_messages, {:messages => :edit}, :require => :member |
|
120 | map.permission :edit_messages, {:messages => :edit}, :require => :member | |
114 | map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin |
|
121 | map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin | |
115 | map.permission :delete_messages, {:messages => :destroy}, :require => :member |
|
122 | map.permission :delete_messages, {:messages => :destroy}, :require => :member | |
116 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin |
|
123 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin | |
117 | end |
|
124 | end | |
118 | end |
|
125 | end | |
119 |
|
126 | |||
120 | Redmine::MenuManager.map :top_menu do |menu| |
|
127 | Redmine::MenuManager.map :top_menu do |menu| | |
121 | menu.push :home, :home_path |
|
128 | menu.push :home, :home_path | |
122 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } |
|
129 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } | |
123 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural |
|
130 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural | |
124 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true |
|
131 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true | |
125 | menu.push :help, Redmine::Info.help_url, :last => true |
|
132 | menu.push :help, Redmine::Info.help_url, :last => true | |
126 | end |
|
133 | end | |
127 |
|
134 | |||
128 | Redmine::MenuManager.map :account_menu do |menu| |
|
135 | Redmine::MenuManager.map :account_menu do |menu| | |
129 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } |
|
136 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } | |
130 | menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? } |
|
137 | menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? } | |
131 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } |
|
138 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } | |
132 | menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? } |
|
139 | menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? } | |
133 | end |
|
140 | end | |
134 |
|
141 | |||
135 | Redmine::MenuManager.map :application_menu do |menu| |
|
142 | Redmine::MenuManager.map :application_menu do |menu| | |
136 | # Empty |
|
143 | # Empty | |
137 | end |
|
144 | end | |
138 |
|
145 | |||
139 | Redmine::MenuManager.map :admin_menu do |menu| |
|
146 | Redmine::MenuManager.map :admin_menu do |menu| | |
140 | # Empty |
|
147 | # Empty | |
141 | end |
|
148 | end | |
142 |
|
149 | |||
143 | Redmine::MenuManager.map :project_menu do |menu| |
|
150 | Redmine::MenuManager.map :project_menu do |menu| | |
144 | menu.push :overview, { :controller => 'projects', :action => 'show' } |
|
151 | menu.push :overview, { :controller => 'projects', :action => 'show' } | |
145 | menu.push :activity, { :controller => 'projects', :action => 'activity' } |
|
152 | menu.push :activity, { :controller => 'projects', :action => 'activity' } | |
146 | menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, |
|
153 | menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, | |
147 | :if => Proc.new { |p| p.shared_versions.any? } |
|
154 | :if => Proc.new { |p| p.shared_versions.any? } | |
148 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural |
|
155 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural | |
149 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, |
|
156 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, | |
150 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } |
|
157 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } | |
151 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural |
|
158 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural | |
152 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural |
|
159 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural | |
153 | menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, |
|
160 | menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, | |
154 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } |
|
161 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } | |
155 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, |
|
162 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, | |
156 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural |
|
163 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural | |
157 | menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural |
|
164 | menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural | |
158 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, |
|
165 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, | |
159 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } |
|
166 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } | |
160 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true |
|
167 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true | |
161 | end |
|
168 | end | |
162 |
|
169 | |||
163 | Redmine::Activity.map do |activity| |
|
170 | Redmine::Activity.map do |activity| | |
164 | activity.register :issues, :class_name => %w(Issue Journal) |
|
171 | activity.register :issues, :class_name => %w(Issue Journal) | |
165 | activity.register :changesets |
|
172 | activity.register :changesets | |
166 | activity.register :news |
|
173 | activity.register :news | |
167 | activity.register :documents, :class_name => %w(Document Attachment) |
|
174 | activity.register :documents, :class_name => %w(Document Attachment) | |
168 | activity.register :files, :class_name => 'Attachment' |
|
175 | activity.register :files, :class_name => 'Attachment' | |
169 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false |
|
176 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false | |
170 | activity.register :messages, :default => false |
|
177 | activity.register :messages, :default => false | |
171 | activity.register :time_entries, :default => false |
|
178 | activity.register :time_entries, :default => false | |
172 | end |
|
179 | end | |
173 |
|
180 | |||
174 | Redmine::WikiFormatting.map do |format| |
|
181 | Redmine::WikiFormatting.map do |format| | |
175 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper |
|
182 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper | |
176 | end |
|
183 | end |
General Comments 0
You need to be logged in to leave comments.
Login now