@@ -1,488 +1,492 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 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 | menu_item :new_issue, :only => [:new, :create] |
|
19 | menu_item :new_issue, :only => [:new, :create] | |
20 | default_search_scope :issues |
|
20 | default_search_scope :issues | |
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :update, :reply] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :update, :reply] | |
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, :create, :update_form, :preview, :auto_complete] |
|
24 | before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete] | |
25 | before_filter :authorize, :except => [:index, :changes, :preview, :context_menu] |
|
25 | before_filter :authorize, :except => [:index, :changes, :preview, :context_menu] | |
26 | before_filter :find_optional_project, :only => [:index, :changes] |
|
26 | before_filter :find_optional_project, :only => [:index, :changes] | |
27 | before_filter :check_for_default_issue_status, :only => [:new, :create] |
|
27 | before_filter :check_for_default_issue_status, :only => [:new, :create] | |
28 | before_filter :build_new_issue_from_params, :only => [:new, :create] |
|
28 | before_filter :build_new_issue_from_params, :only => [:new, :create] | |
29 | accept_key_auth :index, :show, :changes |
|
29 | accept_key_auth :index, :show, :changes | |
30 |
|
30 | |||
31 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
31 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
32 |
|
32 | |||
33 | helper :journals |
|
33 | helper :journals | |
34 | helper :projects |
|
34 | helper :projects | |
35 | include ProjectsHelper |
|
35 | include ProjectsHelper | |
36 | helper :custom_fields |
|
36 | helper :custom_fields | |
37 | include CustomFieldsHelper |
|
37 | include CustomFieldsHelper | |
38 | helper :issue_relations |
|
38 | helper :issue_relations | |
39 | include IssueRelationsHelper |
|
39 | include IssueRelationsHelper | |
40 | helper :watchers |
|
40 | helper :watchers | |
41 | include WatchersHelper |
|
41 | include WatchersHelper | |
42 | helper :attachments |
|
42 | helper :attachments | |
43 | include AttachmentsHelper |
|
43 | include AttachmentsHelper | |
44 | helper :queries |
|
44 | helper :queries | |
45 | include QueriesHelper |
|
45 | include QueriesHelper | |
46 | helper :sort |
|
46 | helper :sort | |
47 | include SortHelper |
|
47 | include SortHelper | |
48 | include IssuesHelper |
|
48 | include IssuesHelper | |
49 | helper :timelog |
|
49 | helper :timelog | |
50 | include Redmine::Export::PDF |
|
50 | include Redmine::Export::PDF | |
51 |
|
51 | |||
52 | verify :method => [:post, :delete], |
|
52 | verify :method => [:post, :delete], | |
53 | :only => :destroy, |
|
53 | :only => :destroy, | |
54 | :render => { :nothing => true, :status => :method_not_allowed } |
|
54 | :render => { :nothing => true, :status => :method_not_allowed } | |
55 |
|
55 | |||
56 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
56 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
57 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
57 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
58 |
|
58 | |||
59 | def index |
|
59 | def index | |
60 | retrieve_query |
|
60 | retrieve_query | |
61 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
61 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | |
62 | sort_update(@query.sortable_columns) |
|
62 | sort_update(@query.sortable_columns) | |
63 |
|
63 | |||
64 | if @query.valid? |
|
64 | if @query.valid? | |
65 | limit = case params[:format] |
|
65 | limit = case params[:format] | |
66 | when 'csv', 'pdf' |
|
66 | when 'csv', 'pdf' | |
67 | Setting.issues_export_limit.to_i |
|
67 | Setting.issues_export_limit.to_i | |
68 | when 'atom' |
|
68 | when 'atom' | |
69 | Setting.feeds_limit.to_i |
|
69 | Setting.feeds_limit.to_i | |
70 | else |
|
70 | else | |
71 | per_page_option |
|
71 | per_page_option | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | @issue_count = @query.issue_count |
|
74 | @issue_count = @query.issue_count | |
75 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
75 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
76 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
76 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | |
77 | :order => sort_clause, |
|
77 | :order => sort_clause, | |
78 | :offset => @issue_pages.current.offset, |
|
78 | :offset => @issue_pages.current.offset, | |
79 | :limit => limit) |
|
79 | :limit => limit) | |
80 | @issue_count_by_group = @query.issue_count_by_group |
|
80 | @issue_count_by_group = @query.issue_count_by_group | |
81 |
|
81 | |||
82 | respond_to do |format| |
|
82 | respond_to do |format| | |
83 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
83 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
84 | format.xml { render :layout => false } |
|
84 | format.xml { render :layout => false } | |
85 | format.json { render :text => @issues.to_json, :layout => false } |
|
85 | format.json { render :text => @issues.to_json, :layout => false } | |
86 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
86 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
87 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
87 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } | |
88 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
88 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | |
89 | end |
|
89 | end | |
90 | else |
|
90 | else | |
91 | # Send html if the query is not valid |
|
91 | # Send html if the query is not valid | |
92 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
92 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
93 | end |
|
93 | end | |
94 | rescue ActiveRecord::RecordNotFound |
|
94 | rescue ActiveRecord::RecordNotFound | |
95 | render_404 |
|
95 | render_404 | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def changes |
|
98 | def changes | |
99 | retrieve_query |
|
99 | retrieve_query | |
100 | sort_init 'id', 'desc' |
|
100 | sort_init 'id', 'desc' | |
101 | sort_update(@query.sortable_columns) |
|
101 | sort_update(@query.sortable_columns) | |
102 |
|
102 | |||
103 | if @query.valid? |
|
103 | if @query.valid? | |
104 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
104 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", | |
105 | :limit => 25) |
|
105 | :limit => 25) | |
106 | end |
|
106 | end | |
107 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
107 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
108 | render :layout => false, :content_type => 'application/atom+xml' |
|
108 | render :layout => false, :content_type => 'application/atom+xml' | |
109 | rescue ActiveRecord::RecordNotFound |
|
109 | rescue ActiveRecord::RecordNotFound | |
110 | render_404 |
|
110 | render_404 | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def show |
|
113 | def show | |
114 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
114 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
115 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
115 | @journals.each_with_index {|j,i| j.indice = i+1} | |
116 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
116 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
117 | @changesets = @issue.changesets.visible.all |
|
117 | @changesets = @issue.changesets.visible.all | |
118 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
118 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? | |
119 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
119 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
120 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
120 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
121 | @priorities = IssuePriority.all |
|
121 | @priorities = IssuePriority.all | |
122 | @time_entry = TimeEntry.new |
|
122 | @time_entry = TimeEntry.new | |
123 | respond_to do |format| |
|
123 | respond_to do |format| | |
124 | format.html { render :template => 'issues/show.rhtml' } |
|
124 | format.html { render :template => 'issues/show.rhtml' } | |
125 | format.xml { render :layout => false } |
|
125 | format.xml { render :layout => false } | |
126 | format.json { render :text => @issue.to_json, :layout => false } |
|
126 | format.json { render :text => @issue.to_json, :layout => false } | |
127 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } |
|
127 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } | |
128 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
128 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
129 | end |
|
129 | end | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | # Add a new issue |
|
132 | # Add a new issue | |
133 | # The new issue will be created from an existing one if copy_from parameter is given |
|
133 | # The new issue will be created from an existing one if copy_from parameter is given | |
134 | def new |
|
134 | def new | |
135 | render :action => 'new', :layout => !request.xhr? |
|
135 | render :action => 'new', :layout => !request.xhr? | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def create |
|
138 | def create | |
139 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
139 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | |
140 | if @issue.save |
|
140 | if @issue.save | |
141 | attachments = Attachment.attach_files(@issue, params[:attachments]) |
|
141 | attachments = Attachment.attach_files(@issue, params[:attachments]) | |
142 | render_attachment_warning_if_needed(@issue) |
|
142 | render_attachment_warning_if_needed(@issue) | |
143 | flash[:notice] = l(:notice_successful_create) |
|
143 | flash[:notice] = l(:notice_successful_create) | |
144 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
144 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | |
145 | respond_to do |format| |
|
145 | respond_to do |format| | |
146 | format.html { |
|
146 | format.html { | |
147 | redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : |
|
147 | redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : | |
148 | { :action => 'show', :id => @issue }) |
|
148 | { :action => 'show', :id => @issue }) | |
149 | } |
|
149 | } | |
150 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } |
|
150 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } | |
151 | format.json { render :text => @issue.to_json, :status => :created, :location => url_for(:controller => 'issues', :action => 'show'), :layout => false } |
|
151 | format.json { render :text => @issue.to_json, :status => :created, :location => url_for(:controller => 'issues', :action => 'show'), :layout => false } | |
152 | end |
|
152 | end | |
153 | return |
|
153 | return | |
154 | else |
|
154 | else | |
155 | respond_to do |format| |
|
155 | respond_to do |format| | |
156 | format.html { render :action => 'new' } |
|
156 | format.html { render :action => 'new' } | |
157 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } |
|
157 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } | |
158 | format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false } |
|
158 | format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false } | |
159 | end |
|
159 | end | |
160 | end |
|
160 | end | |
161 | end |
|
161 | end | |
162 |
|
162 | |||
163 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
163 | # Attributes that can be updated on workflow transition (without :edit permission) | |
164 | # TODO: make it configurable (at least per role) |
|
164 | # TODO: make it configurable (at least per role) | |
165 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
165 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) | |
166 |
|
166 | |||
167 | def edit |
|
167 | def edit | |
168 | update_issue_from_params |
|
168 | update_issue_from_params | |
169 |
|
169 | |||
170 | @journal = @issue.current_journal |
|
170 | @journal = @issue.current_journal | |
171 |
|
171 | |||
172 | respond_to do |format| |
|
172 | respond_to do |format| | |
173 | format.html { } |
|
173 | format.html { } | |
174 | format.xml { } |
|
174 | format.xml { } | |
175 | end |
|
175 | end | |
176 | end |
|
176 | end | |
177 |
|
177 | |||
178 | def update |
|
178 | def update | |
179 | update_issue_from_params |
|
179 | update_issue_from_params | |
180 |
|
180 | |||
181 | if @issue.save_issue_with_child_records(params, @time_entry) |
|
181 | if @issue.save_issue_with_child_records(params, @time_entry) | |
182 | render_attachment_warning_if_needed(@issue) |
|
182 | render_attachment_warning_if_needed(@issue) | |
183 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
183 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
184 |
|
184 | |||
185 | respond_to do |format| |
|
185 | respond_to do |format| | |
186 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
186 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | |
187 | format.xml { head :ok } |
|
187 | format.xml { head :ok } | |
188 | format.json { head :ok } |
|
188 | format.json { head :ok } | |
189 | end |
|
189 | end | |
190 | else |
|
190 | else | |
191 | render_attachment_warning_if_needed(@issue) |
|
191 | render_attachment_warning_if_needed(@issue) | |
192 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
192 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
193 | @journal = @issue.current_journal |
|
193 | @journal = @issue.current_journal | |
194 |
|
194 | |||
195 | respond_to do |format| |
|
195 | respond_to do |format| | |
196 | format.html { render :action => 'edit' } |
|
196 | format.html { render :action => 'edit' } | |
197 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } |
|
197 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } | |
198 | format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false } |
|
198 | format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false } | |
199 | end |
|
199 | end | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def reply |
|
203 | def reply | |
204 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
204 | journal = Journal.find(params[:journal_id]) if params[:journal_id] | |
205 | if journal |
|
205 | if journal | |
206 | user = journal.user |
|
206 | user = journal.user | |
207 | text = journal.notes |
|
207 | text = journal.notes | |
208 | else |
|
208 | else | |
209 | user = @issue.author |
|
209 | user = @issue.author | |
210 | text = @issue.description |
|
210 | text = @issue.description | |
211 | end |
|
211 | end | |
212 | # Replaces pre blocks with [...] |
|
212 | # Replaces pre blocks with [...] | |
213 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') |
|
213 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') | |
214 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " |
|
214 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " | |
215 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
215 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" | |
216 |
|
216 | |||
217 | render(:update) { |page| |
|
217 | render(:update) { |page| | |
218 | page.<< "$('notes').value = \"#{escape_javascript content}\";" |
|
218 | page.<< "$('notes').value = \"#{escape_javascript content}\";" | |
219 | page.show 'update' |
|
219 | page.show 'update' | |
220 | page << "Form.Element.focus('notes');" |
|
220 | page << "Form.Element.focus('notes');" | |
221 | page << "Element.scrollTo('update');" |
|
221 | page << "Element.scrollTo('update');" | |
222 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
222 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" | |
223 | } |
|
223 | } | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | # Bulk edit a set of issues |
|
226 | # Bulk edit a set of issues | |
227 | def bulk_edit |
|
227 | def bulk_edit | |
228 | @issues.sort! |
|
228 | @issues.sort! | |
229 | if request.post? |
|
229 | if request.post? | |
230 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} |
|
230 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} | |
231 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} |
|
231 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} | |
232 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] |
|
232 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] | |
233 |
|
233 | |||
234 | unsaved_issue_ids = [] |
|
234 | unsaved_issue_ids = [] | |
235 | @issues.each do |issue| |
|
235 | @issues.each do |issue| | |
236 | issue.reload |
|
236 | issue.reload | |
237 | journal = issue.init_journal(User.current, params[:notes]) |
|
237 | journal = issue.init_journal(User.current, params[:notes]) | |
238 | issue.safe_attributes = attributes |
|
238 | issue.safe_attributes = attributes | |
239 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
239 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) | |
240 | unless issue.save |
|
240 | unless issue.save | |
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 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
245 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
246 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) |
|
246 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) | |
247 | return |
|
247 | return | |
248 | end |
|
248 | end | |
249 | @available_statuses = Workflow.available_statuses(@project) |
|
249 | @available_statuses = Workflow.available_statuses(@project) | |
250 | @custom_fields = @project.all_issue_custom_fields |
|
250 | @custom_fields = @project.all_issue_custom_fields | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
253 | def move |
|
253 | def move | |
254 | @issues.sort! |
|
254 | @issues.sort! | |
255 | @copy = params[:copy_options] && params[:copy_options][:copy] |
|
255 | @copy = params[:copy_options] && params[:copy_options][:copy] | |
256 | @allowed_projects = Issue.allowed_target_projects_on_move |
|
256 | @allowed_projects = Issue.allowed_target_projects_on_move | |
257 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
257 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
258 | @target_project ||= @project |
|
258 | @target_project ||= @project | |
259 | @trackers = @target_project.trackers |
|
259 | @trackers = @target_project.trackers | |
260 | @available_statuses = Workflow.available_statuses(@project) |
|
260 | @available_statuses = Workflow.available_statuses(@project) | |
261 | if request.post? |
|
261 | if request.post? | |
262 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
262 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
263 | unsaved_issue_ids = [] |
|
263 | unsaved_issue_ids = [] | |
264 | moved_issues = [] |
|
264 | moved_issues = [] | |
265 | @issues.each do |issue| |
|
265 | @issues.each do |issue| | |
266 | issue.reload |
|
266 | issue.reload | |
267 | changed_attributes = {} |
|
|||
268 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| |
|
|||
269 | unless params[valid_attribute].blank? |
|
|||
270 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) |
|
|||
271 | end |
|
|||
272 | end |
|
|||
273 | issue.init_journal(User.current) |
|
267 | issue.init_journal(User.current) | |
274 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) |
|
268 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) | |
275 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) |
|
269 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)}) | |
276 | moved_issues << r |
|
270 | moved_issues << r | |
277 | else |
|
271 | else | |
278 | unsaved_issue_ids << issue.id |
|
272 | unsaved_issue_ids << issue.id | |
279 | end |
|
273 | end | |
280 | end |
|
274 | end | |
281 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
275 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
282 |
|
276 | |||
283 | if params[:follow] |
|
277 | if params[:follow] | |
284 | if @issues.size == 1 && moved_issues.size == 1 |
|
278 | if @issues.size == 1 && moved_issues.size == 1 | |
285 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first |
|
279 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first | |
286 | else |
|
280 | else | |
287 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) |
|
281 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) | |
288 | end |
|
282 | end | |
289 | else |
|
283 | else | |
290 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
284 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
291 | end |
|
285 | end | |
292 | return |
|
286 | return | |
293 | end |
|
287 | end | |
294 | render :layout => false if request.xhr? |
|
288 | render :layout => false if request.xhr? | |
295 | end |
|
289 | end | |
296 |
|
290 | |||
297 | def destroy |
|
291 | def destroy | |
298 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
292 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
299 | if @hours > 0 |
|
293 | if @hours > 0 | |
300 | case params[:todo] |
|
294 | case params[:todo] | |
301 | when 'destroy' |
|
295 | when 'destroy' | |
302 | # nothing to do |
|
296 | # nothing to do | |
303 | when 'nullify' |
|
297 | when 'nullify' | |
304 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
298 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
305 | when 'reassign' |
|
299 | when 'reassign' | |
306 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
300 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
307 | if reassign_to.nil? |
|
301 | if reassign_to.nil? | |
308 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
302 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
309 | return |
|
303 | return | |
310 | else |
|
304 | else | |
311 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
305 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
312 | end |
|
306 | end | |
313 | else |
|
307 | else | |
314 | unless params[:format] == 'xml' || params[:format] == 'json' |
|
308 | unless params[:format] == 'xml' || params[:format] == 'json' | |
315 | # display the destroy form if it's a user request |
|
309 | # display the destroy form if it's a user request | |
316 | return |
|
310 | return | |
317 | end |
|
311 | end | |
318 | end |
|
312 | end | |
319 | end |
|
313 | end | |
320 | @issues.each(&:destroy) |
|
314 | @issues.each(&:destroy) | |
321 | respond_to do |format| |
|
315 | respond_to do |format| | |
322 | format.html { redirect_to :action => 'index', :project_id => @project } |
|
316 | format.html { redirect_to :action => 'index', :project_id => @project } | |
323 | format.xml { head :ok } |
|
317 | format.xml { head :ok } | |
324 | format.json { head :ok } |
|
318 | format.json { head :ok } | |
325 | end |
|
319 | end | |
326 | end |
|
320 | end | |
327 |
|
321 | |||
328 | def context_menu |
|
322 | def context_menu | |
329 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) |
|
323 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) | |
330 | if (@issues.size == 1) |
|
324 | if (@issues.size == 1) | |
331 | @issue = @issues.first |
|
325 | @issue = @issues.first | |
332 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
326 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
333 | end |
|
327 | end | |
334 | projects = @issues.collect(&:project).compact.uniq |
|
328 | projects = @issues.collect(&:project).compact.uniq | |
335 | @project = projects.first if projects.size == 1 |
|
329 | @project = projects.first if projects.size == 1 | |
336 |
|
330 | |||
337 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), |
|
331 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), | |
338 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
332 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), | |
339 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), |
|
333 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), | |
340 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
334 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), | |
341 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
335 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), | |
342 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) |
|
336 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) | |
343 | } |
|
337 | } | |
344 | if @project |
|
338 | if @project | |
345 | @assignables = @project.assignable_users |
|
339 | @assignables = @project.assignable_users | |
346 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
340 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) | |
347 | @trackers = @project.trackers |
|
341 | @trackers = @project.trackers | |
348 | end |
|
342 | end | |
349 |
|
343 | |||
350 | @priorities = IssuePriority.all.reverse |
|
344 | @priorities = IssuePriority.all.reverse | |
351 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
345 | @statuses = IssueStatus.find(:all, :order => 'position') | |
352 | @back = back_url |
|
346 | @back = back_url | |
353 |
|
347 | |||
354 | render :layout => false |
|
348 | render :layout => false | |
355 | end |
|
349 | end | |
356 |
|
350 | |||
357 | def update_form |
|
351 | def update_form | |
358 | if params[:id].blank? |
|
352 | if params[:id].blank? | |
359 | @issue = Issue.new |
|
353 | @issue = Issue.new | |
360 | @issue.project = @project |
|
354 | @issue.project = @project | |
361 | else |
|
355 | else | |
362 | @issue = @project.issues.visible.find(params[:id]) |
|
356 | @issue = @project.issues.visible.find(params[:id]) | |
363 | end |
|
357 | end | |
364 | @issue.attributes = params[:issue] |
|
358 | @issue.attributes = params[:issue] | |
365 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq |
|
359 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq | |
366 | @priorities = IssuePriority.all |
|
360 | @priorities = IssuePriority.all | |
367 |
|
361 | |||
368 | render :partial => 'attributes' |
|
362 | render :partial => 'attributes' | |
369 | end |
|
363 | end | |
370 |
|
364 | |||
371 | def preview |
|
365 | def preview | |
372 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
366 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
373 | if @issue |
|
367 | if @issue | |
374 | @attachements = @issue.attachments |
|
368 | @attachements = @issue.attachments | |
375 | @description = params[:issue] && params[:issue][:description] |
|
369 | @description = params[:issue] && params[:issue][:description] | |
376 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") |
|
370 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") | |
377 | @description = nil |
|
371 | @description = nil | |
378 | end |
|
372 | end | |
379 | @notes = params[:notes] |
|
373 | @notes = params[:notes] | |
380 | else |
|
374 | else | |
381 | @description = (params[:issue] ? params[:issue][:description] : nil) |
|
375 | @description = (params[:issue] ? params[:issue][:description] : nil) | |
382 | end |
|
376 | end | |
383 | render :layout => false |
|
377 | render :layout => false | |
384 | end |
|
378 | end | |
385 |
|
379 | |||
386 | def auto_complete |
|
380 | def auto_complete | |
387 | @issues = [] |
|
381 | @issues = [] | |
388 | q = params[:q].to_s |
|
382 | q = params[:q].to_s | |
389 | if q.match(/^\d+$/) |
|
383 | if q.match(/^\d+$/) | |
390 | @issues << @project.issues.visible.find_by_id(q.to_i) |
|
384 | @issues << @project.issues.visible.find_by_id(q.to_i) | |
391 | end |
|
385 | end | |
392 | unless q.blank? |
|
386 | unless q.blank? | |
393 | @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10) |
|
387 | @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10) | |
394 | end |
|
388 | end | |
395 | render :layout => false |
|
389 | render :layout => false | |
396 | end |
|
390 | end | |
397 |
|
391 | |||
398 | private |
|
392 | private | |
399 | def find_issue |
|
393 | def find_issue | |
400 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
394 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
401 | @project = @issue.project |
|
395 | @project = @issue.project | |
402 | rescue ActiveRecord::RecordNotFound |
|
396 | rescue ActiveRecord::RecordNotFound | |
403 | render_404 |
|
397 | render_404 | |
404 | end |
|
398 | end | |
405 |
|
399 | |||
406 | # Filter for bulk operations |
|
400 | # Filter for bulk operations | |
407 | def find_issues |
|
401 | def find_issues | |
408 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
402 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
409 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
403 | raise ActiveRecord::RecordNotFound if @issues.empty? | |
410 | projects = @issues.collect(&:project).compact.uniq |
|
404 | projects = @issues.collect(&:project).compact.uniq | |
411 | if projects.size == 1 |
|
405 | if projects.size == 1 | |
412 | @project = projects.first |
|
406 | @project = projects.first | |
413 | else |
|
407 | else | |
414 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
408 | # TODO: let users bulk edit/move/destroy issues from different projects | |
415 | render_error 'Can not bulk edit/move/destroy issues from different projects' |
|
409 | render_error 'Can not bulk edit/move/destroy issues from different projects' | |
416 | return false |
|
410 | return false | |
417 | end |
|
411 | end | |
418 | rescue ActiveRecord::RecordNotFound |
|
412 | rescue ActiveRecord::RecordNotFound | |
419 | render_404 |
|
413 | render_404 | |
420 | end |
|
414 | end | |
421 |
|
415 | |||
422 | def find_project |
|
416 | def find_project | |
423 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
417 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] | |
424 | @project = Project.find(project_id) |
|
418 | @project = Project.find(project_id) | |
425 | rescue ActiveRecord::RecordNotFound |
|
419 | rescue ActiveRecord::RecordNotFound | |
426 | render_404 |
|
420 | render_404 | |
427 | end |
|
421 | end | |
428 |
|
422 | |||
429 | # Used by #edit and #update to set some common instance variables |
|
423 | # Used by #edit and #update to set some common instance variables | |
430 | # from the params |
|
424 | # from the params | |
431 | # TODO: Refactor, not everything in here is needed by #edit |
|
425 | # TODO: Refactor, not everything in here is needed by #edit | |
432 | def update_issue_from_params |
|
426 | def update_issue_from_params | |
433 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
427 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
434 | @priorities = IssuePriority.all |
|
428 | @priorities = IssuePriority.all | |
435 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
429 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
436 | @time_entry = TimeEntry.new |
|
430 | @time_entry = TimeEntry.new | |
437 |
|
431 | |||
438 | @notes = params[:notes] |
|
432 | @notes = params[:notes] | |
439 | @issue.init_journal(User.current, @notes) |
|
433 | @issue.init_journal(User.current, @notes) | |
440 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
434 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |
441 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
435 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |
442 | attrs = params[:issue].dup |
|
436 | attrs = params[:issue].dup | |
443 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
437 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |
444 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
438 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |
445 | @issue.safe_attributes = attrs |
|
439 | @issue.safe_attributes = attrs | |
446 | end |
|
440 | end | |
447 |
|
441 | |||
448 | end |
|
442 | end | |
449 |
|
443 | |||
450 | # TODO: Refactor, lots of extra code in here |
|
444 | # TODO: Refactor, lots of extra code in here | |
451 | def build_new_issue_from_params |
|
445 | def build_new_issue_from_params | |
452 | @issue = Issue.new |
|
446 | @issue = Issue.new | |
453 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
447 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
454 | @issue.project = @project |
|
448 | @issue.project = @project | |
455 | # Tracker must be set before custom field values |
|
449 | # Tracker must be set before custom field values | |
456 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
450 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
457 | if @issue.tracker.nil? |
|
451 | if @issue.tracker.nil? | |
458 | render_error l(:error_no_tracker_in_project) |
|
452 | render_error l(:error_no_tracker_in_project) | |
459 | return false |
|
453 | return false | |
460 | end |
|
454 | end | |
461 | if params[:issue].is_a?(Hash) |
|
455 | if params[:issue].is_a?(Hash) | |
462 | @issue.safe_attributes = params[:issue] |
|
456 | @issue.safe_attributes = params[:issue] | |
463 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) |
|
457 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
464 | end |
|
458 | end | |
465 | @issue.author = User.current |
|
459 | @issue.author = User.current | |
466 | @issue.start_date ||= Date.today |
|
460 | @issue.start_date ||= Date.today | |
467 | @priorities = IssuePriority.all |
|
461 | @priorities = IssuePriority.all | |
468 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) |
|
462 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
469 | end |
|
463 | end | |
470 |
|
464 | |||
471 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) |
|
465 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) | |
472 | if unsaved_issue_ids.empty? |
|
466 | if unsaved_issue_ids.empty? | |
473 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
|
467 | flash[:notice] = l(:notice_successful_update) unless issues.empty? | |
474 | else |
|
468 | else | |
475 | flash[:error] = l(:notice_failed_to_save_issues, |
|
469 | flash[:error] = l(:notice_failed_to_save_issues, | |
476 | :count => unsaved_issue_ids.size, |
|
470 | :count => unsaved_issue_ids.size, | |
477 | :total => issues.size, |
|
471 | :total => issues.size, | |
478 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
472 | :ids => '#' + unsaved_issue_ids.join(', #')) | |
479 | end |
|
473 | end | |
480 | end |
|
474 | end | |
481 |
|
475 | |||
482 | def check_for_default_issue_status |
|
476 | def check_for_default_issue_status | |
483 | if IssueStatus.default.nil? |
|
477 | if IssueStatus.default.nil? | |
484 | render_error l(:error_no_default_issue_status) |
|
478 | render_error l(:error_no_default_issue_status) | |
485 | return false |
|
479 | return false | |
486 | end |
|
480 | end | |
487 | end |
|
481 | end | |
|
482 | ||||
|
483 | def extract_changed_attributes_for_move(params) | |||
|
484 | changed_attributes = {} | |||
|
485 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| | |||
|
486 | unless params[valid_attribute].blank? | |||
|
487 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) | |||
|
488 | end | |||
|
489 | end | |||
|
490 | changed_attributes | |||
|
491 | end | |||
488 | end |
|
492 | end |
General Comments 0
You need to be logged in to leave comments.
Login now