annotate .svn/pristine/ac/ac2df139756a1b383082a659ee11216bfec62b21.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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