@@ -1,428 +1,428 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class IssuesController < ApplicationController |
|
18 | class IssuesController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | menu_item :new_issue, :only => :new |
|
20 | menu_item :new_issue, :only => :new | |
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment] | |
23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] |
|
23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] | |
24 | before_filter :find_project, :only => [:new, :update_form, :preview] |
|
24 | before_filter :find_project, :only => [:new, :update_form, :preview] | |
25 | before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu] |
|
25 | before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu] | |
26 | before_filter :find_optional_project, :only => [:index, :changes] |
|
26 | before_filter :find_optional_project, :only => [:index, :changes] | |
27 | accept_key_auth :index, :changes |
|
27 | accept_key_auth :index, :changes | |
28 |
|
28 | |||
29 | helper :journals |
|
29 | helper :journals | |
30 | helper :projects |
|
30 | helper :projects | |
31 | include ProjectsHelper |
|
31 | include ProjectsHelper | |
32 | helper :custom_fields |
|
32 | helper :custom_fields | |
33 | include CustomFieldsHelper |
|
33 | include CustomFieldsHelper | |
34 | helper :ifpdf |
|
34 | helper :ifpdf | |
35 | include IfpdfHelper |
|
35 | include IfpdfHelper | |
36 | helper :issue_relations |
|
36 | helper :issue_relations | |
37 | include IssueRelationsHelper |
|
37 | include IssueRelationsHelper | |
38 | helper :watchers |
|
38 | helper :watchers | |
39 | include WatchersHelper |
|
39 | include WatchersHelper | |
40 | helper :attachments |
|
40 | helper :attachments | |
41 | include AttachmentsHelper |
|
41 | include AttachmentsHelper | |
42 | helper :queries |
|
42 | helper :queries | |
43 | helper :sort |
|
43 | helper :sort | |
44 | include SortHelper |
|
44 | include SortHelper | |
45 | include IssuesHelper |
|
45 | include IssuesHelper | |
46 | helper :timelog |
|
46 | helper :timelog | |
47 |
|
47 | |||
48 | def index |
|
48 | def index | |
49 | sort_init "#{Issue.table_name}.id", "desc" |
|
49 | sort_init "#{Issue.table_name}.id", "desc" | |
50 | sort_update |
|
50 | sort_update | |
51 | retrieve_query |
|
51 | retrieve_query | |
52 | if @query.valid? |
|
52 | if @query.valid? | |
53 | limit = per_page_option |
|
53 | limit = per_page_option | |
54 | respond_to do |format| |
|
54 | respond_to do |format| | |
55 | format.html { } |
|
55 | format.html { } | |
56 | format.atom { } |
|
56 | format.atom { } | |
57 | format.csv { limit = Setting.issues_export_limit.to_i } |
|
57 | format.csv { limit = Setting.issues_export_limit.to_i } | |
58 | format.pdf { limit = Setting.issues_export_limit.to_i } |
|
58 | format.pdf { limit = Setting.issues_export_limit.to_i } | |
59 | end |
|
59 | end | |
60 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
60 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
61 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
61 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
62 | @issues = Issue.find :all, :order => sort_clause, |
|
62 | @issues = Issue.find :all, :order => sort_clause, | |
63 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ], |
|
63 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ], | |
64 | :conditions => @query.statement, |
|
64 | :conditions => @query.statement, | |
65 | :limit => limit, |
|
65 | :limit => limit, | |
66 | :offset => @issue_pages.current.offset |
|
66 | :offset => @issue_pages.current.offset | |
67 | respond_to do |format| |
|
67 | respond_to do |format| | |
68 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
68 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
69 | format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } |
|
69 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
70 | format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
70 | format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } | |
71 | format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } |
|
71 | format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } | |
72 | end |
|
72 | end | |
73 | else |
|
73 | else | |
74 | # Send html if the query is not valid |
|
74 | # Send html if the query is not valid | |
75 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
75 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
76 | end |
|
76 | end | |
77 | rescue ActiveRecord::RecordNotFound |
|
77 | rescue ActiveRecord::RecordNotFound | |
78 | render_404 |
|
78 | render_404 | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def changes |
|
81 | def changes | |
82 | sort_init "#{Issue.table_name}.id", "desc" |
|
82 | sort_init "#{Issue.table_name}.id", "desc" | |
83 | sort_update |
|
83 | sort_update | |
84 | retrieve_query |
|
84 | retrieve_query | |
85 | if @query.valid? |
|
85 | if @query.valid? | |
86 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], |
|
86 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], | |
87 | :conditions => @query.statement, |
|
87 | :conditions => @query.statement, | |
88 | :limit => 25, |
|
88 | :limit => 25, | |
89 | :order => "#{Journal.table_name}.created_on DESC" |
|
89 | :order => "#{Journal.table_name}.created_on DESC" | |
90 | end |
|
90 | end | |
91 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
91 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
92 | render :layout => false, :content_type => 'application/atom+xml' |
|
92 | render :layout => false, :content_type => 'application/atom+xml' | |
93 | rescue ActiveRecord::RecordNotFound |
|
93 | rescue ActiveRecord::RecordNotFound | |
94 | render_404 |
|
94 | render_404 | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def show |
|
97 | def show | |
98 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
98 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
99 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
99 | @journals.each_with_index {|j,i| j.indice = i+1} | |
100 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
100 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
101 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
101 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
102 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
102 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
103 | @priorities = Enumeration::get_values('IPRI') |
|
103 | @priorities = Enumeration::get_values('IPRI') | |
104 | @time_entry = TimeEntry.new |
|
104 | @time_entry = TimeEntry.new | |
105 | respond_to do |format| |
|
105 | respond_to do |format| | |
106 | format.html { render :template => 'issues/show.rhtml' } |
|
106 | format.html { render :template => 'issues/show.rhtml' } | |
107 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } |
|
107 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } | |
108 | format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
108 | format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
109 | end |
|
109 | end | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | # Add a new issue |
|
112 | # Add a new issue | |
113 | # The new issue will be created from an existing one if copy_from parameter is given |
|
113 | # The new issue will be created from an existing one if copy_from parameter is given | |
114 | def new |
|
114 | def new | |
115 | @issue = Issue.new |
|
115 | @issue = Issue.new | |
116 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
116 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
117 | @issue.project = @project |
|
117 | @issue.project = @project | |
118 | # Tracker must be set before custom field values |
|
118 | # Tracker must be set before custom field values | |
119 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
119 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
120 | if @issue.tracker.nil? |
|
120 | if @issue.tracker.nil? | |
121 | flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.' |
|
121 | flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.' | |
122 | render :nothing => true, :layout => true |
|
122 | render :nothing => true, :layout => true | |
123 | return |
|
123 | return | |
124 | end |
|
124 | end | |
125 | @issue.attributes = params[:issue] |
|
125 | @issue.attributes = params[:issue] | |
126 | @issue.author = User.current |
|
126 | @issue.author = User.current | |
127 |
|
127 | |||
128 | default_status = IssueStatus.default |
|
128 | default_status = IssueStatus.default | |
129 | unless default_status |
|
129 | unless default_status | |
130 | flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' |
|
130 | flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' | |
131 | render :nothing => true, :layout => true |
|
131 | render :nothing => true, :layout => true | |
132 | return |
|
132 | return | |
133 | end |
|
133 | end | |
134 | @issue.status = default_status |
|
134 | @issue.status = default_status | |
135 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq |
|
135 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq | |
136 |
|
136 | |||
137 | if request.get? || request.xhr? |
|
137 | if request.get? || request.xhr? | |
138 | @issue.start_date ||= Date.today |
|
138 | @issue.start_date ||= Date.today | |
139 | else |
|
139 | else | |
140 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
140 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
141 | # Check that the user is allowed to apply the requested status |
|
141 | # Check that the user is allowed to apply the requested status | |
142 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
142 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
143 | if @issue.save |
|
143 | if @issue.save | |
144 | attach_files(@issue, params[:attachments]) |
|
144 | attach_files(@issue, params[:attachments]) | |
145 | flash[:notice] = l(:notice_successful_create) |
|
145 | flash[:notice] = l(:notice_successful_create) | |
146 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') |
|
146 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') | |
147 | redirect_to :controller => 'issues', :action => 'show', :id => @issue |
|
147 | redirect_to :controller => 'issues', :action => 'show', :id => @issue | |
148 | return |
|
148 | return | |
149 | end |
|
149 | end | |
150 | end |
|
150 | end | |
151 | @priorities = Enumeration::get_values('IPRI') |
|
151 | @priorities = Enumeration::get_values('IPRI') | |
152 | render :layout => !request.xhr? |
|
152 | render :layout => !request.xhr? | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
155 | # Attributes that can be updated on workflow transition (without :edit permission) | |
156 | # TODO: make it configurable (at least per role) |
|
156 | # TODO: make it configurable (at least per role) | |
157 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
157 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) | |
158 |
|
158 | |||
159 | def edit |
|
159 | def edit | |
160 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
160 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
161 | @priorities = Enumeration::get_values('IPRI') |
|
161 | @priorities = Enumeration::get_values('IPRI') | |
162 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
162 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
163 |
|
163 | |||
164 | @notes = params[:notes] |
|
164 | @notes = params[:notes] | |
165 | journal = @issue.init_journal(User.current, @notes) |
|
165 | journal = @issue.init_journal(User.current, @notes) | |
166 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
166 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |
167 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
167 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |
168 | attrs = params[:issue].dup |
|
168 | attrs = params[:issue].dup | |
169 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
169 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |
170 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
170 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |
171 | @issue.attributes = attrs |
|
171 | @issue.attributes = attrs | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | if request.post? |
|
174 | if request.post? | |
175 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
175 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) | |
176 | @time_entry.attributes = params[:time_entry] |
|
176 | @time_entry.attributes = params[:time_entry] | |
177 | attachments = attach_files(@issue, params[:attachments]) |
|
177 | attachments = attach_files(@issue, params[:attachments]) | |
178 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
178 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
179 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save |
|
179 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save | |
180 | # Log spend time |
|
180 | # Log spend time | |
181 | if current_role.allowed_to?(:log_time) |
|
181 | if current_role.allowed_to?(:log_time) | |
182 | @time_entry.save |
|
182 | @time_entry.save | |
183 | end |
|
183 | end | |
184 | if !journal.new_record? |
|
184 | if !journal.new_record? | |
185 | # Only send notification if something was actually changed |
|
185 | # Only send notification if something was actually changed | |
186 | flash[:notice] = l(:notice_successful_update) |
|
186 | flash[:notice] = l(:notice_successful_update) | |
187 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
|
187 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
188 | end |
|
188 | end | |
189 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) |
|
189 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) | |
190 | end |
|
190 | end | |
191 | end |
|
191 | end | |
192 | rescue ActiveRecord::StaleObjectError |
|
192 | rescue ActiveRecord::StaleObjectError | |
193 | # Optimistic locking exception |
|
193 | # Optimistic locking exception | |
194 | flash.now[:error] = l(:notice_locking_conflict) |
|
194 | flash.now[:error] = l(:notice_locking_conflict) | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | def reply |
|
197 | def reply | |
198 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
198 | journal = Journal.find(params[:journal_id]) if params[:journal_id] | |
199 | if journal |
|
199 | if journal | |
200 | user = journal.user |
|
200 | user = journal.user | |
201 | text = journal.notes |
|
201 | text = journal.notes | |
202 | else |
|
202 | else | |
203 | user = @issue.author |
|
203 | user = @issue.author | |
204 | text = @issue.description |
|
204 | text = @issue.description | |
205 | end |
|
205 | end | |
206 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " |
|
206 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " | |
207 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" |
|
207 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" | |
208 | render(:update) { |page| |
|
208 | render(:update) { |page| | |
209 | page.<< "$('notes').value = \"#{content}\";" |
|
209 | page.<< "$('notes').value = \"#{content}\";" | |
210 | page.show 'update' |
|
210 | page.show 'update' | |
211 | page << "Form.Element.focus('notes');" |
|
211 | page << "Form.Element.focus('notes');" | |
212 | page << "Element.scrollTo('update');" |
|
212 | page << "Element.scrollTo('update');" | |
213 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
213 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" | |
214 | } |
|
214 | } | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | # Bulk edit a set of issues |
|
217 | # Bulk edit a set of issues | |
218 | def bulk_edit |
|
218 | def bulk_edit | |
219 | if request.post? |
|
219 | if request.post? | |
220 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) |
|
220 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) | |
221 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) |
|
221 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) | |
222 | assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) |
|
222 | assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) | |
223 | category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) |
|
223 | category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) | |
224 | fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id]) |
|
224 | fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id]) | |
225 |
|
225 | |||
226 | unsaved_issue_ids = [] |
|
226 | unsaved_issue_ids = [] | |
227 | @issues.each do |issue| |
|
227 | @issues.each do |issue| | |
228 | journal = issue.init_journal(User.current, params[:notes]) |
|
228 | journal = issue.init_journal(User.current, params[:notes]) | |
229 | issue.priority = priority if priority |
|
229 | issue.priority = priority if priority | |
230 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' |
|
230 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' | |
231 | issue.category = category if category || params[:category_id] == 'none' |
|
231 | issue.category = category if category || params[:category_id] == 'none' | |
232 | issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none' |
|
232 | issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none' | |
233 | issue.start_date = params[:start_date] unless params[:start_date].blank? |
|
233 | issue.start_date = params[:start_date] unless params[:start_date].blank? | |
234 | issue.due_date = params[:due_date] unless params[:due_date].blank? |
|
234 | issue.due_date = params[:due_date] unless params[:due_date].blank? | |
235 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? |
|
235 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? | |
236 | # Don't save any change to the issue if the user is not authorized to apply the requested status |
|
236 | # Don't save any change to the issue if the user is not authorized to apply the requested status | |
237 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save |
|
237 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save | |
238 | # Send notification for each issue (if changed) |
|
238 | # Send notification for each issue (if changed) | |
239 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') |
|
239 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') | |
240 | else |
|
240 | else | |
241 | # Keep unsaved issue ids to display them in flash error |
|
241 | # Keep unsaved issue ids to display them in flash error | |
242 | unsaved_issue_ids << issue.id |
|
242 | unsaved_issue_ids << issue.id | |
243 | end |
|
243 | end | |
244 | end |
|
244 | end | |
245 | if unsaved_issue_ids.empty? |
|
245 | if unsaved_issue_ids.empty? | |
246 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
246 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
247 | else |
|
247 | else | |
248 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
248 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) | |
249 | end |
|
249 | end | |
250 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
250 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
251 | return |
|
251 | return | |
252 | end |
|
252 | end | |
253 | # Find potential statuses the user could be allowed to switch issues to |
|
253 | # Find potential statuses the user could be allowed to switch issues to | |
254 | @available_statuses = Workflow.find(:all, :include => :new_status, |
|
254 | @available_statuses = Workflow.find(:all, :include => :new_status, | |
255 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq |
|
255 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | def move |
|
258 | def move | |
259 | @allowed_projects = [] |
|
259 | @allowed_projects = [] | |
260 | # find projects to which the user is allowed to move the issue |
|
260 | # find projects to which the user is allowed to move the issue | |
261 | if User.current.admin? |
|
261 | if User.current.admin? | |
262 | # admin is allowed to move issues to any active (visible) project |
|
262 | # admin is allowed to move issues to any active (visible) project | |
263 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') |
|
263 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') | |
264 | else |
|
264 | else | |
265 | User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)} |
|
265 | User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)} | |
266 | end |
|
266 | end | |
267 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
267 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
268 | @target_project ||= @project |
|
268 | @target_project ||= @project | |
269 | @trackers = @target_project.trackers |
|
269 | @trackers = @target_project.trackers | |
270 | if request.post? |
|
270 | if request.post? | |
271 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
271 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
272 | unsaved_issue_ids = [] |
|
272 | unsaved_issue_ids = [] | |
273 | @issues.each do |issue| |
|
273 | @issues.each do |issue| | |
274 | issue.init_journal(User.current) |
|
274 | issue.init_journal(User.current) | |
275 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) |
|
275 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) | |
276 | end |
|
276 | end | |
277 | if unsaved_issue_ids.empty? |
|
277 | if unsaved_issue_ids.empty? | |
278 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
278 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
279 | else |
|
279 | else | |
280 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
280 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) | |
281 | end |
|
281 | end | |
282 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
282 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
283 | return |
|
283 | return | |
284 | end |
|
284 | end | |
285 | render :layout => false if request.xhr? |
|
285 | render :layout => false if request.xhr? | |
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | def destroy |
|
288 | def destroy | |
289 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
289 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
290 | if @hours > 0 |
|
290 | if @hours > 0 | |
291 | case params[:todo] |
|
291 | case params[:todo] | |
292 | when 'destroy' |
|
292 | when 'destroy' | |
293 | # nothing to do |
|
293 | # nothing to do | |
294 | when 'nullify' |
|
294 | when 'nullify' | |
295 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
295 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
296 | when 'reassign' |
|
296 | when 'reassign' | |
297 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
297 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
298 | if reassign_to.nil? |
|
298 | if reassign_to.nil? | |
299 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
299 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
300 | return |
|
300 | return | |
301 | else |
|
301 | else | |
302 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
302 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
303 | end |
|
303 | end | |
304 | else |
|
304 | else | |
305 | # display the destroy form |
|
305 | # display the destroy form | |
306 | return |
|
306 | return | |
307 | end |
|
307 | end | |
308 | end |
|
308 | end | |
309 | @issues.each(&:destroy) |
|
309 | @issues.each(&:destroy) | |
310 | redirect_to :action => 'index', :project_id => @project |
|
310 | redirect_to :action => 'index', :project_id => @project | |
311 | end |
|
311 | end | |
312 |
|
312 | |||
313 | def destroy_attachment |
|
313 | def destroy_attachment | |
314 | a = @issue.attachments.find(params[:attachment_id]) |
|
314 | a = @issue.attachments.find(params[:attachment_id]) | |
315 | a.destroy |
|
315 | a.destroy | |
316 | journal = @issue.init_journal(User.current) |
|
316 | journal = @issue.init_journal(User.current) | |
317 | journal.details << JournalDetail.new(:property => 'attachment', |
|
317 | journal.details << JournalDetail.new(:property => 'attachment', | |
318 | :prop_key => a.id, |
|
318 | :prop_key => a.id, | |
319 | :old_value => a.filename) |
|
319 | :old_value => a.filename) | |
320 | journal.save |
|
320 | journal.save | |
321 | redirect_to :action => 'show', :id => @issue |
|
321 | redirect_to :action => 'show', :id => @issue | |
322 | end |
|
322 | end | |
323 |
|
323 | |||
324 | def context_menu |
|
324 | def context_menu | |
325 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) |
|
325 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) | |
326 | if (@issues.size == 1) |
|
326 | if (@issues.size == 1) | |
327 | @issue = @issues.first |
|
327 | @issue = @issues.first | |
328 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
328 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
329 | @assignables = @issue.assignable_users |
|
329 | @assignables = @issue.assignable_users | |
330 | @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
330 | @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) | |
331 | end |
|
331 | end | |
332 | projects = @issues.collect(&:project).compact.uniq |
|
332 | projects = @issues.collect(&:project).compact.uniq | |
333 | @project = projects.first if projects.size == 1 |
|
333 | @project = projects.first if projects.size == 1 | |
334 |
|
334 | |||
335 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), |
|
335 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), | |
336 | :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))), |
|
336 | :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))), | |
337 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
337 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), | |
338 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
338 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), | |
339 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) |
|
339 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | @priorities = Enumeration.get_values('IPRI').reverse |
|
342 | @priorities = Enumeration.get_values('IPRI').reverse | |
343 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
343 | @statuses = IssueStatus.find(:all, :order => 'position') | |
344 | @back = request.env['HTTP_REFERER'] |
|
344 | @back = request.env['HTTP_REFERER'] | |
345 |
|
345 | |||
346 | render :layout => false |
|
346 | render :layout => false | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | def update_form |
|
349 | def update_form | |
350 | @issue = Issue.new(params[:issue]) |
|
350 | @issue = Issue.new(params[:issue]) | |
351 | render :action => :new, :layout => false |
|
351 | render :action => :new, :layout => false | |
352 | end |
|
352 | end | |
353 |
|
353 | |||
354 | def preview |
|
354 | def preview | |
355 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
355 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
356 | @attachements = @issue.attachments if @issue |
|
356 | @attachements = @issue.attachments if @issue | |
357 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) |
|
357 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) | |
358 | render :partial => 'common/preview' |
|
358 | render :partial => 'common/preview' | |
359 | end |
|
359 | end | |
360 |
|
360 | |||
361 | private |
|
361 | private | |
362 | def find_issue |
|
362 | def find_issue | |
363 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
363 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
364 | @project = @issue.project |
|
364 | @project = @issue.project | |
365 | rescue ActiveRecord::RecordNotFound |
|
365 | rescue ActiveRecord::RecordNotFound | |
366 | render_404 |
|
366 | render_404 | |
367 | end |
|
367 | end | |
368 |
|
368 | |||
369 | # Filter for bulk operations |
|
369 | # Filter for bulk operations | |
370 | def find_issues |
|
370 | def find_issues | |
371 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
371 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
372 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
372 | raise ActiveRecord::RecordNotFound if @issues.empty? | |
373 | projects = @issues.collect(&:project).compact.uniq |
|
373 | projects = @issues.collect(&:project).compact.uniq | |
374 | if projects.size == 1 |
|
374 | if projects.size == 1 | |
375 | @project = projects.first |
|
375 | @project = projects.first | |
376 | else |
|
376 | else | |
377 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
377 | # TODO: let users bulk edit/move/destroy issues from different projects | |
378 | render_error 'Can not bulk edit/move/destroy issues from different projects' and return false |
|
378 | render_error 'Can not bulk edit/move/destroy issues from different projects' and return false | |
379 | end |
|
379 | end | |
380 | rescue ActiveRecord::RecordNotFound |
|
380 | rescue ActiveRecord::RecordNotFound | |
381 | render_404 |
|
381 | render_404 | |
382 | end |
|
382 | end | |
383 |
|
383 | |||
384 | def find_project |
|
384 | def find_project | |
385 | @project = Project.find(params[:project_id]) |
|
385 | @project = Project.find(params[:project_id]) | |
386 | rescue ActiveRecord::RecordNotFound |
|
386 | rescue ActiveRecord::RecordNotFound | |
387 | render_404 |
|
387 | render_404 | |
388 | end |
|
388 | end | |
389 |
|
389 | |||
390 | def find_optional_project |
|
390 | def find_optional_project | |
391 | return true unless params[:project_id] |
|
391 | return true unless params[:project_id] | |
392 | @project = Project.find(params[:project_id]) |
|
392 | @project = Project.find(params[:project_id]) | |
393 | authorize |
|
393 | authorize | |
394 | rescue ActiveRecord::RecordNotFound |
|
394 | rescue ActiveRecord::RecordNotFound | |
395 | render_404 |
|
395 | render_404 | |
396 | end |
|
396 | end | |
397 |
|
397 | |||
398 | # Retrieve query from session or build a new query |
|
398 | # Retrieve query from session or build a new query | |
399 | def retrieve_query |
|
399 | def retrieve_query | |
400 | if !params[:query_id].blank? |
|
400 | if !params[:query_id].blank? | |
401 | cond = "project_id IS NULL" |
|
401 | cond = "project_id IS NULL" | |
402 | cond << " OR project_id = #{@project.id}" if @project |
|
402 | cond << " OR project_id = #{@project.id}" if @project | |
403 | @query = Query.find(params[:query_id], :conditions => cond) |
|
403 | @query = Query.find(params[:query_id], :conditions => cond) | |
404 | @query.project = @project |
|
404 | @query.project = @project | |
405 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
405 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
406 | else |
|
406 | else | |
407 | if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
407 | if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
408 | # Give it a name, required to be valid |
|
408 | # Give it a name, required to be valid | |
409 | @query = Query.new(:name => "_") |
|
409 | @query = Query.new(:name => "_") | |
410 | @query.project = @project |
|
410 | @query.project = @project | |
411 | if params[:fields] and params[:fields].is_a? Array |
|
411 | if params[:fields] and params[:fields].is_a? Array | |
412 | params[:fields].each do |field| |
|
412 | params[:fields].each do |field| | |
413 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
413 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
414 | end |
|
414 | end | |
415 | else |
|
415 | else | |
416 | @query.available_filters.keys.each do |field| |
|
416 | @query.available_filters.keys.each do |field| | |
417 | @query.add_short_filter(field, params[field]) if params[field] |
|
417 | @query.add_short_filter(field, params[field]) if params[field] | |
418 | end |
|
418 | end | |
419 | end |
|
419 | end | |
420 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters} |
|
420 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters} | |
421 | else |
|
421 | else | |
422 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
422 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
423 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters]) |
|
423 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters]) | |
424 | @query.project = @project |
|
424 | @query.project = @project | |
425 | end |
|
425 | end | |
426 | end |
|
426 | end | |
427 | end |
|
427 | end | |
428 | end |
|
428 | end |
General Comments 0
You need to be logged in to leave comments.
Login now