annotate .svn/pristine/4d/4d604786de278b5fda48f4134b1c01b3378cf99a.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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