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