You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issues_controller.rb 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # redMine - project management software
  2. # Copyright (C) 2006 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class IssuesController < ApplicationController
  18. layout 'base', :except => :export_pdf
  19. before_filter :find_project, :authorize
  20. helper :custom_fields
  21. include CustomFieldsHelper
  22. helper :ifpdf
  23. include IfpdfHelper
  24. def show
  25. @status_options = @issue.status.workflows.find(:all, :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user
  26. @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
  27. @journals_count = @issue.journals.count
  28. @journals = @issue.journals.find(:all, :include => [:user, :details], :limit => 15, :order => "journals.created_on desc")
  29. end
  30. def history
  31. @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "journals.created_on desc")
  32. @journals_count = @journals.length
  33. end
  34. def export_pdf
  35. @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
  36. @options_for_rfpdf ||= {}
  37. @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.long_id}.pdf"
  38. end
  39. def edit
  40. @priorities = Enumeration::get_values('IPRI')
  41. if request.get?
  42. @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }
  43. else
  44. begin
  45. @issue.init_journal(self.logged_in_user)
  46. # Retrieve custom fields and values
  47. @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
  48. @issue.custom_values = @custom_values
  49. @issue.attributes = params[:issue]
  50. if @issue.save
  51. flash[:notice] = l(:notice_successful_update)
  52. redirect_to :action => 'show', :id => @issue
  53. end
  54. rescue ActiveRecord::StaleObjectError
  55. # Optimistic locking exception
  56. flash[:notice] = l(:notice_locking_conflict)
  57. end
  58. end
  59. end
  60. def add_note
  61. unless params[:notes].empty?
  62. journal = @issue.init_journal(self.logged_in_user, params[:notes])
  63. #@history = @issue.histories.build(params[:history])
  64. #@history.author_id = self.logged_in_user.id if self.logged_in_user
  65. #@history.status = @issue.status
  66. if @issue.save
  67. flash[:notice] = l(:notice_successful_update)
  68. Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?
  69. redirect_to :action => 'show', :id => @issue
  70. return
  71. end
  72. end
  73. show
  74. render :action => 'show'
  75. end
  76. def change_status
  77. #@history = @issue.histories.build(params[:history])
  78. @status_options = @issue.status.workflows.find(:all, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user
  79. @new_status = IssueStatus.find(params[:new_status_id])
  80. if params[:confirm]
  81. begin
  82. #@history.author_id = self.logged_in_user.id if self.logged_in_user
  83. #@issue.status = @history.status
  84. #@issue.fixed_version_id = (params[:issue][:fixed_version_id])
  85. #@issue.assigned_to_id = (params[:issue][:assigned_to_id])
  86. #@issue.done_ratio = (params[:issue][:done_ratio])
  87. #@issue.lock_version = (params[:issue][:lock_version])
  88. journal = @issue.init_journal(self.logged_in_user, params[:notes])
  89. @issue.status = @new_status
  90. if @issue.update_attributes(params[:issue])
  91. flash[:notice] = l(:notice_successful_update)
  92. Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?
  93. redirect_to :action => 'show', :id => @issue
  94. end
  95. rescue ActiveRecord::StaleObjectError
  96. # Optimistic locking exception
  97. flash[:notice] = l(:notice_locking_conflict)
  98. end
  99. end
  100. @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
  101. end
  102. def destroy
  103. @issue.destroy
  104. redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
  105. end
  106. def add_attachment
  107. # Save the attachments
  108. params[:attachments].each { |a|
  109. @attachment = @issue.attachments.build(:file => a, :author => self.logged_in_user) unless a.size == 0
  110. @attachment.save
  111. } if params[:attachments] and params[:attachments].is_a? Array
  112. redirect_to :action => 'show', :id => @issue
  113. end
  114. def destroy_attachment
  115. @issue.attachments.find(params[:attachment_id]).destroy
  116. redirect_to :action => 'show', :id => @issue
  117. end
  118. # Send the file in stream mode
  119. def download
  120. @attachment = @issue.attachments.find(params[:attachment_id])
  121. send_file @attachment.diskfile, :filename => @attachment.filename
  122. rescue
  123. flash.now[:notice] = l(:notice_file_not_found)
  124. render :text => "", :layout => true, :status => 404
  125. end
  126. private
  127. def find_project
  128. @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
  129. @project = @issue.project
  130. @html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
  131. end
  132. end