annotate app/controllers/issues_controller.rb @ 1613:90bed4e10cc8 deploy

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