##// END OF EJS Templates
Adds a title to the issue link in the flash message....
Jean-Philippe Lang -
r10015:91c875437d5d
parent child
Show More

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

@@ -1,426 +1,426
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssuesController < ApplicationController
19 19 menu_item :new_issue, :only => [:new, :create]
20 20 default_search_scope :issues
21 21
22 22 before_filter :find_issue, :only => [:show, :edit, :update]
23 23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
24 24 before_filter :find_project, :only => [:new, :create]
25 25 before_filter :authorize, :except => [:index]
26 26 before_filter :find_optional_project, :only => [:index]
27 27 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 28 before_filter :build_new_issue_from_params, :only => [:new, :create]
29 29 accept_rss_auth :index, :show
30 30 accept_api_auth :index, :show, :create, :update, :destroy
31 31
32 32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33 33
34 34 helper :journals
35 35 helper :projects
36 36 include ProjectsHelper
37 37 helper :custom_fields
38 38 include CustomFieldsHelper
39 39 helper :issue_relations
40 40 include IssueRelationsHelper
41 41 helper :watchers
42 42 include WatchersHelper
43 43 helper :attachments
44 44 include AttachmentsHelper
45 45 helper :queries
46 46 include QueriesHelper
47 47 helper :repositories
48 48 include RepositoriesHelper
49 49 helper :sort
50 50 include SortHelper
51 51 include IssuesHelper
52 52 helper :timelog
53 53 include Redmine::Export::PDF
54 54
55 55 def index
56 56 retrieve_query
57 57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
58 58 sort_update(@query.sortable_columns)
59 59
60 60 if @query.valid?
61 61 case params[:format]
62 62 when 'csv', 'pdf'
63 63 @limit = Setting.issues_export_limit.to_i
64 64 when 'atom'
65 65 @limit = Setting.feeds_limit.to_i
66 66 when 'xml', 'json'
67 67 @offset, @limit = api_offset_and_limit
68 68 else
69 69 @limit = per_page_option
70 70 end
71 71
72 72 @issue_count = @query.issue_count
73 73 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
74 74 @offset ||= @issue_pages.current.offset
75 75 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
76 76 :order => sort_clause,
77 77 :offset => @offset,
78 78 :limit => @limit)
79 79 @issue_count_by_group = @query.issue_count_by_group
80 80
81 81 respond_to do |format|
82 82 format.html { render :template => 'issues/index', :layout => !request.xhr? }
83 83 format.api {
84 84 Issue.load_relations(@issues) if include_in_api_response?('relations')
85 85 }
86 86 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
87 87 format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') }
88 88 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
89 89 end
90 90 else
91 91 respond_to do |format|
92 92 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
93 93 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
94 94 format.api { render_validation_errors(@query) }
95 95 end
96 96 end
97 97 rescue ActiveRecord::RecordNotFound
98 98 render_404
99 99 end
100 100
101 101 def show
102 102 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
103 103 @journals.each_with_index {|j,i| j.indice = i+1}
104 104 @journals.reverse! if User.current.wants_comments_in_reverse_order?
105 105
106 106 @changesets = @issue.changesets.visible.all
107 107 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
108 108
109 109 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
110 110 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
111 111 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
112 112 @priorities = IssuePriority.active
113 113 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
114 114 respond_to do |format|
115 115 format.html {
116 116 retrieve_previous_and_next_issue_ids
117 117 render :template => 'issues/show'
118 118 }
119 119 format.api
120 120 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
121 121 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
122 122 end
123 123 end
124 124
125 125 # Add a new issue
126 126 # The new issue will be created from an existing one if copy_from parameter is given
127 127 def new
128 128 respond_to do |format|
129 129 format.html { render :action => 'new', :layout => !request.xhr? }
130 130 format.js { render :partial => 'update_form' }
131 131 end
132 132 end
133 133
134 134 def create
135 135 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
136 136 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
137 137 if @issue.save
138 138 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
139 139 respond_to do |format|
140 140 format.html {
141 141 render_attachment_warning_if_needed(@issue)
142 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue)))
142 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
143 143 redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
144 144 { :action => 'show', :id => @issue })
145 145 }
146 146 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
147 147 end
148 148 return
149 149 else
150 150 respond_to do |format|
151 151 format.html { render :action => 'new' }
152 152 format.api { render_validation_errors(@issue) }
153 153 end
154 154 end
155 155 end
156 156
157 157 def edit
158 158 return unless update_issue_from_params
159 159
160 160 respond_to do |format|
161 161 format.html { }
162 162 format.xml { }
163 163 end
164 164 end
165 165
166 166 def update
167 167 return unless update_issue_from_params
168 168 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
169 169 saved = false
170 170 begin
171 171 saved = @issue.save_issue_with_child_records(params, @time_entry)
172 172 rescue ActiveRecord::StaleObjectError
173 173 @conflict = true
174 174 if params[:last_journal_id]
175 175 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
176 176 end
177 177 end
178 178
179 179 if saved
180 180 render_attachment_warning_if_needed(@issue)
181 181 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
182 182
183 183 respond_to do |format|
184 184 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
185 185 format.api { render_api_ok }
186 186 end
187 187 else
188 188 respond_to do |format|
189 189 format.html { render :action => 'edit' }
190 190 format.api { render_validation_errors(@issue) }
191 191 end
192 192 end
193 193 end
194 194
195 195 # Bulk edit/copy a set of issues
196 196 def bulk_edit
197 197 @issues.sort!
198 198 @copy = params[:copy].present?
199 199 @notes = params[:notes]
200 200
201 201 if User.current.allowed_to?(:move_issues, @projects)
202 202 @allowed_projects = Issue.allowed_target_projects_on_move
203 203 if params[:issue]
204 204 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
205 205 if @target_project
206 206 target_projects = [@target_project]
207 207 end
208 208 end
209 209 end
210 210 target_projects ||= @projects
211 211
212 212 if @copy
213 213 @available_statuses = [IssueStatus.default]
214 214 else
215 215 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
216 216 end
217 217 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
218 218 @assignables = target_projects.map(&:assignable_users).reduce(:&)
219 219 @trackers = target_projects.map(&:trackers).reduce(:&)
220 220 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
221 221 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
222 222 if @copy
223 223 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
224 224 end
225 225
226 226 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
227 227 render :layout => false if request.xhr?
228 228 end
229 229
230 230 def bulk_update
231 231 @issues.sort!
232 232 @copy = params[:copy].present?
233 233 attributes = parse_params_for_bulk_issue_attributes(params)
234 234
235 235 unsaved_issue_ids = []
236 236 moved_issues = []
237 237 @issues.each do |issue|
238 238 issue.reload
239 239 if @copy
240 240 issue = issue.copy({}, :attachments => params[:copy_attachments].present?)
241 241 end
242 242 journal = issue.init_journal(User.current, params[:notes])
243 243 issue.safe_attributes = attributes
244 244 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
245 245 if issue.save
246 246 moved_issues << issue
247 247 else
248 248 # Keep unsaved issue ids to display them in flash error
249 249 unsaved_issue_ids << issue.id
250 250 end
251 251 end
252 252 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
253 253
254 254 if params[:follow]
255 255 if @issues.size == 1 && moved_issues.size == 1
256 256 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
257 257 elsif moved_issues.map(&:project).uniq.size == 1
258 258 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
259 259 end
260 260 else
261 261 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
262 262 end
263 263 end
264 264
265 265 def destroy
266 266 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
267 267 if @hours > 0
268 268 case params[:todo]
269 269 when 'destroy'
270 270 # nothing to do
271 271 when 'nullify'
272 272 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
273 273 when 'reassign'
274 274 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
275 275 if reassign_to.nil?
276 276 flash.now[:error] = l(:error_issue_not_found_in_project)
277 277 return
278 278 else
279 279 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
280 280 end
281 281 else
282 282 # display the destroy form if it's a user request
283 283 return unless api_request?
284 284 end
285 285 end
286 286 @issues.each do |issue|
287 287 begin
288 288 issue.reload.destroy
289 289 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
290 290 # nothing to do, issue was already deleted (eg. by a parent)
291 291 end
292 292 end
293 293 respond_to do |format|
294 294 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
295 295 format.api { render_api_ok }
296 296 end
297 297 end
298 298
299 299 private
300 300 def find_issue
301 301 # Issue.visible.find(...) can not be used to redirect user to the login form
302 302 # if the issue actually exists but requires authentication
303 303 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
304 304 unless @issue.visible?
305 305 deny_access
306 306 return
307 307 end
308 308 @project = @issue.project
309 309 rescue ActiveRecord::RecordNotFound
310 310 render_404
311 311 end
312 312
313 313 def find_project
314 314 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
315 315 @project = Project.find(project_id)
316 316 rescue ActiveRecord::RecordNotFound
317 317 render_404
318 318 end
319 319
320 320 def retrieve_previous_and_next_issue_ids
321 321 retrieve_query_from_session
322 322 if @query
323 323 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
324 324 sort_update(@query.sortable_columns, 'issues_index_sort')
325 325 limit = 500
326 326 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
327 327 if (idx = issue_ids.index(@issue.id)) && idx < limit
328 328 if issue_ids.size < 500
329 329 @issue_position = idx + 1
330 330 @issue_count = issue_ids.size
331 331 end
332 332 @prev_issue_id = issue_ids[idx - 1] if idx > 0
333 333 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
334 334 end
335 335 end
336 336 end
337 337
338 338 # Used by #edit and #update to set some common instance variables
339 339 # from the params
340 340 # TODO: Refactor, not everything in here is needed by #edit
341 341 def update_issue_from_params
342 342 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
343 343 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
344 344 @time_entry.attributes = params[:time_entry]
345 345
346 346 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
347 347 @issue.init_journal(User.current, @notes)
348 348
349 349 issue_attributes = params[:issue]
350 350 if issue_attributes && params[:conflict_resolution]
351 351 case params[:conflict_resolution]
352 352 when 'overwrite'
353 353 issue_attributes = issue_attributes.dup
354 354 issue_attributes.delete(:lock_version)
355 355 when 'add_notes'
356 356 issue_attributes = {}
357 357 when 'cancel'
358 358 redirect_to issue_path(@issue)
359 359 return false
360 360 end
361 361 end
362 362 @issue.safe_attributes = issue_attributes
363 363 @priorities = IssuePriority.active
364 364 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
365 365 true
366 366 end
367 367
368 368 # TODO: Refactor, lots of extra code in here
369 369 # TODO: Changing tracker on an existing issue should not trigger this
370 370 def build_new_issue_from_params
371 371 if params[:id].blank?
372 372 @issue = Issue.new
373 373 if params[:copy_from]
374 374 begin
375 375 @copy_from = Issue.visible.find(params[:copy_from])
376 376 @copy_attachments = params[:copy_attachments].present? || request.get?
377 377 @issue.copy_from(@copy_from, :attachments => @copy_attachments)
378 378 rescue ActiveRecord::RecordNotFound
379 379 render_404
380 380 return
381 381 end
382 382 end
383 383 @issue.project = @project
384 384 else
385 385 @issue = @project.issues.visible.find(params[:id])
386 386 end
387 387
388 388 @issue.project = @project
389 389 @issue.author = User.current
390 390 # Tracker must be set before custom field values
391 391 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
392 392 if @issue.tracker.nil?
393 393 render_error l(:error_no_tracker_in_project)
394 394 return false
395 395 end
396 396 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
397 397 @issue.safe_attributes = params[:issue]
398 398
399 399 @priorities = IssuePriority.active
400 400 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
401 401 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
402 402 end
403 403
404 404 def check_for_default_issue_status
405 405 if IssueStatus.default.nil?
406 406 render_error l(:error_no_default_issue_status)
407 407 return false
408 408 end
409 409 end
410 410
411 411 def parse_params_for_bulk_issue_attributes(params)
412 412 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
413 413 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
414 414 if custom = attributes[:custom_field_values]
415 415 custom.reject! {|k,v| v.blank?}
416 416 custom.keys.each do |k|
417 417 if custom[k].is_a?(Array)
418 418 custom[k] << '' if custom[k].delete('__none__')
419 419 else
420 420 custom[k] = '' if custom[k] == '__none__'
421 421 end
422 422 end
423 423 end
424 424 attributes
425 425 end
426 426 end
1 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