##// END OF EJS Templates
Display the bulk edit form with error messages when some issues can not be saved (#13943)....
Jean-Philippe Lang -
r11556:1269e6c7d3f5
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,607 +1,592
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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 Unauthorized < Exception; end
21 class Unauthorized < Exception; end
22
22
23 class ApplicationController < ActionController::Base
23 class ApplicationController < ActionController::Base
24 include Redmine::I18n
24 include Redmine::I18n
25 include Redmine::Pagination
25 include Redmine::Pagination
26 include RoutesHelper
26 include RoutesHelper
27 helper :routes
27 helper :routes
28
28
29 class_attribute :accept_api_auth_actions
29 class_attribute :accept_api_auth_actions
30 class_attribute :accept_rss_auth_actions
30 class_attribute :accept_rss_auth_actions
31 class_attribute :model_object
31 class_attribute :model_object
32
32
33 layout 'base'
33 layout 'base'
34
34
35 protect_from_forgery
35 protect_from_forgery
36 def handle_unverified_request
36 def handle_unverified_request
37 super
37 super
38 cookies.delete(autologin_cookie_name)
38 cookies.delete(autologin_cookie_name)
39 end
39 end
40
40
41 before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization
41 before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization
42
42
43 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
43 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
44 rescue_from ::Unauthorized, :with => :deny_access
44 rescue_from ::Unauthorized, :with => :deny_access
45 rescue_from ::ActionView::MissingTemplate, :with => :missing_template
45 rescue_from ::ActionView::MissingTemplate, :with => :missing_template
46
46
47 include Redmine::Search::Controller
47 include Redmine::Search::Controller
48 include Redmine::MenuManager::MenuController
48 include Redmine::MenuManager::MenuController
49 helper Redmine::MenuManager::MenuHelper
49 helper Redmine::MenuManager::MenuHelper
50
50
51 def session_expiration
51 def session_expiration
52 if session[:user_id]
52 if session[:user_id]
53 if session_expired? && !try_to_autologin
53 if session_expired? && !try_to_autologin
54 reset_session
54 reset_session
55 flash[:error] = l(:error_session_expired)
55 flash[:error] = l(:error_session_expired)
56 redirect_to signin_url
56 redirect_to signin_url
57 else
57 else
58 session[:atime] = Time.now.utc.to_i
58 session[:atime] = Time.now.utc.to_i
59 end
59 end
60 end
60 end
61 end
61 end
62
62
63 def session_expired?
63 def session_expired?
64 if Setting.session_lifetime?
64 if Setting.session_lifetime?
65 unless session[:ctime] && (Time.now.utc.to_i - session[:ctime].to_i <= Setting.session_lifetime.to_i * 60)
65 unless session[:ctime] && (Time.now.utc.to_i - session[:ctime].to_i <= Setting.session_lifetime.to_i * 60)
66 return true
66 return true
67 end
67 end
68 end
68 end
69 if Setting.session_timeout?
69 if Setting.session_timeout?
70 unless session[:atime] && (Time.now.utc.to_i - session[:atime].to_i <= Setting.session_timeout.to_i * 60)
70 unless session[:atime] && (Time.now.utc.to_i - session[:atime].to_i <= Setting.session_timeout.to_i * 60)
71 return true
71 return true
72 end
72 end
73 end
73 end
74 false
74 false
75 end
75 end
76
76
77 def start_user_session(user)
77 def start_user_session(user)
78 session[:user_id] = user.id
78 session[:user_id] = user.id
79 session[:ctime] = Time.now.utc.to_i
79 session[:ctime] = Time.now.utc.to_i
80 session[:atime] = Time.now.utc.to_i
80 session[:atime] = Time.now.utc.to_i
81 end
81 end
82
82
83 def user_setup
83 def user_setup
84 # Check the settings cache for each request
84 # Check the settings cache for each request
85 Setting.check_cache
85 Setting.check_cache
86 # Find the current user
86 # Find the current user
87 User.current = find_current_user
87 User.current = find_current_user
88 logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
88 logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
89 end
89 end
90
90
91 # Returns the current user or nil if no user is logged in
91 # Returns the current user or nil if no user is logged in
92 # and starts a session if needed
92 # and starts a session if needed
93 def find_current_user
93 def find_current_user
94 user = nil
94 user = nil
95 unless api_request?
95 unless api_request?
96 if session[:user_id]
96 if session[:user_id]
97 # existing session
97 # existing session
98 user = (User.active.find(session[:user_id]) rescue nil)
98 user = (User.active.find(session[:user_id]) rescue nil)
99 elsif autologin_user = try_to_autologin
99 elsif autologin_user = try_to_autologin
100 user = autologin_user
100 user = autologin_user
101 elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
101 elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
102 # RSS key authentication does not start a session
102 # RSS key authentication does not start a session
103 user = User.find_by_rss_key(params[:key])
103 user = User.find_by_rss_key(params[:key])
104 end
104 end
105 end
105 end
106 if user.nil? && Setting.rest_api_enabled? && accept_api_auth?
106 if user.nil? && Setting.rest_api_enabled? && accept_api_auth?
107 if (key = api_key_from_request)
107 if (key = api_key_from_request)
108 # Use API key
108 # Use API key
109 user = User.find_by_api_key(key)
109 user = User.find_by_api_key(key)
110 else
110 else
111 # HTTP Basic, either username/password or API key/random
111 # HTTP Basic, either username/password or API key/random
112 authenticate_with_http_basic do |username, password|
112 authenticate_with_http_basic do |username, password|
113 user = User.try_to_login(username, password) || User.find_by_api_key(username)
113 user = User.try_to_login(username, password) || User.find_by_api_key(username)
114 end
114 end
115 end
115 end
116 # Switch user if requested by an admin user
116 # Switch user if requested by an admin user
117 if user && user.admin? && (username = api_switch_user_from_request)
117 if user && user.admin? && (username = api_switch_user_from_request)
118 su = User.find_by_login(username)
118 su = User.find_by_login(username)
119 if su && su.active?
119 if su && su.active?
120 logger.info(" User switched by: #{user.login} (id=#{user.id})") if logger
120 logger.info(" User switched by: #{user.login} (id=#{user.id})") if logger
121 user = su
121 user = su
122 else
122 else
123 render_error :message => 'Invalid X-Redmine-Switch-User header', :status => 412
123 render_error :message => 'Invalid X-Redmine-Switch-User header', :status => 412
124 end
124 end
125 end
125 end
126 end
126 end
127 user
127 user
128 end
128 end
129
129
130 def autologin_cookie_name
130 def autologin_cookie_name
131 Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'
131 Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'
132 end
132 end
133
133
134 def try_to_autologin
134 def try_to_autologin
135 if cookies[autologin_cookie_name] && Setting.autologin?
135 if cookies[autologin_cookie_name] && Setting.autologin?
136 # auto-login feature starts a new session
136 # auto-login feature starts a new session
137 user = User.try_to_autologin(cookies[autologin_cookie_name])
137 user = User.try_to_autologin(cookies[autologin_cookie_name])
138 if user
138 if user
139 reset_session
139 reset_session
140 start_user_session(user)
140 start_user_session(user)
141 end
141 end
142 user
142 user
143 end
143 end
144 end
144 end
145
145
146 # Sets the logged in user
146 # Sets the logged in user
147 def logged_user=(user)
147 def logged_user=(user)
148 reset_session
148 reset_session
149 if user && user.is_a?(User)
149 if user && user.is_a?(User)
150 User.current = user
150 User.current = user
151 start_user_session(user)
151 start_user_session(user)
152 else
152 else
153 User.current = User.anonymous
153 User.current = User.anonymous
154 end
154 end
155 end
155 end
156
156
157 # Logs out current user
157 # Logs out current user
158 def logout_user
158 def logout_user
159 if User.current.logged?
159 if User.current.logged?
160 cookies.delete(autologin_cookie_name)
160 cookies.delete(autologin_cookie_name)
161 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin'])
161 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin'])
162 self.logged_user = nil
162 self.logged_user = nil
163 end
163 end
164 end
164 end
165
165
166 # check if login is globally required to access the application
166 # check if login is globally required to access the application
167 def check_if_login_required
167 def check_if_login_required
168 # no check needed if user is already logged in
168 # no check needed if user is already logged in
169 return true if User.current.logged?
169 return true if User.current.logged?
170 require_login if Setting.login_required?
170 require_login if Setting.login_required?
171 end
171 end
172
172
173 def set_localization
173 def set_localization
174 lang = nil
174 lang = nil
175 if User.current.logged?
175 if User.current.logged?
176 lang = find_language(User.current.language)
176 lang = find_language(User.current.language)
177 end
177 end
178 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
178 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
179 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
179 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
180 if !accept_lang.blank?
180 if !accept_lang.blank?
181 accept_lang = accept_lang.downcase
181 accept_lang = accept_lang.downcase
182 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
182 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
183 end
183 end
184 end
184 end
185 lang ||= Setting.default_language
185 lang ||= Setting.default_language
186 set_language_if_valid(lang)
186 set_language_if_valid(lang)
187 end
187 end
188
188
189 def require_login
189 def require_login
190 if !User.current.logged?
190 if !User.current.logged?
191 # Extract only the basic url parameters on non-GET requests
191 # Extract only the basic url parameters on non-GET requests
192 if request.get?
192 if request.get?
193 url = url_for(params)
193 url = url_for(params)
194 else
194 else
195 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
195 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
196 end
196 end
197 respond_to do |format|
197 respond_to do |format|
198 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
198 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
199 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
199 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
200 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
200 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
201 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
201 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
202 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
202 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
203 end
203 end
204 return false
204 return false
205 end
205 end
206 true
206 true
207 end
207 end
208
208
209 def require_admin
209 def require_admin
210 return unless require_login
210 return unless require_login
211 if !User.current.admin?
211 if !User.current.admin?
212 render_403
212 render_403
213 return false
213 return false
214 end
214 end
215 true
215 true
216 end
216 end
217
217
218 def deny_access
218 def deny_access
219 User.current.logged? ? render_403 : require_login
219 User.current.logged? ? render_403 : require_login
220 end
220 end
221
221
222 # Authorize the user for the requested action
222 # Authorize the user for the requested action
223 def authorize(ctrl = params[:controller], action = params[:action], global = false)
223 def authorize(ctrl = params[:controller], action = params[:action], global = false)
224 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
224 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
225 if allowed
225 if allowed
226 true
226 true
227 else
227 else
228 if @project && @project.archived?
228 if @project && @project.archived?
229 render_403 :message => :notice_not_authorized_archived_project
229 render_403 :message => :notice_not_authorized_archived_project
230 else
230 else
231 deny_access
231 deny_access
232 end
232 end
233 end
233 end
234 end
234 end
235
235
236 # Authorize the user for the requested action outside a project
236 # Authorize the user for the requested action outside a project
237 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
237 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
238 authorize(ctrl, action, global)
238 authorize(ctrl, action, global)
239 end
239 end
240
240
241 # Find project of id params[:id]
241 # Find project of id params[:id]
242 def find_project
242 def find_project
243 @project = Project.find(params[:id])
243 @project = Project.find(params[:id])
244 rescue ActiveRecord::RecordNotFound
244 rescue ActiveRecord::RecordNotFound
245 render_404
245 render_404
246 end
246 end
247
247
248 # Find project of id params[:project_id]
248 # Find project of id params[:project_id]
249 def find_project_by_project_id
249 def find_project_by_project_id
250 @project = Project.find(params[:project_id])
250 @project = Project.find(params[:project_id])
251 rescue ActiveRecord::RecordNotFound
251 rescue ActiveRecord::RecordNotFound
252 render_404
252 render_404
253 end
253 end
254
254
255 # Find a project based on params[:project_id]
255 # Find a project based on params[:project_id]
256 # TODO: some subclasses override this, see about merging their logic
256 # TODO: some subclasses override this, see about merging their logic
257 def find_optional_project
257 def find_optional_project
258 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
258 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
259 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
259 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
260 allowed ? true : deny_access
260 allowed ? true : deny_access
261 rescue ActiveRecord::RecordNotFound
261 rescue ActiveRecord::RecordNotFound
262 render_404
262 render_404
263 end
263 end
264
264
265 # Finds and sets @project based on @object.project
265 # Finds and sets @project based on @object.project
266 def find_project_from_association
266 def find_project_from_association
267 render_404 unless @object.present?
267 render_404 unless @object.present?
268
268
269 @project = @object.project
269 @project = @object.project
270 end
270 end
271
271
272 def find_model_object
272 def find_model_object
273 model = self.class.model_object
273 model = self.class.model_object
274 if model
274 if model
275 @object = model.find(params[:id])
275 @object = model.find(params[:id])
276 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
276 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
277 end
277 end
278 rescue ActiveRecord::RecordNotFound
278 rescue ActiveRecord::RecordNotFound
279 render_404
279 render_404
280 end
280 end
281
281
282 def self.model_object(model)
282 def self.model_object(model)
283 self.model_object = model
283 self.model_object = model
284 end
284 end
285
285
286 # Find the issue whose id is the :id parameter
286 # Find the issue whose id is the :id parameter
287 # Raises a Unauthorized exception if the issue is not visible
287 # Raises a Unauthorized exception if the issue is not visible
288 def find_issue
288 def find_issue
289 # Issue.visible.find(...) can not be used to redirect user to the login form
289 # Issue.visible.find(...) can not be used to redirect user to the login form
290 # if the issue actually exists but requires authentication
290 # if the issue actually exists but requires authentication
291 @issue = Issue.find(params[:id])
291 @issue = Issue.find(params[:id])
292 raise Unauthorized unless @issue.visible?
292 raise Unauthorized unless @issue.visible?
293 @project = @issue.project
293 @project = @issue.project
294 rescue ActiveRecord::RecordNotFound
294 rescue ActiveRecord::RecordNotFound
295 render_404
295 render_404
296 end
296 end
297
297
298 # Find issues with a single :id param or :ids array param
298 # Find issues with a single :id param or :ids array param
299 # Raises a Unauthorized exception if one of the issues is not visible
299 # Raises a Unauthorized exception if one of the issues is not visible
300 def find_issues
300 def find_issues
301 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
301 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
302 raise ActiveRecord::RecordNotFound if @issues.empty?
302 raise ActiveRecord::RecordNotFound if @issues.empty?
303 raise Unauthorized unless @issues.all?(&:visible?)
303 raise Unauthorized unless @issues.all?(&:visible?)
304 @projects = @issues.collect(&:project).compact.uniq
304 @projects = @issues.collect(&:project).compact.uniq
305 @project = @projects.first if @projects.size == 1
305 @project = @projects.first if @projects.size == 1
306 rescue ActiveRecord::RecordNotFound
306 rescue ActiveRecord::RecordNotFound
307 render_404
307 render_404
308 end
308 end
309
309
310 def find_attachments
310 def find_attachments
311 if (attachments = params[:attachments]).present?
311 if (attachments = params[:attachments]).present?
312 att = attachments.values.collect do |attachment|
312 att = attachments.values.collect do |attachment|
313 Attachment.find_by_token( attachment[:token] ) if attachment[:token].present?
313 Attachment.find_by_token( attachment[:token] ) if attachment[:token].present?
314 end
314 end
315 att.compact!
315 att.compact!
316 end
316 end
317 @attachments = att || []
317 @attachments = att || []
318 end
318 end
319
319
320 # make sure that the user is a member of the project (or admin) if project is private
320 # make sure that the user is a member of the project (or admin) if project is private
321 # used as a before_filter for actions that do not require any particular permission on the project
321 # used as a before_filter for actions that do not require any particular permission on the project
322 def check_project_privacy
322 def check_project_privacy
323 if @project && !@project.archived?
323 if @project && !@project.archived?
324 if @project.visible?
324 if @project.visible?
325 true
325 true
326 else
326 else
327 deny_access
327 deny_access
328 end
328 end
329 else
329 else
330 @project = nil
330 @project = nil
331 render_404
331 render_404
332 false
332 false
333 end
333 end
334 end
334 end
335
335
336 def back_url
336 def back_url
337 url = params[:back_url]
337 url = params[:back_url]
338 if url.nil? && referer = request.env['HTTP_REFERER']
338 if url.nil? && referer = request.env['HTTP_REFERER']
339 url = CGI.unescape(referer.to_s)
339 url = CGI.unescape(referer.to_s)
340 end
340 end
341 url
341 url
342 end
342 end
343
343
344 def redirect_back_or_default(default)
344 def redirect_back_or_default(default)
345 back_url = params[:back_url].to_s
345 back_url = params[:back_url].to_s
346 if back_url.present?
346 if back_url.present?
347 begin
347 begin
348 uri = URI.parse(back_url)
348 uri = URI.parse(back_url)
349 # do not redirect user to another host or to the login or register page
349 # do not redirect user to another host or to the login or register page
350 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
350 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
351 redirect_to(back_url)
351 redirect_to(back_url)
352 return
352 return
353 end
353 end
354 rescue URI::InvalidURIError
354 rescue URI::InvalidURIError
355 logger.warn("Could not redirect to invalid URL #{back_url}")
355 logger.warn("Could not redirect to invalid URL #{back_url}")
356 # redirect to default
356 # redirect to default
357 end
357 end
358 end
358 end
359 redirect_to default
359 redirect_to default
360 false
360 false
361 end
361 end
362
362
363 # Redirects to the request referer if present, redirects to args or call block otherwise.
363 # Redirects to the request referer if present, redirects to args or call block otherwise.
364 def redirect_to_referer_or(*args, &block)
364 def redirect_to_referer_or(*args, &block)
365 redirect_to :back
365 redirect_to :back
366 rescue ::ActionController::RedirectBackError
366 rescue ::ActionController::RedirectBackError
367 if args.any?
367 if args.any?
368 redirect_to *args
368 redirect_to *args
369 elsif block_given?
369 elsif block_given?
370 block.call
370 block.call
371 else
371 else
372 raise "#redirect_to_referer_or takes arguments or a block"
372 raise "#redirect_to_referer_or takes arguments or a block"
373 end
373 end
374 end
374 end
375
375
376 def render_403(options={})
376 def render_403(options={})
377 @project = nil
377 @project = nil
378 render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
378 render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
379 return false
379 return false
380 end
380 end
381
381
382 def render_404(options={})
382 def render_404(options={})
383 render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
383 render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
384 return false
384 return false
385 end
385 end
386
386
387 # Renders an error response
387 # Renders an error response
388 def render_error(arg)
388 def render_error(arg)
389 arg = {:message => arg} unless arg.is_a?(Hash)
389 arg = {:message => arg} unless arg.is_a?(Hash)
390
390
391 @message = arg[:message]
391 @message = arg[:message]
392 @message = l(@message) if @message.is_a?(Symbol)
392 @message = l(@message) if @message.is_a?(Symbol)
393 @status = arg[:status] || 500
393 @status = arg[:status] || 500
394
394
395 respond_to do |format|
395 respond_to do |format|
396 format.html {
396 format.html {
397 render :template => 'common/error', :layout => use_layout, :status => @status
397 render :template => 'common/error', :layout => use_layout, :status => @status
398 }
398 }
399 format.any { head @status }
399 format.any { head @status }
400 end
400 end
401 end
401 end
402
402
403 # Handler for ActionView::MissingTemplate exception
403 # Handler for ActionView::MissingTemplate exception
404 def missing_template
404 def missing_template
405 logger.warn "Missing template, responding with 404"
405 logger.warn "Missing template, responding with 404"
406 @project = nil
406 @project = nil
407 render_404
407 render_404
408 end
408 end
409
409
410 # Filter for actions that provide an API response
410 # Filter for actions that provide an API response
411 # but have no HTML representation for non admin users
411 # but have no HTML representation for non admin users
412 def require_admin_or_api_request
412 def require_admin_or_api_request
413 return true if api_request?
413 return true if api_request?
414 if User.current.admin?
414 if User.current.admin?
415 true
415 true
416 elsif User.current.logged?
416 elsif User.current.logged?
417 render_error(:status => 406)
417 render_error(:status => 406)
418 else
418 else
419 deny_access
419 deny_access
420 end
420 end
421 end
421 end
422
422
423 # Picks which layout to use based on the request
423 # Picks which layout to use based on the request
424 #
424 #
425 # @return [boolean, string] name of the layout to use or false for no layout
425 # @return [boolean, string] name of the layout to use or false for no layout
426 def use_layout
426 def use_layout
427 request.xhr? ? false : 'base'
427 request.xhr? ? false : 'base'
428 end
428 end
429
429
430 def invalid_authenticity_token
430 def invalid_authenticity_token
431 if api_request?
431 if api_request?
432 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
432 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
433 end
433 end
434 render_error "Invalid form authenticity token."
434 render_error "Invalid form authenticity token."
435 end
435 end
436
436
437 def render_feed(items, options={})
437 def render_feed(items, options={})
438 @items = items || []
438 @items = items || []
439 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
439 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
440 @items = @items.slice(0, Setting.feeds_limit.to_i)
440 @items = @items.slice(0, Setting.feeds_limit.to_i)
441 @title = options[:title] || Setting.app_title
441 @title = options[:title] || Setting.app_title
442 render :template => "common/feed", :formats => [:atom], :layout => false,
442 render :template => "common/feed", :formats => [:atom], :layout => false,
443 :content_type => 'application/atom+xml'
443 :content_type => 'application/atom+xml'
444 end
444 end
445
445
446 def self.accept_rss_auth(*actions)
446 def self.accept_rss_auth(*actions)
447 if actions.any?
447 if actions.any?
448 self.accept_rss_auth_actions = actions
448 self.accept_rss_auth_actions = actions
449 else
449 else
450 self.accept_rss_auth_actions || []
450 self.accept_rss_auth_actions || []
451 end
451 end
452 end
452 end
453
453
454 def accept_rss_auth?(action=action_name)
454 def accept_rss_auth?(action=action_name)
455 self.class.accept_rss_auth.include?(action.to_sym)
455 self.class.accept_rss_auth.include?(action.to_sym)
456 end
456 end
457
457
458 def self.accept_api_auth(*actions)
458 def self.accept_api_auth(*actions)
459 if actions.any?
459 if actions.any?
460 self.accept_api_auth_actions = actions
460 self.accept_api_auth_actions = actions
461 else
461 else
462 self.accept_api_auth_actions || []
462 self.accept_api_auth_actions || []
463 end
463 end
464 end
464 end
465
465
466 def accept_api_auth?(action=action_name)
466 def accept_api_auth?(action=action_name)
467 self.class.accept_api_auth.include?(action.to_sym)
467 self.class.accept_api_auth.include?(action.to_sym)
468 end
468 end
469
469
470 # Returns the number of objects that should be displayed
470 # Returns the number of objects that should be displayed
471 # on the paginated list
471 # on the paginated list
472 def per_page_option
472 def per_page_option
473 per_page = nil
473 per_page = nil
474 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
474 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
475 per_page = params[:per_page].to_s.to_i
475 per_page = params[:per_page].to_s.to_i
476 session[:per_page] = per_page
476 session[:per_page] = per_page
477 elsif session[:per_page]
477 elsif session[:per_page]
478 per_page = session[:per_page]
478 per_page = session[:per_page]
479 else
479 else
480 per_page = Setting.per_page_options_array.first || 25
480 per_page = Setting.per_page_options_array.first || 25
481 end
481 end
482 per_page
482 per_page
483 end
483 end
484
484
485 # Returns offset and limit used to retrieve objects
485 # Returns offset and limit used to retrieve objects
486 # for an API response based on offset, limit and page parameters
486 # for an API response based on offset, limit and page parameters
487 def api_offset_and_limit(options=params)
487 def api_offset_and_limit(options=params)
488 if options[:offset].present?
488 if options[:offset].present?
489 offset = options[:offset].to_i
489 offset = options[:offset].to_i
490 if offset < 0
490 if offset < 0
491 offset = 0
491 offset = 0
492 end
492 end
493 end
493 end
494 limit = options[:limit].to_i
494 limit = options[:limit].to_i
495 if limit < 1
495 if limit < 1
496 limit = 25
496 limit = 25
497 elsif limit > 100
497 elsif limit > 100
498 limit = 100
498 limit = 100
499 end
499 end
500 if offset.nil? && options[:page].present?
500 if offset.nil? && options[:page].present?
501 offset = (options[:page].to_i - 1) * limit
501 offset = (options[:page].to_i - 1) * limit
502 offset = 0 if offset < 0
502 offset = 0 if offset < 0
503 end
503 end
504 offset ||= 0
504 offset ||= 0
505
505
506 [offset, limit]
506 [offset, limit]
507 end
507 end
508
508
509 # qvalues http header parser
509 # qvalues http header parser
510 # code taken from webrick
510 # code taken from webrick
511 def parse_qvalues(value)
511 def parse_qvalues(value)
512 tmp = []
512 tmp = []
513 if value
513 if value
514 parts = value.split(/,\s*/)
514 parts = value.split(/,\s*/)
515 parts.each {|part|
515 parts.each {|part|
516 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
516 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
517 val = m[1]
517 val = m[1]
518 q = (m[2] or 1).to_f
518 q = (m[2] or 1).to_f
519 tmp.push([val, q])
519 tmp.push([val, q])
520 end
520 end
521 }
521 }
522 tmp = tmp.sort_by{|val, q| -q}
522 tmp = tmp.sort_by{|val, q| -q}
523 tmp.collect!{|val, q| val}
523 tmp.collect!{|val, q| val}
524 end
524 end
525 return tmp
525 return tmp
526 rescue
526 rescue
527 nil
527 nil
528 end
528 end
529
529
530 # Returns a string that can be used as filename value in Content-Disposition header
530 # Returns a string that can be used as filename value in Content-Disposition header
531 def filename_for_content_disposition(name)
531 def filename_for_content_disposition(name)
532 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
532 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
533 end
533 end
534
534
535 def api_request?
535 def api_request?
536 %w(xml json).include? params[:format]
536 %w(xml json).include? params[:format]
537 end
537 end
538
538
539 # Returns the API key present in the request
539 # Returns the API key present in the request
540 def api_key_from_request
540 def api_key_from_request
541 if params[:key].present?
541 if params[:key].present?
542 params[:key].to_s
542 params[:key].to_s
543 elsif request.headers["X-Redmine-API-Key"].present?
543 elsif request.headers["X-Redmine-API-Key"].present?
544 request.headers["X-Redmine-API-Key"].to_s
544 request.headers["X-Redmine-API-Key"].to_s
545 end
545 end
546 end
546 end
547
547
548 # Returns the API 'switch user' value if present
548 # Returns the API 'switch user' value if present
549 def api_switch_user_from_request
549 def api_switch_user_from_request
550 request.headers["X-Redmine-Switch-User"].to_s.presence
550 request.headers["X-Redmine-Switch-User"].to_s.presence
551 end
551 end
552
552
553 # Renders a warning flash if obj has unsaved attachments
553 # Renders a warning flash if obj has unsaved attachments
554 def render_attachment_warning_if_needed(obj)
554 def render_attachment_warning_if_needed(obj)
555 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
555 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
556 end
556 end
557
557
558 # Sets the `flash` notice or error based the number of issues that did not save
559 #
560 # @param [Array, Issue] issues all of the saved and unsaved Issues
561 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
562 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
563 if unsaved_issue_ids.empty?
564 flash[:notice] = l(:notice_successful_update) unless issues.empty?
565 else
566 flash[:error] = l(:notice_failed_to_save_issues,
567 :count => unsaved_issue_ids.size,
568 :total => issues.size,
569 :ids => '#' + unsaved_issue_ids.join(', #'))
570 end
571 end
572
573 # Rescues an invalid query statement. Just in case...
558 # Rescues an invalid query statement. Just in case...
574 def query_statement_invalid(exception)
559 def query_statement_invalid(exception)
575 logger.error "Query::StatementInvalid: #{exception.message}" if logger
560 logger.error "Query::StatementInvalid: #{exception.message}" if logger
576 session.delete(:query)
561 session.delete(:query)
577 sort_clear if respond_to?(:sort_clear)
562 sort_clear if respond_to?(:sort_clear)
578 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
563 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
579 end
564 end
580
565
581 # Renders a 200 response for successfull updates or deletions via the API
566 # Renders a 200 response for successfull updates or deletions via the API
582 def render_api_ok
567 def render_api_ok
583 render_api_head :ok
568 render_api_head :ok
584 end
569 end
585
570
586 # Renders a head API response
571 # Renders a head API response
587 def render_api_head(status)
572 def render_api_head(status)
588 # #head would return a response body with one space
573 # #head would return a response body with one space
589 render :text => '', :status => status, :layout => nil
574 render :text => '', :status => status, :layout => nil
590 end
575 end
591
576
592 # Renders API response on validation failure
577 # Renders API response on validation failure
593 def render_validation_errors(objects)
578 def render_validation_errors(objects)
594 if objects.is_a?(Array)
579 if objects.is_a?(Array)
595 @error_messages = objects.map {|object| object.errors.full_messages}.flatten
580 @error_messages = objects.map {|object| object.errors.full_messages}.flatten
596 else
581 else
597 @error_messages = objects.errors.full_messages
582 @error_messages = objects.errors.full_messages
598 end
583 end
599 render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => nil
584 render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => nil
600 end
585 end
601
586
602 # Overrides #_include_layout? so that #render with no arguments
587 # Overrides #_include_layout? so that #render with no arguments
603 # doesn't use the layout for api requests
588 # doesn't use the layout for api requests
604 def _include_layout?(*args)
589 def _include_layout?(*args)
605 api_request? ? false : super
590 api_request? ? false : super
606 end
591 end
607 end
592 end
@@ -1,442 +1,447
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 menu_item :new_issue, :only => [:new, :create]
19 menu_item :new_issue, :only => [:new, :create]
20 default_search_scope :issues
20 default_search_scope :issues
21
21
22 before_filter :find_issue, :only => [:show, :edit, :update]
22 before_filter :find_issue, :only => [:show, :edit, :update]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
24 before_filter :find_project, :only => [:new, :create, :update_form]
24 before_filter :find_project, :only => [:new, :create, :update_form]
25 before_filter :authorize, :except => [:index]
25 before_filter :authorize, :except => [:index]
26 before_filter :find_optional_project, :only => [:index]
26 before_filter :find_optional_project, :only => [:index]
27 before_filter :check_for_default_issue_status, :only => [:new, :create]
27 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
28 before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
29 accept_rss_auth :index, :show
29 accept_rss_auth :index, :show
30 accept_api_auth :index, :show, :create, :update, :destroy
30 accept_api_auth :index, :show, :create, :update, :destroy
31
31
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33
33
34 helper :journals
34 helper :journals
35 helper :projects
35 helper :projects
36 include ProjectsHelper
36 include ProjectsHelper
37 helper :custom_fields
37 helper :custom_fields
38 include CustomFieldsHelper
38 include CustomFieldsHelper
39 helper :issue_relations
39 helper :issue_relations
40 include IssueRelationsHelper
40 include IssueRelationsHelper
41 helper :watchers
41 helper :watchers
42 include WatchersHelper
42 include WatchersHelper
43 helper :attachments
43 helper :attachments
44 include AttachmentsHelper
44 include AttachmentsHelper
45 helper :queries
45 helper :queries
46 include QueriesHelper
46 include QueriesHelper
47 helper :repositories
47 helper :repositories
48 include RepositoriesHelper
48 include RepositoriesHelper
49 helper :sort
49 helper :sort
50 include SortHelper
50 include SortHelper
51 include IssuesHelper
51 include IssuesHelper
52 helper :timelog
52 helper :timelog
53 include Redmine::Export::PDF
53 include Redmine::Export::PDF
54
54
55 def index
55 def index
56 retrieve_query
56 retrieve_query
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
58 sort_update(@query.sortable_columns)
58 sort_update(@query.sortable_columns)
59 @query.sort_criteria = sort_criteria.to_a
59 @query.sort_criteria = sort_criteria.to_a
60
60
61 if @query.valid?
61 if @query.valid?
62 case params[:format]
62 case params[:format]
63 when 'csv', 'pdf'
63 when 'csv', 'pdf'
64 @limit = Setting.issues_export_limit.to_i
64 @limit = Setting.issues_export_limit.to_i
65 when 'atom'
65 when 'atom'
66 @limit = Setting.feeds_limit.to_i
66 @limit = Setting.feeds_limit.to_i
67 when 'xml', 'json'
67 when 'xml', 'json'
68 @offset, @limit = api_offset_and_limit
68 @offset, @limit = api_offset_and_limit
69 else
69 else
70 @limit = per_page_option
70 @limit = per_page_option
71 end
71 end
72
72
73 @issue_count = @query.issue_count
73 @issue_count = @query.issue_count
74 @issue_pages = Paginator.new @issue_count, @limit, params['page']
74 @issue_pages = Paginator.new @issue_count, @limit, params['page']
75 @offset ||= @issue_pages.offset
75 @offset ||= @issue_pages.offset
76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
77 :order => sort_clause,
77 :order => sort_clause,
78 :offset => @offset,
78 :offset => @offset,
79 :limit => @limit)
79 :limit => @limit)
80 @issue_count_by_group = @query.issue_count_by_group
80 @issue_count_by_group = @query.issue_count_by_group
81
81
82 respond_to do |format|
82 respond_to do |format|
83 format.html { render :template => 'issues/index', :layout => !request.xhr? }
83 format.html { render :template => 'issues/index', :layout => !request.xhr? }
84 format.api {
84 format.api {
85 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
85 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
86 }
86 }
87 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
87 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
88 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
88 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
89 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
89 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
90 end
90 end
91 else
91 else
92 respond_to do |format|
92 respond_to do |format|
93 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
93 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
94 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
94 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
95 format.api { render_validation_errors(@query) }
95 format.api { render_validation_errors(@query) }
96 end
96 end
97 end
97 end
98 rescue ActiveRecord::RecordNotFound
98 rescue ActiveRecord::RecordNotFound
99 render_404
99 render_404
100 end
100 end
101
101
102 def show
102 def show
103 @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
103 @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
104 @journals.each_with_index {|j,i| j.indice = i+1}
104 @journals.each_with_index {|j,i| j.indice = i+1}
105 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
105 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
106 @journals.reverse! if User.current.wants_comments_in_reverse_order?
106 @journals.reverse! if User.current.wants_comments_in_reverse_order?
107
107
108 @changesets = @issue.changesets.visible.all
108 @changesets = @issue.changesets.visible.all
109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
110
110
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
114 @priorities = IssuePriority.active
114 @priorities = IssuePriority.active
115 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
115 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
116 @relation = IssueRelation.new
116 @relation = IssueRelation.new
117
117
118 respond_to do |format|
118 respond_to do |format|
119 format.html {
119 format.html {
120 retrieve_previous_and_next_issue_ids
120 retrieve_previous_and_next_issue_ids
121 render :template => 'issues/show'
121 render :template => 'issues/show'
122 }
122 }
123 format.api
123 format.api
124 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
124 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
125 format.pdf {
125 format.pdf {
126 pdf = issue_to_pdf(@issue, :journals => @journals)
126 pdf = issue_to_pdf(@issue, :journals => @journals)
127 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
127 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
128 }
128 }
129 end
129 end
130 end
130 end
131
131
132 # Add a new issue
132 # Add a new issue
133 # The new issue will be created from an existing one if copy_from parameter is given
133 # The new issue will be created from an existing one if copy_from parameter is given
134 def new
134 def new
135 respond_to do |format|
135 respond_to do |format|
136 format.html { render :action => 'new', :layout => !request.xhr? }
136 format.html { render :action => 'new', :layout => !request.xhr? }
137 end
137 end
138 end
138 end
139
139
140 def create
140 def create
141 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
141 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
142 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
142 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
143 if @issue.save
143 if @issue.save
144 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
144 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
145 respond_to do |format|
145 respond_to do |format|
146 format.html {
146 format.html {
147 render_attachment_warning_if_needed(@issue)
147 render_attachment_warning_if_needed(@issue)
148 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
148 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
149 if params[:continue]
149 if params[:continue]
150 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
150 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
151 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
151 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
152 else
152 else
153 redirect_to issue_path(@issue)
153 redirect_to issue_path(@issue)
154 end
154 end
155 }
155 }
156 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
156 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
157 end
157 end
158 return
158 return
159 else
159 else
160 respond_to do |format|
160 respond_to do |format|
161 format.html { render :action => 'new' }
161 format.html { render :action => 'new' }
162 format.api { render_validation_errors(@issue) }
162 format.api { render_validation_errors(@issue) }
163 end
163 end
164 end
164 end
165 end
165 end
166
166
167 def edit
167 def edit
168 return unless update_issue_from_params
168 return unless update_issue_from_params
169
169
170 respond_to do |format|
170 respond_to do |format|
171 format.html { }
171 format.html { }
172 format.xml { }
172 format.xml { }
173 end
173 end
174 end
174 end
175
175
176 def update
176 def update
177 return unless update_issue_from_params
177 return unless update_issue_from_params
178 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
178 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
179 saved = false
179 saved = false
180 begin
180 begin
181 saved = @issue.save_issue_with_child_records(params, @time_entry)
181 saved = @issue.save_issue_with_child_records(params, @time_entry)
182 rescue ActiveRecord::StaleObjectError
182 rescue ActiveRecord::StaleObjectError
183 @conflict = true
183 @conflict = true
184 if params[:last_journal_id]
184 if params[:last_journal_id]
185 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
185 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
186 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
186 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
187 end
187 end
188 end
188 end
189
189
190 if saved
190 if saved
191 render_attachment_warning_if_needed(@issue)
191 render_attachment_warning_if_needed(@issue)
192 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
192 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
193
193
194 respond_to do |format|
194 respond_to do |format|
195 format.html { redirect_back_or_default issue_path(@issue) }
195 format.html { redirect_back_or_default issue_path(@issue) }
196 format.api { render_api_ok }
196 format.api { render_api_ok }
197 end
197 end
198 else
198 else
199 respond_to do |format|
199 respond_to do |format|
200 format.html { render :action => 'edit' }
200 format.html { render :action => 'edit' }
201 format.api { render_validation_errors(@issue) }
201 format.api { render_validation_errors(@issue) }
202 end
202 end
203 end
203 end
204 end
204 end
205
205
206 # Updates the issue form when changing the project, status or tracker
206 # Updates the issue form when changing the project, status or tracker
207 # on issue creation/update
207 # on issue creation/update
208 def update_form
208 def update_form
209 end
209 end
210
210
211 # Bulk edit/copy a set of issues
211 # Bulk edit/copy a set of issues
212 def bulk_edit
212 def bulk_edit
213 @issues.sort!
213 @issues.sort!
214 @copy = params[:copy].present?
214 @copy = params[:copy].present?
215 @notes = params[:notes]
215 @notes = params[:notes]
216
216
217 if User.current.allowed_to?(:move_issues, @projects)
217 if User.current.allowed_to?(:move_issues, @projects)
218 @allowed_projects = Issue.allowed_target_projects_on_move
218 @allowed_projects = Issue.allowed_target_projects_on_move
219 if params[:issue]
219 if params[:issue]
220 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
220 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
221 if @target_project
221 if @target_project
222 target_projects = [@target_project]
222 target_projects = [@target_project]
223 end
223 end
224 end
224 end
225 end
225 end
226 target_projects ||= @projects
226 target_projects ||= @projects
227
227
228 if @copy
228 if @copy
229 @available_statuses = [IssueStatus.default]
229 @available_statuses = [IssueStatus.default]
230 else
230 else
231 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
231 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
232 end
232 end
233 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
233 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
234 @assignables = target_projects.map(&:assignable_users).reduce(:&)
234 @assignables = target_projects.map(&:assignable_users).reduce(:&)
235 @trackers = target_projects.map(&:trackers).reduce(:&)
235 @trackers = target_projects.map(&:trackers).reduce(:&)
236 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
236 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
237 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
237 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
238 if @copy
238 if @copy
239 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
239 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
240 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
240 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
241 end
241 end
242
242
243 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
243 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
244 render :layout => false if request.xhr?
245 end
244 end
246
245
247 def bulk_update
246 def bulk_update
248 @issues.sort!
247 @issues.sort!
249 @copy = params[:copy].present?
248 @copy = params[:copy].present?
250 attributes = parse_params_for_bulk_issue_attributes(params)
249 attributes = parse_params_for_bulk_issue_attributes(params)
251
250
252 unsaved_issue_ids = []
251 unsaved_issues = []
253 moved_issues = []
252 saved_issues = []
254
253
255 if @copy && params[:copy_subtasks].present?
254 if @copy && params[:copy_subtasks].present?
256 # Descendant issues will be copied with the parent task
255 # Descendant issues will be copied with the parent task
257 # Don't copy them twice
256 # Don't copy them twice
258 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
257 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
259 end
258 end
260
259
261 @issues.each do |issue|
260 @issues.each do |issue|
262 issue.reload
261 issue.reload
263 if @copy
262 if @copy
264 issue = issue.copy({},
263 issue = issue.copy({},
265 :attachments => params[:copy_attachments].present?,
264 :attachments => params[:copy_attachments].present?,
266 :subtasks => params[:copy_subtasks].present?
265 :subtasks => params[:copy_subtasks].present?
267 )
266 )
268 end
267 end
269 journal = issue.init_journal(User.current, params[:notes])
268 journal = issue.init_journal(User.current, params[:notes])
270 issue.safe_attributes = attributes
269 issue.safe_attributes = attributes
271 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
270 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
272 if issue.save
271 if issue.save
273 moved_issues << issue
272 saved_issues << issue
274 else
273 else
275 logger.info "issue could not be updated or copied: #{issue.errors.full_messages}" if logger && logger.info
274 unsaved_issues << issue
276 # Keep unsaved issue ids to display them in flash error
277 unsaved_issue_ids << issue.id
278 end
275 end
279 end
276 end
280 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
281
277
278 if unsaved_issues.empty?
279 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
282 if params[:follow]
280 if params[:follow]
283 if @issues.size == 1 && moved_issues.size == 1
281 if @issues.size == 1 && saved_issues.size == 1
284 redirect_to issue_path(moved_issues.first)
282 redirect_to issue_path(saved_issues.first)
285 elsif moved_issues.map(&:project).uniq.size == 1
283 elsif saved_issues.map(&:project).uniq.size == 1
286 redirect_to project_issues_path(moved_issues.map(&:project).first)
284 redirect_to project_issues_path(saved_issues.map(&:project).first)
287 end
285 end
288 else
286 else
289 redirect_back_or_default _project_issues_path(@project)
287 redirect_back_or_default _project_issues_path(@project)
290 end
288 end
289 else
290 @saved_issues = @issues
291 @unsaved_issues = unsaved_issues
292 @issues = Issue.visible.find_all_by_id(@unsaved_issues.map(&:id))
293 bulk_edit
294 render :action => 'bulk_edit'
295 end
291 end
296 end
292
297
293 def destroy
298 def destroy
294 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
299 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
295 if @hours > 0
300 if @hours > 0
296 case params[:todo]
301 case params[:todo]
297 when 'destroy'
302 when 'destroy'
298 # nothing to do
303 # nothing to do
299 when 'nullify'
304 when 'nullify'
300 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
305 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
301 when 'reassign'
306 when 'reassign'
302 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
307 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
303 if reassign_to.nil?
308 if reassign_to.nil?
304 flash.now[:error] = l(:error_issue_not_found_in_project)
309 flash.now[:error] = l(:error_issue_not_found_in_project)
305 return
310 return
306 else
311 else
307 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
312 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
308 end
313 end
309 else
314 else
310 # display the destroy form if it's a user request
315 # display the destroy form if it's a user request
311 return unless api_request?
316 return unless api_request?
312 end
317 end
313 end
318 end
314 @issues.each do |issue|
319 @issues.each do |issue|
315 begin
320 begin
316 issue.reload.destroy
321 issue.reload.destroy
317 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
322 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
318 # nothing to do, issue was already deleted (eg. by a parent)
323 # nothing to do, issue was already deleted (eg. by a parent)
319 end
324 end
320 end
325 end
321 respond_to do |format|
326 respond_to do |format|
322 format.html { redirect_back_or_default _project_issues_path(@project) }
327 format.html { redirect_back_or_default _project_issues_path(@project) }
323 format.api { render_api_ok }
328 format.api { render_api_ok }
324 end
329 end
325 end
330 end
326
331
327 private
332 private
328
333
329 def find_project
334 def find_project
330 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
335 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
331 @project = Project.find(project_id)
336 @project = Project.find(project_id)
332 rescue ActiveRecord::RecordNotFound
337 rescue ActiveRecord::RecordNotFound
333 render_404
338 render_404
334 end
339 end
335
340
336 def retrieve_previous_and_next_issue_ids
341 def retrieve_previous_and_next_issue_ids
337 retrieve_query_from_session
342 retrieve_query_from_session
338 if @query
343 if @query
339 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
344 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
340 sort_update(@query.sortable_columns, 'issues_index_sort')
345 sort_update(@query.sortable_columns, 'issues_index_sort')
341 limit = 500
346 limit = 500
342 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
347 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
343 if (idx = issue_ids.index(@issue.id)) && idx < limit
348 if (idx = issue_ids.index(@issue.id)) && idx < limit
344 if issue_ids.size < 500
349 if issue_ids.size < 500
345 @issue_position = idx + 1
350 @issue_position = idx + 1
346 @issue_count = issue_ids.size
351 @issue_count = issue_ids.size
347 end
352 end
348 @prev_issue_id = issue_ids[idx - 1] if idx > 0
353 @prev_issue_id = issue_ids[idx - 1] if idx > 0
349 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
354 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
350 end
355 end
351 end
356 end
352 end
357 end
353
358
354 # Used by #edit and #update to set some common instance variables
359 # Used by #edit and #update to set some common instance variables
355 # from the params
360 # from the params
356 # TODO: Refactor, not everything in here is needed by #edit
361 # TODO: Refactor, not everything in here is needed by #edit
357 def update_issue_from_params
362 def update_issue_from_params
358 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
363 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
359 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
364 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
360 @time_entry.attributes = params[:time_entry]
365 @time_entry.attributes = params[:time_entry]
361
366
362 @issue.init_journal(User.current)
367 @issue.init_journal(User.current)
363
368
364 issue_attributes = params[:issue]
369 issue_attributes = params[:issue]
365 if issue_attributes && params[:conflict_resolution]
370 if issue_attributes && params[:conflict_resolution]
366 case params[:conflict_resolution]
371 case params[:conflict_resolution]
367 when 'overwrite'
372 when 'overwrite'
368 issue_attributes = issue_attributes.dup
373 issue_attributes = issue_attributes.dup
369 issue_attributes.delete(:lock_version)
374 issue_attributes.delete(:lock_version)
370 when 'add_notes'
375 when 'add_notes'
371 issue_attributes = issue_attributes.slice(:notes)
376 issue_attributes = issue_attributes.slice(:notes)
372 when 'cancel'
377 when 'cancel'
373 redirect_to issue_path(@issue)
378 redirect_to issue_path(@issue)
374 return false
379 return false
375 end
380 end
376 end
381 end
377 @issue.safe_attributes = issue_attributes
382 @issue.safe_attributes = issue_attributes
378 @priorities = IssuePriority.active
383 @priorities = IssuePriority.active
379 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
384 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
380 true
385 true
381 end
386 end
382
387
383 # TODO: Refactor, lots of extra code in here
388 # TODO: Refactor, lots of extra code in here
384 # TODO: Changing tracker on an existing issue should not trigger this
389 # TODO: Changing tracker on an existing issue should not trigger this
385 def build_new_issue_from_params
390 def build_new_issue_from_params
386 if params[:id].blank?
391 if params[:id].blank?
387 @issue = Issue.new
392 @issue = Issue.new
388 if params[:copy_from]
393 if params[:copy_from]
389 begin
394 begin
390 @copy_from = Issue.visible.find(params[:copy_from])
395 @copy_from = Issue.visible.find(params[:copy_from])
391 @copy_attachments = params[:copy_attachments].present? || request.get?
396 @copy_attachments = params[:copy_attachments].present? || request.get?
392 @copy_subtasks = params[:copy_subtasks].present? || request.get?
397 @copy_subtasks = params[:copy_subtasks].present? || request.get?
393 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
398 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
394 rescue ActiveRecord::RecordNotFound
399 rescue ActiveRecord::RecordNotFound
395 render_404
400 render_404
396 return
401 return
397 end
402 end
398 end
403 end
399 @issue.project = @project
404 @issue.project = @project
400 else
405 else
401 @issue = @project.issues.visible.find(params[:id])
406 @issue = @project.issues.visible.find(params[:id])
402 end
407 end
403
408
404 @issue.project = @project
409 @issue.project = @project
405 @issue.author ||= User.current
410 @issue.author ||= User.current
406 # Tracker must be set before custom field values
411 # Tracker must be set before custom field values
407 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
412 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
408 if @issue.tracker.nil?
413 if @issue.tracker.nil?
409 render_error l(:error_no_tracker_in_project)
414 render_error l(:error_no_tracker_in_project)
410 return false
415 return false
411 end
416 end
412 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
417 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
413 @issue.safe_attributes = params[:issue]
418 @issue.safe_attributes = params[:issue]
414
419
415 @priorities = IssuePriority.active
420 @priorities = IssuePriority.active
416 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
421 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
417 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
422 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
418 end
423 end
419
424
420 def check_for_default_issue_status
425 def check_for_default_issue_status
421 if IssueStatus.default.nil?
426 if IssueStatus.default.nil?
422 render_error l(:error_no_default_issue_status)
427 render_error l(:error_no_default_issue_status)
423 return false
428 return false
424 end
429 end
425 end
430 end
426
431
427 def parse_params_for_bulk_issue_attributes(params)
432 def parse_params_for_bulk_issue_attributes(params)
428 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
433 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
429 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
434 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
430 if custom = attributes[:custom_field_values]
435 if custom = attributes[:custom_field_values]
431 custom.reject! {|k,v| v.blank?}
436 custom.reject! {|k,v| v.blank?}
432 custom.keys.each do |k|
437 custom.keys.each do |k|
433 if custom[k].is_a?(Array)
438 if custom[k].is_a?(Array)
434 custom[k] << '' if custom[k].delete('__none__')
439 custom[k] << '' if custom[k].delete('__none__')
435 else
440 else
436 custom[k] = '' if custom[k] == '__none__'
441 custom[k] = '' if custom[k] == '__none__'
437 end
442 end
438 end
443 end
439 end
444 end
440 attributes
445 attributes
441 end
446 end
442 end
447 end
@@ -1,378 +1,392
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2013 Jean-Philippe Lang
4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module IssuesHelper
20 module IssuesHelper
21 include ApplicationHelper
21 include ApplicationHelper
22
22
23 def issue_list(issues, &block)
23 def issue_list(issues, &block)
24 ancestors = []
24 ancestors = []
25 issues.each do |issue|
25 issues.each do |issue|
26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
27 ancestors.pop
27 ancestors.pop
28 end
28 end
29 yield issue, ancestors.size
29 yield issue, ancestors.size
30 ancestors << issue unless issue.leaf?
30 ancestors << issue unless issue.leaf?
31 end
31 end
32 end
32 end
33
33
34 # Renders a HTML/CSS tooltip
34 # Renders a HTML/CSS tooltip
35 #
35 #
36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
37 # that contains this method wrapped in a span with the class of "tip"
37 # that contains this method wrapped in a span with the class of "tip"
38 #
38 #
39 # <div class="tooltip"><%= link_to_issue(issue) %>
39 # <div class="tooltip"><%= link_to_issue(issue) %>
40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
41 # </div>
41 # </div>
42 #
42 #
43 def render_issue_tooltip(issue)
43 def render_issue_tooltip(issue)
44 @cached_label_status ||= l(:field_status)
44 @cached_label_status ||= l(:field_status)
45 @cached_label_start_date ||= l(:field_start_date)
45 @cached_label_start_date ||= l(:field_start_date)
46 @cached_label_due_date ||= l(:field_due_date)
46 @cached_label_due_date ||= l(:field_due_date)
47 @cached_label_assigned_to ||= l(:field_assigned_to)
47 @cached_label_assigned_to ||= l(:field_assigned_to)
48 @cached_label_priority ||= l(:field_priority)
48 @cached_label_priority ||= l(:field_priority)
49 @cached_label_project ||= l(:field_project)
49 @cached_label_project ||= l(:field_project)
50
50
51 link_to_issue(issue) + "<br /><br />".html_safe +
51 link_to_issue(issue) + "<br /><br />".html_safe +
52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
58 end
58 end
59
59
60 def issue_heading(issue)
60 def issue_heading(issue)
61 h("#{issue.tracker} ##{issue.id}")
61 h("#{issue.tracker} ##{issue.id}")
62 end
62 end
63
63
64 def render_issue_subject_with_tree(issue)
64 def render_issue_subject_with_tree(issue)
65 s = ''
65 s = ''
66 ancestors = issue.root? ? [] : issue.ancestors.visible.all
66 ancestors = issue.root? ? [] : issue.ancestors.visible.all
67 ancestors.each do |ancestor|
67 ancestors.each do |ancestor|
68 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
68 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
69 end
69 end
70 s << '<div>'
70 s << '<div>'
71 subject = h(issue.subject)
71 subject = h(issue.subject)
72 if issue.is_private?
72 if issue.is_private?
73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
74 end
74 end
75 s << content_tag('h3', subject)
75 s << content_tag('h3', subject)
76 s << '</div>' * (ancestors.size + 1)
76 s << '</div>' * (ancestors.size + 1)
77 s.html_safe
77 s.html_safe
78 end
78 end
79
79
80 def render_descendants_tree(issue)
80 def render_descendants_tree(issue)
81 s = '<form><table class="list issues">'
81 s = '<form><table class="list issues">'
82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
83 css = "issue issue-#{child.id} hascontextmenu"
83 css = "issue issue-#{child.id} hascontextmenu"
84 css << " idnt idnt-#{level}" if level > 0
84 css << " idnt idnt-#{level}" if level > 0
85 s << content_tag('tr',
85 s << content_tag('tr',
86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
87 content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
87 content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
88 content_tag('td', h(child.status)) +
88 content_tag('td', h(child.status)) +
89 content_tag('td', link_to_user(child.assigned_to)) +
89 content_tag('td', link_to_user(child.assigned_to)) +
90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
91 :class => css)
91 :class => css)
92 end
92 end
93 s << '</table></form>'
93 s << '</table></form>'
94 s.html_safe
94 s.html_safe
95 end
95 end
96
96
97 # Returns an array of error messages for bulk edited issues
98 def bulk_edit_error_messages(issues)
99 messages = {}
100 issues.each do |issue|
101 issue.errors.full_messages.each do |message|
102 messages[message] ||= []
103 messages[message] << issue
104 end
105 end
106 messages.map { |message, issues|
107 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
108 }
109 end
110
97 # Returns a link for adding a new subtask to the given issue
111 # Returns a link for adding a new subtask to the given issue
98 def link_to_new_subtask(issue)
112 def link_to_new_subtask(issue)
99 attrs = {
113 attrs = {
100 :tracker_id => issue.tracker,
114 :tracker_id => issue.tracker,
101 :parent_issue_id => issue
115 :parent_issue_id => issue
102 }
116 }
103 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
117 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
104 end
118 end
105
119
106 class IssueFieldsRows
120 class IssueFieldsRows
107 include ActionView::Helpers::TagHelper
121 include ActionView::Helpers::TagHelper
108
122
109 def initialize
123 def initialize
110 @left = []
124 @left = []
111 @right = []
125 @right = []
112 end
126 end
113
127
114 def left(*args)
128 def left(*args)
115 args.any? ? @left << cells(*args) : @left
129 args.any? ? @left << cells(*args) : @left
116 end
130 end
117
131
118 def right(*args)
132 def right(*args)
119 args.any? ? @right << cells(*args) : @right
133 args.any? ? @right << cells(*args) : @right
120 end
134 end
121
135
122 def size
136 def size
123 @left.size > @right.size ? @left.size : @right.size
137 @left.size > @right.size ? @left.size : @right.size
124 end
138 end
125
139
126 def to_html
140 def to_html
127 html = ''.html_safe
141 html = ''.html_safe
128 blank = content_tag('th', '') + content_tag('td', '')
142 blank = content_tag('th', '') + content_tag('td', '')
129 size.times do |i|
143 size.times do |i|
130 left = @left[i] || blank
144 left = @left[i] || blank
131 right = @right[i] || blank
145 right = @right[i] || blank
132 html << content_tag('tr', left + right)
146 html << content_tag('tr', left + right)
133 end
147 end
134 html
148 html
135 end
149 end
136
150
137 def cells(label, text, options={})
151 def cells(label, text, options={})
138 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
152 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
139 end
153 end
140 end
154 end
141
155
142 def issue_fields_rows
156 def issue_fields_rows
143 r = IssueFieldsRows.new
157 r = IssueFieldsRows.new
144 yield r
158 yield r
145 r.to_html
159 r.to_html
146 end
160 end
147
161
148 def render_custom_fields_rows(issue)
162 def render_custom_fields_rows(issue)
149 return if issue.custom_field_values.empty?
163 return if issue.custom_field_values.empty?
150 ordered_values = []
164 ordered_values = []
151 half = (issue.custom_field_values.size / 2.0).ceil
165 half = (issue.custom_field_values.size / 2.0).ceil
152 half.times do |i|
166 half.times do |i|
153 ordered_values << issue.custom_field_values[i]
167 ordered_values << issue.custom_field_values[i]
154 ordered_values << issue.custom_field_values[i + half]
168 ordered_values << issue.custom_field_values[i + half]
155 end
169 end
156 s = "<tr>\n"
170 s = "<tr>\n"
157 n = 0
171 n = 0
158 ordered_values.compact.each do |value|
172 ordered_values.compact.each do |value|
159 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
173 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
160 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
174 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
161 n += 1
175 n += 1
162 end
176 end
163 s << "</tr>\n"
177 s << "</tr>\n"
164 s.html_safe
178 s.html_safe
165 end
179 end
166
180
167 def issues_destroy_confirmation_message(issues)
181 def issues_destroy_confirmation_message(issues)
168 issues = [issues] unless issues.is_a?(Array)
182 issues = [issues] unless issues.is_a?(Array)
169 message = l(:text_issues_destroy_confirmation)
183 message = l(:text_issues_destroy_confirmation)
170 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
184 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
171 if descendant_count > 0
185 if descendant_count > 0
172 issues.each do |issue|
186 issues.each do |issue|
173 next if issue.root?
187 next if issue.root?
174 issues.each do |other_issue|
188 issues.each do |other_issue|
175 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
189 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
176 end
190 end
177 end
191 end
178 if descendant_count > 0
192 if descendant_count > 0
179 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
193 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
180 end
194 end
181 end
195 end
182 message
196 message
183 end
197 end
184
198
185 def sidebar_queries
199 def sidebar_queries
186 unless @sidebar_queries
200 unless @sidebar_queries
187 @sidebar_queries = IssueQuery.visible.
201 @sidebar_queries = IssueQuery.visible.
188 order("#{Query.table_name}.name ASC").
202 order("#{Query.table_name}.name ASC").
189 # Project specific queries and global queries
203 # Project specific queries and global queries
190 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
204 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
191 all
205 all
192 end
206 end
193 @sidebar_queries
207 @sidebar_queries
194 end
208 end
195
209
196 def query_links(title, queries)
210 def query_links(title, queries)
197 return '' if queries.empty?
211 return '' if queries.empty?
198 # links to #index on issues/show
212 # links to #index on issues/show
199 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
213 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
200
214
201 content_tag('h3', title) + "\n" +
215 content_tag('h3', title) + "\n" +
202 content_tag('ul',
216 content_tag('ul',
203 queries.collect {|query|
217 queries.collect {|query|
204 css = 'query'
218 css = 'query'
205 css << ' selected' if query == @query
219 css << ' selected' if query == @query
206 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
220 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
207 }.join("\n").html_safe,
221 }.join("\n").html_safe,
208 :class => 'queries'
222 :class => 'queries'
209 ) + "\n"
223 ) + "\n"
210 end
224 end
211
225
212 def render_sidebar_queries
226 def render_sidebar_queries
213 out = ''.html_safe
227 out = ''.html_safe
214 out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?))
228 out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?))
215 out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?))
229 out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?))
216 out
230 out
217 end
231 end
218
232
219 # Returns the textual representation of a journal details
233 # Returns the textual representation of a journal details
220 # as an array of strings
234 # as an array of strings
221 def details_to_strings(details, no_html=false, options={})
235 def details_to_strings(details, no_html=false, options={})
222 options[:only_path] = (options[:only_path] == false ? false : true)
236 options[:only_path] = (options[:only_path] == false ? false : true)
223 strings = []
237 strings = []
224 values_by_field = {}
238 values_by_field = {}
225 details.each do |detail|
239 details.each do |detail|
226 if detail.property == 'cf'
240 if detail.property == 'cf'
227 field_id = detail.prop_key
241 field_id = detail.prop_key
228 field = CustomField.find_by_id(field_id)
242 field = CustomField.find_by_id(field_id)
229 if field && field.multiple?
243 if field && field.multiple?
230 values_by_field[field_id] ||= {:added => [], :deleted => []}
244 values_by_field[field_id] ||= {:added => [], :deleted => []}
231 if detail.old_value
245 if detail.old_value
232 values_by_field[field_id][:deleted] << detail.old_value
246 values_by_field[field_id][:deleted] << detail.old_value
233 end
247 end
234 if detail.value
248 if detail.value
235 values_by_field[field_id][:added] << detail.value
249 values_by_field[field_id][:added] << detail.value
236 end
250 end
237 next
251 next
238 end
252 end
239 end
253 end
240 strings << show_detail(detail, no_html, options)
254 strings << show_detail(detail, no_html, options)
241 end
255 end
242 values_by_field.each do |field_id, changes|
256 values_by_field.each do |field_id, changes|
243 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
257 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
244 if changes[:added].any?
258 if changes[:added].any?
245 detail.value = changes[:added]
259 detail.value = changes[:added]
246 strings << show_detail(detail, no_html, options)
260 strings << show_detail(detail, no_html, options)
247 elsif changes[:deleted].any?
261 elsif changes[:deleted].any?
248 detail.old_value = changes[:deleted]
262 detail.old_value = changes[:deleted]
249 strings << show_detail(detail, no_html, options)
263 strings << show_detail(detail, no_html, options)
250 end
264 end
251 end
265 end
252 strings
266 strings
253 end
267 end
254
268
255 # Returns the textual representation of a single journal detail
269 # Returns the textual representation of a single journal detail
256 def show_detail(detail, no_html=false, options={})
270 def show_detail(detail, no_html=false, options={})
257 multiple = false
271 multiple = false
258 case detail.property
272 case detail.property
259 when 'attr'
273 when 'attr'
260 field = detail.prop_key.to_s.gsub(/\_id$/, "")
274 field = detail.prop_key.to_s.gsub(/\_id$/, "")
261 label = l(("field_" + field).to_sym)
275 label = l(("field_" + field).to_sym)
262 case detail.prop_key
276 case detail.prop_key
263 when 'due_date', 'start_date'
277 when 'due_date', 'start_date'
264 value = format_date(detail.value.to_date) if detail.value
278 value = format_date(detail.value.to_date) if detail.value
265 old_value = format_date(detail.old_value.to_date) if detail.old_value
279 old_value = format_date(detail.old_value.to_date) if detail.old_value
266
280
267 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
281 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
268 'priority_id', 'category_id', 'fixed_version_id'
282 'priority_id', 'category_id', 'fixed_version_id'
269 value = find_name_by_reflection(field, detail.value)
283 value = find_name_by_reflection(field, detail.value)
270 old_value = find_name_by_reflection(field, detail.old_value)
284 old_value = find_name_by_reflection(field, detail.old_value)
271
285
272 when 'estimated_hours'
286 when 'estimated_hours'
273 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
287 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
274 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
288 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
275
289
276 when 'parent_id'
290 when 'parent_id'
277 label = l(:field_parent_issue)
291 label = l(:field_parent_issue)
278 value = "##{detail.value}" unless detail.value.blank?
292 value = "##{detail.value}" unless detail.value.blank?
279 old_value = "##{detail.old_value}" unless detail.old_value.blank?
293 old_value = "##{detail.old_value}" unless detail.old_value.blank?
280
294
281 when 'is_private'
295 when 'is_private'
282 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
296 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
283 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
297 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
284 end
298 end
285 when 'cf'
299 when 'cf'
286 custom_field = CustomField.find_by_id(detail.prop_key)
300 custom_field = CustomField.find_by_id(detail.prop_key)
287 if custom_field
301 if custom_field
288 multiple = custom_field.multiple?
302 multiple = custom_field.multiple?
289 label = custom_field.name
303 label = custom_field.name
290 value = format_value(detail.value, custom_field.field_format) if detail.value
304 value = format_value(detail.value, custom_field.field_format) if detail.value
291 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
305 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
292 end
306 end
293 when 'attachment'
307 when 'attachment'
294 label = l(:label_attachment)
308 label = l(:label_attachment)
295 end
309 end
296 call_hook(:helper_issues_show_detail_after_setting,
310 call_hook(:helper_issues_show_detail_after_setting,
297 {:detail => detail, :label => label, :value => value, :old_value => old_value })
311 {:detail => detail, :label => label, :value => value, :old_value => old_value })
298
312
299 label ||= detail.prop_key
313 label ||= detail.prop_key
300 value ||= detail.value
314 value ||= detail.value
301 old_value ||= detail.old_value
315 old_value ||= detail.old_value
302
316
303 unless no_html
317 unless no_html
304 label = content_tag('strong', label)
318 label = content_tag('strong', label)
305 old_value = content_tag("i", h(old_value)) if detail.old_value
319 old_value = content_tag("i", h(old_value)) if detail.old_value
306 old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
320 old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
307 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
321 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
308 # Link to the attachment if it has not been removed
322 # Link to the attachment if it has not been removed
309 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
323 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
310 if options[:only_path] != false && atta.is_text?
324 if options[:only_path] != false && atta.is_text?
311 value += link_to(
325 value += link_to(
312 image_tag('magnifier.png'),
326 image_tag('magnifier.png'),
313 :controller => 'attachments', :action => 'show',
327 :controller => 'attachments', :action => 'show',
314 :id => atta, :filename => atta.filename
328 :id => atta, :filename => atta.filename
315 )
329 )
316 end
330 end
317 else
331 else
318 value = content_tag("i", h(value)) if value
332 value = content_tag("i", h(value)) if value
319 end
333 end
320 end
334 end
321
335
322 if detail.property == 'attr' && detail.prop_key == 'description'
336 if detail.property == 'attr' && detail.prop_key == 'description'
323 s = l(:text_journal_changed_no_detail, :label => label)
337 s = l(:text_journal_changed_no_detail, :label => label)
324 unless no_html
338 unless no_html
325 diff_link = link_to 'diff',
339 diff_link = link_to 'diff',
326 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
340 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
327 :detail_id => detail.id, :only_path => options[:only_path]},
341 :detail_id => detail.id, :only_path => options[:only_path]},
328 :title => l(:label_view_diff)
342 :title => l(:label_view_diff)
329 s << " (#{ diff_link })"
343 s << " (#{ diff_link })"
330 end
344 end
331 s.html_safe
345 s.html_safe
332 elsif detail.value.present?
346 elsif detail.value.present?
333 case detail.property
347 case detail.property
334 when 'attr', 'cf'
348 when 'attr', 'cf'
335 if detail.old_value.present?
349 if detail.old_value.present?
336 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
350 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
337 elsif multiple
351 elsif multiple
338 l(:text_journal_added, :label => label, :value => value).html_safe
352 l(:text_journal_added, :label => label, :value => value).html_safe
339 else
353 else
340 l(:text_journal_set_to, :label => label, :value => value).html_safe
354 l(:text_journal_set_to, :label => label, :value => value).html_safe
341 end
355 end
342 when 'attachment'
356 when 'attachment'
343 l(:text_journal_added, :label => label, :value => value).html_safe
357 l(:text_journal_added, :label => label, :value => value).html_safe
344 end
358 end
345 else
359 else
346 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
360 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
347 end
361 end
348 end
362 end
349
363
350 # Find the name of an associated record stored in the field attribute
364 # Find the name of an associated record stored in the field attribute
351 def find_name_by_reflection(field, id)
365 def find_name_by_reflection(field, id)
352 unless id.present?
366 unless id.present?
353 return nil
367 return nil
354 end
368 end
355 association = Issue.reflect_on_association(field.to_sym)
369 association = Issue.reflect_on_association(field.to_sym)
356 if association
370 if association
357 record = association.class_name.constantize.find_by_id(id)
371 record = association.class_name.constantize.find_by_id(id)
358 if record
372 if record
359 record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding)
373 record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding)
360 return record.name
374 return record.name
361 end
375 end
362 end
376 end
363 end
377 end
364
378
365 # Renders issue children recursively
379 # Renders issue children recursively
366 def render_api_issue_children(issue, api)
380 def render_api_issue_children(issue, api)
367 return if issue.leaf?
381 return if issue.leaf?
368 api.array :children do
382 api.array :children do
369 issue.children.each do |child|
383 issue.children.each do |child|
370 api.issue(:id => child.id) do
384 api.issue(:id => child.id) do
371 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
385 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
372 api.subject child.subject
386 api.subject child.subject
373 render_api_issue_children(child, api)
387 render_api_issue_children(child, api)
374 end
388 end
375 end
389 end
376 end
390 end
377 end
391 end
378 end
392 end
@@ -1,150 +1,166
1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
2
2
3 <% if @saved_issues && @unsaved_issues.present? %>
4 <div id="errorExplanation">
5 <span>
6 <%= l(:notice_failed_to_save_issues,
7 :count => @unsaved_issues.size,
8 :total => @saved_issues.size,
9 :ids => @unsaved_issues.map {|i| "##{i.id}"}.join(', ')) %>
10 </span>
11 <ul>
12 <% bulk_edit_error_messages(@unsaved_issues).each do |message| %>
13 <li><%= message %></li>
14 <% end %>
15 </ul>
16 </div>
17 <% end %>
18
3 <ul id="bulk-selection">
19 <ul id="bulk-selection">
4 <% @issues.each do |issue| %>
20 <% @issues.each do |issue| %>
5 <%= content_tag 'li', link_to_issue(issue) %>
21 <%= content_tag 'li', link_to_issue(issue) %>
6 <% end %>
22 <% end %>
7 </ul>
23 </ul>
8
24
9 <%= form_tag(bulk_update_issues_path, :id => 'bulk_edit_form') do %>
25 <%= form_tag(bulk_update_issues_path, :id => 'bulk_edit_form') do %>
10 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
26 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
11 <div class="box tabular">
27 <div class="box tabular">
12 <fieldset class="attributes">
28 <fieldset class="attributes">
13 <legend><%= l(:label_change_properties) %></legend>
29 <legend><%= l(:label_change_properties) %></legend>
14
30
15 <div class="splitcontentleft">
31 <div class="splitcontentleft">
16 <% if @allowed_projects.present? %>
32 <% if @allowed_projects.present? %>
17 <p>
33 <p>
18 <label for="issue_project_id"><%= l(:field_project) %></label>
34 <label for="issue_project_id"><%= l(:field_project) %></label>
19 <%= select_tag('issue[project_id]', content_tag('option', l(:label_no_change_option), :value => '') + project_tree_options_for_select(@allowed_projects, :selected => @target_project),
35 <%= select_tag('issue[project_id]', content_tag('option', l(:label_no_change_option), :value => '') + project_tree_options_for_select(@allowed_projects, :selected => @target_project),
20 :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
36 :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
21 </p>
37 </p>
22 <% end %>
38 <% end %>
23 <p>
39 <p>
24 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
40 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
25 <%= select_tag('issue[tracker_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@trackers, :id, :name)) %>
41 <%= select_tag('issue[tracker_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@trackers, :id, :name)) %>
26 </p>
42 </p>
27 <% if @available_statuses.any? %>
43 <% if @available_statuses.any? %>
28 <p>
44 <p>
29 <label for='issue_status_id'><%= l(:field_status) %></label>
45 <label for='issue_status_id'><%= l(:field_status) %></label>
30 <%= select_tag('issue[status_id]',content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_statuses, :id, :name)) %>
46 <%= select_tag('issue[status_id]',content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_statuses, :id, :name)) %>
31 </p>
47 </p>
32 <% end %>
48 <% end %>
33
49
34 <% if @safe_attributes.include?('priority_id') -%>
50 <% if @safe_attributes.include?('priority_id') -%>
35 <p>
51 <p>
36 <label for='issue_priority_id'><%= l(:field_priority) %></label>
52 <label for='issue_priority_id'><%= l(:field_priority) %></label>
37 <%= select_tag('issue[priority_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(IssuePriority.active, :id, :name)) %>
53 <%= select_tag('issue[priority_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(IssuePriority.active, :id, :name)) %>
38 </p>
54 </p>
39 <% end %>
55 <% end %>
40
56
41 <% if @safe_attributes.include?('assigned_to_id') -%>
57 <% if @safe_attributes.include?('assigned_to_id') -%>
42 <p>
58 <p>
43 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
59 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
44 <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
60 <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
45 content_tag('option', l(:label_nobody), :value => 'none') +
61 content_tag('option', l(:label_nobody), :value => 'none') +
46 principals_options_for_select(@assignables)) %>
62 principals_options_for_select(@assignables)) %>
47 </p>
63 </p>
48 <% end %>
64 <% end %>
49
65
50 <% if @safe_attributes.include?('category_id') -%>
66 <% if @safe_attributes.include?('category_id') -%>
51 <p>
67 <p>
52 <label for='issue_category_id'><%= l(:field_category) %></label>
68 <label for='issue_category_id'><%= l(:field_category) %></label>
53 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
69 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
54 content_tag('option', l(:label_none), :value => 'none') +
70 content_tag('option', l(:label_none), :value => 'none') +
55 options_from_collection_for_select(@categories, :id, :name)) %>
71 options_from_collection_for_select(@categories, :id, :name)) %>
56 </p>
72 </p>
57 <% end %>
73 <% end %>
58
74
59 <% if @safe_attributes.include?('fixed_version_id') -%>
75 <% if @safe_attributes.include?('fixed_version_id') -%>
60 <p>
76 <p>
61 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
77 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
62 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
78 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
63 content_tag('option', l(:label_none), :value => 'none') +
79 content_tag('option', l(:label_none), :value => 'none') +
64 version_options_for_select(@versions.sort)) %>
80 version_options_for_select(@versions.sort)) %>
65 </p>
81 </p>
66 <% end %>
82 <% end %>
67
83
68 <% @custom_fields.each do |custom_field| %>
84 <% @custom_fields.each do |custom_field| %>
69 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
85 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
70 <% end %>
86 <% end %>
71
87
72 <% if @copy && @attachments_present %>
88 <% if @copy && @attachments_present %>
73 <p>
89 <p>
74 <label for='copy_attachments'><%= l(:label_copy_attachments) %></label>
90 <label for='copy_attachments'><%= l(:label_copy_attachments) %></label>
75 <%= check_box_tag 'copy_attachments', '1', true %>
91 <%= check_box_tag 'copy_attachments', '1', true %>
76 </p>
92 </p>
77 <% end %>
93 <% end %>
78
94
79 <% if @copy && @subtasks_present %>
95 <% if @copy && @subtasks_present %>
80 <p>
96 <p>
81 <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
97 <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
82 <%= check_box_tag 'copy_subtasks', '1', true %>
98 <%= check_box_tag 'copy_subtasks', '1', true %>
83 </p>
99 </p>
84 <% end %>
100 <% end %>
85
101
86 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
102 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
87 </div>
103 </div>
88
104
89 <div class="splitcontentright">
105 <div class="splitcontentright">
90 <% if @safe_attributes.include?('is_private') %>
106 <% if @safe_attributes.include?('is_private') %>
91 <p>
107 <p>
92 <label for='issue_is_private'><%= l(:field_is_private) %></label>
108 <label for='issue_is_private'><%= l(:field_is_private) %></label>
93 <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') +
109 <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') +
94 content_tag('option', l(:general_text_Yes), :value => '1') +
110 content_tag('option', l(:general_text_Yes), :value => '1') +
95 content_tag('option', l(:general_text_No), :value => '0')) %>
111 content_tag('option', l(:general_text_No), :value => '0')) %>
96 </p>
112 </p>
97 <% end %>
113 <% end %>
98
114
99 <% if @safe_attributes.include?('parent_issue_id') && @project %>
115 <% if @safe_attributes.include?('parent_issue_id') && @project %>
100 <p>
116 <p>
101 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
117 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
102 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %>
118 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %>
103 </p>
119 </p>
104 <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project)}')" %>
120 <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project)}')" %>
105 <% end %>
121 <% end %>
106
122
107 <% if @safe_attributes.include?('start_date') %>
123 <% if @safe_attributes.include?('start_date') %>
108 <p>
124 <p>
109 <label for='issue_start_date'><%= l(:field_start_date) %></label>
125 <label for='issue_start_date'><%= l(:field_start_date) %></label>
110 <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
126 <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
111 </p>
127 </p>
112 <% end %>
128 <% end %>
113
129
114 <% if @safe_attributes.include?('due_date') %>
130 <% if @safe_attributes.include?('due_date') %>
115 <p>
131 <p>
116 <label for='issue_due_date'><%= l(:field_due_date) %></label>
132 <label for='issue_due_date'><%= l(:field_due_date) %></label>
117 <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
133 <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
118 </p>
134 </p>
119 <% end %>
135 <% end %>
120
136
121 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
137 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
122 <p>
138 <p>
123 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
139 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
124 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
140 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
125 </p>
141 </p>
126 <% end %>
142 <% end %>
127 </div>
143 </div>
128 </fieldset>
144 </fieldset>
129
145
130 <fieldset>
146 <fieldset>
131 <legend><%= l(:field_notes) %></legend>
147 <legend><%= l(:field_notes) %></legend>
132 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
148 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
133 <%= wikitoolbar_for 'notes' %>
149 <%= wikitoolbar_for 'notes' %>
134 </fieldset>
150 </fieldset>
135 </div>
151 </div>
136
152
137 <p>
153 <p>
138 <% if @copy %>
154 <% if @copy %>
139 <%= hidden_field_tag 'copy', '1' %>
155 <%= hidden_field_tag 'copy', '1' %>
140 <%= submit_tag l(:button_copy) %>
156 <%= submit_tag l(:button_copy) %>
141 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
157 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
142 <% elsif @target_project %>
158 <% elsif @target_project %>
143 <%= submit_tag l(:button_move) %>
159 <%= submit_tag l(:button_move) %>
144 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
160 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
145 <% else %>
161 <% else %>
146 <%= submit_tag l(:button_submit) %>
162 <%= submit_tag l(:button_submit) %>
147 <% end %>
163 <% end %>
148 </p>
164 </p>
149
165
150 <% end %>
166 <% end %>
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now