OSDN Git Service

added svn:eol-style native property on /app files
[redminele/redmine.git] / app / controllers / issues_controller.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2007  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
18 class IssuesController < ApplicationController
19   layout 'base', :except => :export_pdf
20   before_filter :find_project, :authorize
21
22   helper :custom_fields
23   include CustomFieldsHelper
24   helper :ifpdf
25   include IfpdfHelper
26
27   def show
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")
32   end
33   
34   def history
35     @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "journals.created_on desc")
36     @journals_count = @journals.length  
37   end
38   
39   def export_pdf
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"
43   end
44
45   def edit
46     @priorities = Enumeration::get_values('IPRI')
47     if request.get?
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) }
49     else
50       begin
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]
56         if @issue.save
57           flash[:notice] = l(:notice_successful_update)
58           redirect_to :action => 'show', :id => @issue
59         end
60       rescue ActiveRecord::StaleObjectError
61         # Optimistic locking exception
62         flash[:notice] = l(:notice_locking_conflict)
63       end
64     end         
65   end
66   
67   def add_note
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
73       if @issue.save
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
77         return
78       end
79     end
80     show
81     render :action => 'show'
82   end
83
84   def change_status
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])
88     if params[:confirm]
89       begin
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
102         end
103       rescue ActiveRecord::StaleObjectError
104         # Optimistic locking exception
105         flash[:notice] = l(:notice_locking_conflict)
106       end
107     end    
108     @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
109   end
110
111   def destroy
112     @issue.destroy
113     redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
114   end
115
116   def add_attachment
117     # Save the attachments
118     @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
126   end
127
128   def destroy_attachment
129     @issue.attachments.find(params[:attachment_id]).destroy
130     redirect_to :action => 'show', :id => @issue
131   end
132
133   # Send the file in stream mode
134   def download
135     @attachment = @issue.attachments.find(params[:attachment_id])
136     send_file @attachment.diskfile, :filename => @attachment.filename
137   rescue
138     render_404
139   end
140
141 private
142   def find_project
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
147     render_404
148   end  
149 end