1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
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.
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.
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.
18 class IssuesController < ApplicationController
19 layout 'base', :except => :export_pdf
20 before_filter :find_project, :authorize
23 include CustomFieldsHelper
28 @status_options = @issue.status.workflows.find(:all, :order => 'position', :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
29 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
30 @journals_count = @issue.journals.count
31 @journals = @issue.journals.find(:all, :include => [:user, :details], :limit => 15, :order => "journals.created_on desc")
35 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "journals.created_on desc")
36 @journals_count = @journals.length
40 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
41 @options_for_rfpdf ||= {}
42 @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.long_id}.pdf"
46 @priorities = Enumeration::get_values('IPRI')
48 @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) }
51 @issue.init_journal(self.logged_in_user)
52 # Retrieve custom fields and values
53 @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]) }
54 @issue.custom_values = @custom_values
55 @issue.attributes = params[:issue]
57 flash[:notice] = l(:notice_successful_update)
58 redirect_to :action => 'show', :id => @issue
60 rescue ActiveRecord::StaleObjectError
61 # Optimistic locking exception
62 flash[:notice] = l(:notice_locking_conflict)
68 unless params[:notes].empty?
69 journal = @issue.init_journal(self.logged_in_user, params[:notes])
70 #@history = @issue.histories.build(params[:history])
71 #@history.author_id = self.logged_in_user.id if self.logged_in_user
72 #@history.status = @issue.status
74 flash[:notice] = l(:notice_successful_update)
75 Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
76 redirect_to :action => 'show', :id => @issue
81 render :action => 'show'
85 #@history = @issue.histories.build(params[:history])
86 @status_options = @issue.status.workflows.find(:all, :order => 'position', :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
87 @new_status = IssueStatus.find(params[:new_status_id])
90 #@history.author_id = self.logged_in_user.id if self.logged_in_user
91 #@issue.status = @history.status
92 #@issue.fixed_version_id = (params[:issue][:fixed_version_id])
93 #@issue.assigned_to_id = (params[:issue][:assigned_to_id])
94 #@issue.done_ratio = (params[:issue][:done_ratio])
95 #@issue.lock_version = (params[:issue][:lock_version])
96 journal = @issue.init_journal(self.logged_in_user, params[:notes])
97 @issue.status = @new_status
98 if @issue.update_attributes(params[:issue])
99 flash[:notice] = l(:notice_successful_update)
100 Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
101 redirect_to :action => 'show', :id => @issue
103 rescue ActiveRecord::StaleObjectError
104 # Optimistic locking exception
105 flash[:notice] = l(:notice_locking_conflict)
108 @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
113 redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
117 # Save the attachments
119 params[:attachments].each { |file|
120 next unless file.size > 0
121 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
122 @attachments << a unless a.new_record?
123 } if params[:attachments] and params[:attachments].is_a? Array
124 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
125 redirect_to :action => 'show', :id => @issue
128 def destroy_attachment
129 @issue.attachments.find(params[:attachment_id]).destroy
130 redirect_to :action => 'show', :id => @issue
133 # Send the file in stream mode
135 @attachment = @issue.attachments.find(params[:attachment_id])
136 send_file @attachment.diskfile, :filename => @attachment.filename
143 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
144 @project = @issue.project
145 @html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
146 rescue ActiveRecord::RecordNotFound