@@ -1,582 +1,585 | |||||
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 |
|
19 | menu_item :new_issue, :only => :new | |
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, :update_form, :preview, :auto_complete] |
|
24 | before_filter :find_project, :only => [:new, :update_form, :preview, :auto_complete] | |
25 | before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] |
|
25 | before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] | |
26 | before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] |
|
26 | before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] | |
27 | accept_key_auth :index, :show, :changes |
|
27 | accept_key_auth :index, :show, :changes | |
28 |
|
28 | |||
29 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
29 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
30 |
|
30 | |||
31 | helper :journals |
|
31 | helper :journals | |
32 | helper :projects |
|
32 | helper :projects | |
33 | include ProjectsHelper |
|
33 | include ProjectsHelper | |
34 | helper :custom_fields |
|
34 | helper :custom_fields | |
35 | include CustomFieldsHelper |
|
35 | include CustomFieldsHelper | |
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 | include QueriesHelper |
|
43 | include QueriesHelper | |
44 | helper :sort |
|
44 | helper :sort | |
45 | include SortHelper |
|
45 | include SortHelper | |
46 | include IssuesHelper |
|
46 | include IssuesHelper | |
47 | helper :timelog |
|
47 | helper :timelog | |
48 | include Redmine::Export::PDF |
|
48 | include Redmine::Export::PDF | |
49 |
|
49 | |||
50 | verify :method => [:post, :delete], |
|
50 | verify :method => [:post, :delete], | |
51 | :only => :destroy, |
|
51 | :only => :destroy, | |
52 | :render => { :nothing => true, :status => :method_not_allowed } |
|
52 | :render => { :nothing => true, :status => :method_not_allowed } | |
53 |
|
53 | |||
54 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
54 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
55 |
|
55 | |||
56 | def index |
|
56 | def index | |
57 | retrieve_query |
|
57 | retrieve_query | |
58 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
58 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | |
59 | sort_update(@query.sortable_columns) |
|
59 | sort_update(@query.sortable_columns) | |
60 |
|
60 | |||
61 | if @query.valid? |
|
61 | if @query.valid? | |
62 | limit = case params[:format] |
|
62 | limit = case params[:format] | |
63 | when 'csv', 'pdf' |
|
63 | when 'csv', 'pdf' | |
64 | Setting.issues_export_limit.to_i |
|
64 | Setting.issues_export_limit.to_i | |
65 | when 'atom' |
|
65 | when 'atom' | |
66 | Setting.feeds_limit.to_i |
|
66 | Setting.feeds_limit.to_i | |
67 | else |
|
67 | else | |
68 | per_page_option |
|
68 | per_page_option | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | @issue_count = @query.issue_count |
|
71 | @issue_count = @query.issue_count | |
72 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
72 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
73 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
73 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | |
74 | :order => sort_clause, |
|
74 | :order => sort_clause, | |
75 | :offset => @issue_pages.current.offset, |
|
75 | :offset => @issue_pages.current.offset, | |
76 | :limit => limit) |
|
76 | :limit => limit) | |
77 | @issue_count_by_group = @query.issue_count_by_group |
|
77 | @issue_count_by_group = @query.issue_count_by_group | |
78 |
|
78 | |||
79 | respond_to do |format| |
|
79 | respond_to do |format| | |
80 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
80 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
81 | format.xml { render :layout => false } |
|
81 | format.xml { render :layout => false } | |
82 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
82 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
83 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
83 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } | |
84 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
84 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | |
85 | end |
|
85 | end | |
86 | else |
|
86 | else | |
87 | # Send html if the query is not valid |
|
87 | # Send html if the query is not valid | |
88 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
88 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
89 | end |
|
89 | end | |
90 | rescue ActiveRecord::RecordNotFound |
|
90 | rescue ActiveRecord::RecordNotFound | |
91 | render_404 |
|
91 | render_404 | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def changes |
|
94 | def changes | |
95 | retrieve_query |
|
95 | retrieve_query | |
96 | sort_init 'id', 'desc' |
|
96 | sort_init 'id', 'desc' | |
97 | sort_update(@query.sortable_columns) |
|
97 | sort_update(@query.sortable_columns) | |
98 |
|
98 | |||
99 | if @query.valid? |
|
99 | if @query.valid? | |
100 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
100 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", | |
101 | :limit => 25) |
|
101 | :limit => 25) | |
102 | end |
|
102 | end | |
103 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
103 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
104 | render :layout => false, :content_type => 'application/atom+xml' |
|
104 | render :layout => false, :content_type => 'application/atom+xml' | |
105 | rescue ActiveRecord::RecordNotFound |
|
105 | rescue ActiveRecord::RecordNotFound | |
106 | render_404 |
|
106 | render_404 | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 | def show |
|
109 | def show | |
110 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
110 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
111 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
111 | @journals.each_with_index {|j,i| j.indice = i+1} | |
112 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
112 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
113 | @changesets = @issue.changesets.visible.all |
|
113 | @changesets = @issue.changesets.visible.all | |
114 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
114 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? | |
115 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
115 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
116 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
116 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
117 | @priorities = IssuePriority.all |
|
117 | @priorities = IssuePriority.all | |
118 | @time_entry = TimeEntry.new |
|
118 | @time_entry = TimeEntry.new | |
119 | respond_to do |format| |
|
119 | respond_to do |format| | |
120 | format.html { render :template => 'issues/show.rhtml' } |
|
120 | format.html { render :template => 'issues/show.rhtml' } | |
121 | format.xml { render :layout => false } |
|
121 | format.xml { render :layout => false } | |
122 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } |
|
122 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } | |
123 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
123 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
124 | end |
|
124 | end | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | # Add a new issue |
|
127 | # Add a new issue | |
128 | # The new issue will be created from an existing one if copy_from parameter is given |
|
128 | # The new issue will be created from an existing one if copy_from parameter is given | |
129 | def new |
|
129 | def new | |
130 | @issue = Issue.new |
|
130 | @issue = Issue.new | |
131 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
131 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
132 | @issue.project = @project |
|
132 | @issue.project = @project | |
133 | # Tracker must be set before custom field values |
|
133 | # Tracker must be set before custom field values | |
134 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
134 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
135 | if @issue.tracker.nil? |
|
135 | if @issue.tracker.nil? | |
136 | render_error l(:error_no_tracker_in_project) |
|
136 | render_error l(:error_no_tracker_in_project) | |
137 | return |
|
137 | return | |
138 | end |
|
138 | end | |
139 | if @issue.status.nil? |
|
139 | if @issue.status.nil? | |
140 | render_error l(:error_no_default_issue_status) |
|
140 | render_error l(:error_no_default_issue_status) | |
141 | return |
|
141 | return | |
142 | end |
|
142 | end | |
143 | if params[:issue].is_a?(Hash) |
|
143 | if params[:issue].is_a?(Hash) | |
144 | @issue.safe_attributes = params[:issue] |
|
144 | @issue.safe_attributes = params[:issue] | |
145 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) |
|
145 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
146 | end |
|
146 | end | |
147 | @issue.author = User.current |
|
147 | @issue.author = User.current | |
148 |
|
148 | |||
149 | if request.get? || request.xhr? |
|
149 | if request.get? || request.xhr? | |
150 | @issue.start_date ||= Date.today |
|
150 | @issue.start_date ||= Date.today | |
151 | else |
|
151 | else | |
152 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
152 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | |
153 | if @issue.save |
|
153 | if @issue.save | |
154 | attachments = Attachment.attach_files(@issue, params[:attachments]) |
|
154 | attachments = Attachment.attach_files(@issue, params[:attachments]) | |
155 | render_attachment_warning_if_needed(@issue) |
|
155 | render_attachment_warning_if_needed(@issue) | |
156 | flash[:notice] = l(:notice_successful_create) |
|
156 | flash[:notice] = l(:notice_successful_create) | |
157 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
157 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | |
158 | respond_to do |format| |
|
158 | respond_to do |format| | |
159 | format.html { |
|
159 | format.html { | |
160 | redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, |
|
160 | redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, | |
161 | :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : |
|
161 | :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : | |
162 | { :action => 'show', :id => @issue }) |
|
162 | { :action => 'show', :id => @issue }) | |
163 | } |
|
163 | } | |
164 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } |
|
164 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } | |
165 | end |
|
165 | end | |
166 | return |
|
166 | return | |
167 | else |
|
167 | else | |
168 | respond_to do |format| |
|
168 | respond_to do |format| | |
169 | format.html { } |
|
169 | format.html { } | |
170 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } |
|
170 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } | |
171 | end |
|
171 | end | |
172 | end |
|
172 | end | |
173 | end |
|
173 | end | |
174 | @priorities = IssuePriority.all |
|
174 | @priorities = IssuePriority.all | |
175 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) |
|
175 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
176 | render :layout => !request.xhr? |
|
176 | render :layout => !request.xhr? | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
179 | # Attributes that can be updated on workflow transition (without :edit permission) | |
180 | # TODO: make it configurable (at least per role) |
|
180 | # TODO: make it configurable (at least per role) | |
181 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
181 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) | |
182 |
|
182 | |||
183 | def edit |
|
183 | def edit | |
184 | update_issue_from_params |
|
184 | update_issue_from_params | |
185 |
|
185 | |||
186 | @journal = @issue.current_journal |
|
186 | @journal = @issue.current_journal | |
187 |
|
187 | |||
188 | respond_to do |format| |
|
188 | respond_to do |format| | |
189 | format.html { } |
|
189 | format.html { } | |
190 | format.xml { } |
|
190 | format.xml { } | |
191 | end |
|
191 | end | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def update |
|
194 | def update | |
195 | update_issue_from_params |
|
195 | update_issue_from_params | |
196 |
|
196 | |||
197 | if @issue.save_issue_with_child_records(params, @time_entry) |
|
197 | if @issue.save_issue_with_child_records(params, @time_entry) | |
198 | render_attachment_warning_if_needed(@issue) |
|
198 | render_attachment_warning_if_needed(@issue) | |
199 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
199 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
200 |
|
200 | |||
201 | respond_to do |format| |
|
201 | respond_to do |format| | |
202 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
202 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | |
203 | format.xml { head :ok } |
|
203 | format.xml { head :ok } | |
204 | end |
|
204 | end | |
205 | else |
|
205 | else | |
206 | render_attachment_warning_if_needed(@issue) |
|
206 | render_attachment_warning_if_needed(@issue) | |
207 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
207 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
208 | @journal = @issue.current_journal |
|
208 | @journal = @issue.current_journal | |
209 |
|
209 | |||
210 | respond_to do |format| |
|
210 | respond_to do |format| | |
211 | format.html { render :action => 'edit' } |
|
211 | format.html { render :action => 'edit' } | |
212 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } |
|
212 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } | |
213 | end |
|
213 | end | |
214 | end |
|
214 | end | |
215 |
|
215 | |||
216 | rescue ActiveRecord::StaleObjectError |
|
216 | rescue ActiveRecord::StaleObjectError | |
217 | # Optimistic locking exception |
|
217 | # Optimistic locking exception | |
218 | flash.now[:error] = l(:notice_locking_conflict) |
|
218 | flash.now[:error] = l(:notice_locking_conflict) | |
219 | # Remove the previously added attachments if issue was not updated |
|
219 | # Remove the previously added attachments if issue was not updated | |
220 | attachments[:files].each(&:destroy) if attachments[:files] |
|
220 | attachments[:files].each(&:destroy) if attachments[:files] | |
221 | end |
|
221 | end | |
222 |
|
222 | |||
223 | def reply |
|
223 | def reply | |
224 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
224 | journal = Journal.find(params[:journal_id]) if params[:journal_id] | |
225 | if journal |
|
225 | if journal | |
226 | user = journal.user |
|
226 | user = journal.user | |
227 | text = journal.notes |
|
227 | text = journal.notes | |
228 | else |
|
228 | else | |
229 | user = @issue.author |
|
229 | user = @issue.author | |
230 | text = @issue.description |
|
230 | text = @issue.description | |
231 | end |
|
231 | end | |
232 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " |
|
232 | # Replaces pre blocks with [...] | |
233 |
|
|
233 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') | |
|
234 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " | |||
|
235 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" | |||
|
236 | ||||
234 | render(:update) { |page| |
|
237 | render(:update) { |page| | |
235 | page.<< "$('notes').value = \"#{content}\";" |
|
238 | page.<< "$('notes').value = \"#{escape_javascript content}\";" | |
236 | page.show 'update' |
|
239 | page.show 'update' | |
237 | page << "Form.Element.focus('notes');" |
|
240 | page << "Form.Element.focus('notes');" | |
238 | page << "Element.scrollTo('update');" |
|
241 | page << "Element.scrollTo('update');" | |
239 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
242 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" | |
240 | } |
|
243 | } | |
241 | end |
|
244 | end | |
242 |
|
245 | |||
243 | # Bulk edit a set of issues |
|
246 | # Bulk edit a set of issues | |
244 | def bulk_edit |
|
247 | def bulk_edit | |
245 | @issues.sort! |
|
248 | @issues.sort! | |
246 | if request.post? |
|
249 | if request.post? | |
247 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} |
|
250 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} | |
248 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} |
|
251 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} | |
249 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] |
|
252 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] | |
250 |
|
253 | |||
251 | unsaved_issue_ids = [] |
|
254 | unsaved_issue_ids = [] | |
252 | @issues.each do |issue| |
|
255 | @issues.each do |issue| | |
253 | issue.reload |
|
256 | issue.reload | |
254 | journal = issue.init_journal(User.current, params[:notes]) |
|
257 | journal = issue.init_journal(User.current, params[:notes]) | |
255 | issue.safe_attributes = attributes |
|
258 | issue.safe_attributes = attributes | |
256 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
259 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) | |
257 | unless issue.save |
|
260 | unless issue.save | |
258 | # Keep unsaved issue ids to display them in flash error |
|
261 | # Keep unsaved issue ids to display them in flash error | |
259 | unsaved_issue_ids << issue.id |
|
262 | unsaved_issue_ids << issue.id | |
260 | end |
|
263 | end | |
261 | end |
|
264 | end | |
262 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
265 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
263 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) |
|
266 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) | |
264 | return |
|
267 | return | |
265 | end |
|
268 | end | |
266 | @available_statuses = Workflow.available_statuses(@project) |
|
269 | @available_statuses = Workflow.available_statuses(@project) | |
267 | @custom_fields = @project.all_issue_custom_fields |
|
270 | @custom_fields = @project.all_issue_custom_fields | |
268 | end |
|
271 | end | |
269 |
|
272 | |||
270 | def move |
|
273 | def move | |
271 | @issues.sort! |
|
274 | @issues.sort! | |
272 | @copy = params[:copy_options] && params[:copy_options][:copy] |
|
275 | @copy = params[:copy_options] && params[:copy_options][:copy] | |
273 | @allowed_projects = [] |
|
276 | @allowed_projects = [] | |
274 | # find projects to which the user is allowed to move the issue |
|
277 | # find projects to which the user is allowed to move the issue | |
275 | if User.current.admin? |
|
278 | if User.current.admin? | |
276 | # admin is allowed to move issues to any active (visible) project |
|
279 | # admin is allowed to move issues to any active (visible) project | |
277 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current)) |
|
280 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current)) | |
278 | else |
|
281 | else | |
279 | User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} |
|
282 | User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} | |
280 | end |
|
283 | end | |
281 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
284 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
282 | @target_project ||= @project |
|
285 | @target_project ||= @project | |
283 | @trackers = @target_project.trackers |
|
286 | @trackers = @target_project.trackers | |
284 | @available_statuses = Workflow.available_statuses(@project) |
|
287 | @available_statuses = Workflow.available_statuses(@project) | |
285 | if request.post? |
|
288 | if request.post? | |
286 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
289 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
287 | unsaved_issue_ids = [] |
|
290 | unsaved_issue_ids = [] | |
288 | moved_issues = [] |
|
291 | moved_issues = [] | |
289 | @issues.each do |issue| |
|
292 | @issues.each do |issue| | |
290 | issue.reload |
|
293 | issue.reload | |
291 | changed_attributes = {} |
|
294 | changed_attributes = {} | |
292 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| |
|
295 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| | |
293 | unless params[valid_attribute].blank? |
|
296 | unless params[valid_attribute].blank? | |
294 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) |
|
297 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) | |
295 | end |
|
298 | end | |
296 | end |
|
299 | end | |
297 | issue.init_journal(User.current) |
|
300 | issue.init_journal(User.current) | |
298 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) |
|
301 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) | |
299 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) |
|
302 | if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) | |
300 | moved_issues << r |
|
303 | moved_issues << r | |
301 | else |
|
304 | else | |
302 | unsaved_issue_ids << issue.id |
|
305 | unsaved_issue_ids << issue.id | |
303 | end |
|
306 | end | |
304 | end |
|
307 | end | |
305 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
308 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
306 |
|
309 | |||
307 | if params[:follow] |
|
310 | if params[:follow] | |
308 | if @issues.size == 1 && moved_issues.size == 1 |
|
311 | if @issues.size == 1 && moved_issues.size == 1 | |
309 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first |
|
312 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first | |
310 | else |
|
313 | else | |
311 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) |
|
314 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) | |
312 | end |
|
315 | end | |
313 | else |
|
316 | else | |
314 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
317 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
315 | end |
|
318 | end | |
316 | return |
|
319 | return | |
317 | end |
|
320 | end | |
318 | render :layout => false if request.xhr? |
|
321 | render :layout => false if request.xhr? | |
319 | end |
|
322 | end | |
320 |
|
323 | |||
321 | def destroy |
|
324 | def destroy | |
322 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
325 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
323 | if @hours > 0 |
|
326 | if @hours > 0 | |
324 | case params[:todo] |
|
327 | case params[:todo] | |
325 | when 'destroy' |
|
328 | when 'destroy' | |
326 | # nothing to do |
|
329 | # nothing to do | |
327 | when 'nullify' |
|
330 | when 'nullify' | |
328 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
331 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
329 | when 'reassign' |
|
332 | when 'reassign' | |
330 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
333 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
331 | if reassign_to.nil? |
|
334 | if reassign_to.nil? | |
332 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
335 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
333 | return |
|
336 | return | |
334 | else |
|
337 | else | |
335 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
338 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
336 | end |
|
339 | end | |
337 | else |
|
340 | else | |
338 | unless params[:format] == 'xml' |
|
341 | unless params[:format] == 'xml' | |
339 | # display the destroy form if it's a user request |
|
342 | # display the destroy form if it's a user request | |
340 | return |
|
343 | return | |
341 | end |
|
344 | end | |
342 | end |
|
345 | end | |
343 | end |
|
346 | end | |
344 | @issues.each(&:destroy) |
|
347 | @issues.each(&:destroy) | |
345 | respond_to do |format| |
|
348 | respond_to do |format| | |
346 | format.html { redirect_to :action => 'index', :project_id => @project } |
|
349 | format.html { redirect_to :action => 'index', :project_id => @project } | |
347 | format.xml { head :ok } |
|
350 | format.xml { head :ok } | |
348 | end |
|
351 | end | |
349 | end |
|
352 | end | |
350 |
|
353 | |||
351 | def gantt |
|
354 | def gantt | |
352 | @gantt = Redmine::Helpers::Gantt.new(params) |
|
355 | @gantt = Redmine::Helpers::Gantt.new(params) | |
353 | retrieve_query |
|
356 | retrieve_query | |
354 | @query.group_by = nil |
|
357 | @query.group_by = nil | |
355 | if @query.valid? |
|
358 | if @query.valid? | |
356 | events = [] |
|
359 | events = [] | |
357 | # Issues that have start and due dates |
|
360 | # Issues that have start and due dates | |
358 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
361 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], | |
359 | :order => "start_date, due_date", |
|
362 | :order => "start_date, due_date", | |
360 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] |
|
363 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] | |
361 | ) |
|
364 | ) | |
362 | # Issues that don't have a due date but that are assigned to a version with a date |
|
365 | # Issues that don't have a due date but that are assigned to a version with a date | |
363 | events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version], |
|
366 | events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version], | |
364 | :order => "start_date, effective_date", |
|
367 | :order => "start_date, effective_date", | |
365 | :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] |
|
368 | :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] | |
366 | ) |
|
369 | ) | |
367 | # Versions |
|
370 | # Versions | |
368 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) |
|
371 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) | |
369 |
|
372 | |||
370 | @gantt.events = events |
|
373 | @gantt.events = events | |
371 | end |
|
374 | end | |
372 |
|
375 | |||
373 | basename = (@project ? "#{@project.identifier}-" : '') + 'gantt' |
|
376 | basename = (@project ? "#{@project.identifier}-" : '') + 'gantt' | |
374 |
|
377 | |||
375 | respond_to do |format| |
|
378 | respond_to do |format| | |
376 | format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? } |
|
379 | format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? } | |
377 | format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image') |
|
380 | format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image') | |
378 | format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") } |
|
381 | format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") } | |
379 | end |
|
382 | end | |
380 | end |
|
383 | end | |
381 |
|
384 | |||
382 | def calendar |
|
385 | def calendar | |
383 | if params[:year] and params[:year].to_i > 1900 |
|
386 | if params[:year] and params[:year].to_i > 1900 | |
384 | @year = params[:year].to_i |
|
387 | @year = params[:year].to_i | |
385 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
388 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
386 | @month = params[:month].to_i |
|
389 | @month = params[:month].to_i | |
387 | end |
|
390 | end | |
388 | end |
|
391 | end | |
389 | @year ||= Date.today.year |
|
392 | @year ||= Date.today.year | |
390 | @month ||= Date.today.month |
|
393 | @month ||= Date.today.month | |
391 |
|
394 | |||
392 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
395 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) | |
393 | retrieve_query |
|
396 | retrieve_query | |
394 | @query.group_by = nil |
|
397 | @query.group_by = nil | |
395 | if @query.valid? |
|
398 | if @query.valid? | |
396 | events = [] |
|
399 | events = [] | |
397 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
400 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], | |
398 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
401 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] | |
399 | ) |
|
402 | ) | |
400 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
403 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) | |
401 |
|
404 | |||
402 | @calendar.events = events |
|
405 | @calendar.events = events | |
403 | end |
|
406 | end | |
404 |
|
407 | |||
405 | render :layout => false if request.xhr? |
|
408 | render :layout => false if request.xhr? | |
406 | end |
|
409 | end | |
407 |
|
410 | |||
408 | def context_menu |
|
411 | def context_menu | |
409 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) |
|
412 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) | |
410 | if (@issues.size == 1) |
|
413 | if (@issues.size == 1) | |
411 | @issue = @issues.first |
|
414 | @issue = @issues.first | |
412 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
415 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
413 | end |
|
416 | end | |
414 | projects = @issues.collect(&:project).compact.uniq |
|
417 | projects = @issues.collect(&:project).compact.uniq | |
415 | @project = projects.first if projects.size == 1 |
|
418 | @project = projects.first if projects.size == 1 | |
416 |
|
419 | |||
417 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), |
|
420 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), | |
418 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
421 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), | |
419 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), |
|
422 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), | |
420 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
423 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), | |
421 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
424 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), | |
422 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) |
|
425 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) | |
423 | } |
|
426 | } | |
424 | if @project |
|
427 | if @project | |
425 | @assignables = @project.assignable_users |
|
428 | @assignables = @project.assignable_users | |
426 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
429 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) | |
427 | @trackers = @project.trackers |
|
430 | @trackers = @project.trackers | |
428 | end |
|
431 | end | |
429 |
|
432 | |||
430 | @priorities = IssuePriority.all.reverse |
|
433 | @priorities = IssuePriority.all.reverse | |
431 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
434 | @statuses = IssueStatus.find(:all, :order => 'position') | |
432 | @back = params[:back_url] || request.env['HTTP_REFERER'] |
|
435 | @back = params[:back_url] || request.env['HTTP_REFERER'] | |
433 |
|
436 | |||
434 | render :layout => false |
|
437 | render :layout => false | |
435 | end |
|
438 | end | |
436 |
|
439 | |||
437 | def update_form |
|
440 | def update_form | |
438 | if params[:id].blank? |
|
441 | if params[:id].blank? | |
439 | @issue = Issue.new |
|
442 | @issue = Issue.new | |
440 | @issue.project = @project |
|
443 | @issue.project = @project | |
441 | else |
|
444 | else | |
442 | @issue = @project.issues.visible.find(params[:id]) |
|
445 | @issue = @project.issues.visible.find(params[:id]) | |
443 | end |
|
446 | end | |
444 | @issue.attributes = params[:issue] |
|
447 | @issue.attributes = params[:issue] | |
445 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq |
|
448 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq | |
446 | @priorities = IssuePriority.all |
|
449 | @priorities = IssuePriority.all | |
447 |
|
450 | |||
448 | render :partial => 'attributes' |
|
451 | render :partial => 'attributes' | |
449 | end |
|
452 | end | |
450 |
|
453 | |||
451 | def preview |
|
454 | def preview | |
452 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
455 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
453 | @attachements = @issue.attachments if @issue |
|
456 | @attachements = @issue.attachments if @issue | |
454 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) |
|
457 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) | |
455 | render :partial => 'common/preview' |
|
458 | render :partial => 'common/preview' | |
456 | end |
|
459 | end | |
457 |
|
460 | |||
458 | def auto_complete |
|
461 | def auto_complete | |
459 | @issues = [] |
|
462 | @issues = [] | |
460 | q = params[:q].to_s |
|
463 | q = params[:q].to_s | |
461 | if q.match(/^\d+$/) |
|
464 | if q.match(/^\d+$/) | |
462 | @issues << @project.issues.visible.find_by_id(q.to_i) |
|
465 | @issues << @project.issues.visible.find_by_id(q.to_i) | |
463 | end |
|
466 | end | |
464 | unless q.blank? |
|
467 | unless q.blank? | |
465 | @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10) |
|
468 | @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10) | |
466 | end |
|
469 | end | |
467 | render :layout => false |
|
470 | render :layout => false | |
468 | end |
|
471 | end | |
469 |
|
472 | |||
470 | private |
|
473 | private | |
471 | def find_issue |
|
474 | def find_issue | |
472 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
475 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
473 | @project = @issue.project |
|
476 | @project = @issue.project | |
474 | rescue ActiveRecord::RecordNotFound |
|
477 | rescue ActiveRecord::RecordNotFound | |
475 | render_404 |
|
478 | render_404 | |
476 | end |
|
479 | end | |
477 |
|
480 | |||
478 | # Filter for bulk operations |
|
481 | # Filter for bulk operations | |
479 | def find_issues |
|
482 | def find_issues | |
480 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
483 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
481 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
484 | raise ActiveRecord::RecordNotFound if @issues.empty? | |
482 | projects = @issues.collect(&:project).compact.uniq |
|
485 | projects = @issues.collect(&:project).compact.uniq | |
483 | if projects.size == 1 |
|
486 | if projects.size == 1 | |
484 | @project = projects.first |
|
487 | @project = projects.first | |
485 | else |
|
488 | else | |
486 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
489 | # TODO: let users bulk edit/move/destroy issues from different projects | |
487 | render_error 'Can not bulk edit/move/destroy issues from different projects' |
|
490 | render_error 'Can not bulk edit/move/destroy issues from different projects' | |
488 | return false |
|
491 | return false | |
489 | end |
|
492 | end | |
490 | rescue ActiveRecord::RecordNotFound |
|
493 | rescue ActiveRecord::RecordNotFound | |
491 | render_404 |
|
494 | render_404 | |
492 | end |
|
495 | end | |
493 |
|
496 | |||
494 | def find_project |
|
497 | def find_project | |
495 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
498 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] | |
496 | @project = Project.find(project_id) |
|
499 | @project = Project.find(project_id) | |
497 | rescue ActiveRecord::RecordNotFound |
|
500 | rescue ActiveRecord::RecordNotFound | |
498 | render_404 |
|
501 | render_404 | |
499 | end |
|
502 | end | |
500 |
|
503 | |||
501 | def find_optional_project |
|
504 | def find_optional_project | |
502 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? |
|
505 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? | |
503 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) |
|
506 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) | |
504 | allowed ? true : deny_access |
|
507 | allowed ? true : deny_access | |
505 | rescue ActiveRecord::RecordNotFound |
|
508 | rescue ActiveRecord::RecordNotFound | |
506 | render_404 |
|
509 | render_404 | |
507 | end |
|
510 | end | |
508 |
|
511 | |||
509 | # Retrieve query from session or build a new query |
|
512 | # Retrieve query from session or build a new query | |
510 | def retrieve_query |
|
513 | def retrieve_query | |
511 | if !params[:query_id].blank? |
|
514 | if !params[:query_id].blank? | |
512 | cond = "project_id IS NULL" |
|
515 | cond = "project_id IS NULL" | |
513 | cond << " OR project_id = #{@project.id}" if @project |
|
516 | cond << " OR project_id = #{@project.id}" if @project | |
514 | @query = Query.find(params[:query_id], :conditions => cond) |
|
517 | @query = Query.find(params[:query_id], :conditions => cond) | |
515 | @query.project = @project |
|
518 | @query.project = @project | |
516 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
519 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
517 | sort_clear |
|
520 | sort_clear | |
518 | else |
|
521 | else | |
519 | if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
522 | if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
520 | # Give it a name, required to be valid |
|
523 | # Give it a name, required to be valid | |
521 | @query = Query.new(:name => "_") |
|
524 | @query = Query.new(:name => "_") | |
522 | @query.project = @project |
|
525 | @query.project = @project | |
523 | if params[:fields] and params[:fields].is_a? Array |
|
526 | if params[:fields] and params[:fields].is_a? Array | |
524 | params[:fields].each do |field| |
|
527 | params[:fields].each do |field| | |
525 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
528 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
526 | end |
|
529 | end | |
527 | else |
|
530 | else | |
528 | @query.available_filters.keys.each do |field| |
|
531 | @query.available_filters.keys.each do |field| | |
529 | @query.add_short_filter(field, params[field]) if params[field] |
|
532 | @query.add_short_filter(field, params[field]) if params[field] | |
530 | end |
|
533 | end | |
531 | end |
|
534 | end | |
532 | @query.group_by = params[:group_by] |
|
535 | @query.group_by = params[:group_by] | |
533 | @query.column_names = params[:query] && params[:query][:column_names] |
|
536 | @query.column_names = params[:query] && params[:query][:column_names] | |
534 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} |
|
537 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
535 | else |
|
538 | else | |
536 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
539 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
537 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
540 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
538 | @query.project = @project |
|
541 | @query.project = @project | |
539 | end |
|
542 | end | |
540 | end |
|
543 | end | |
541 | end |
|
544 | end | |
542 |
|
545 | |||
543 | # Rescues an invalid query statement. Just in case... |
|
546 | # Rescues an invalid query statement. Just in case... | |
544 | def query_statement_invalid(exception) |
|
547 | def query_statement_invalid(exception) | |
545 | logger.error "Query::StatementInvalid: #{exception.message}" if logger |
|
548 | logger.error "Query::StatementInvalid: #{exception.message}" if logger | |
546 | session.delete(:query) |
|
549 | session.delete(:query) | |
547 | sort_clear |
|
550 | sort_clear | |
548 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." |
|
551 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." | |
549 | end |
|
552 | end | |
550 |
|
553 | |||
551 | # Used by #edit and #update to set some common instance variables |
|
554 | # Used by #edit and #update to set some common instance variables | |
552 | # from the params |
|
555 | # from the params | |
553 | # TODO: Refactor, not everything in here is needed by #edit |
|
556 | # TODO: Refactor, not everything in here is needed by #edit | |
554 | def update_issue_from_params |
|
557 | def update_issue_from_params | |
555 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
558 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
556 | @priorities = IssuePriority.all |
|
559 | @priorities = IssuePriority.all | |
557 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
560 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
558 | @time_entry = TimeEntry.new |
|
561 | @time_entry = TimeEntry.new | |
559 |
|
562 | |||
560 | @notes = params[:notes] |
|
563 | @notes = params[:notes] | |
561 | @issue.init_journal(User.current, @notes) |
|
564 | @issue.init_journal(User.current, @notes) | |
562 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
565 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |
563 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
566 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |
564 | attrs = params[:issue].dup |
|
567 | attrs = params[:issue].dup | |
565 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
568 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |
566 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
569 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |
567 | @issue.safe_attributes = attrs |
|
570 | @issue.safe_attributes = attrs | |
568 | end |
|
571 | end | |
569 |
|
572 | |||
570 | end |
|
573 | end | |
571 |
|
574 | |||
572 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) |
|
575 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) | |
573 | if unsaved_issue_ids.empty? |
|
576 | if unsaved_issue_ids.empty? | |
574 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
|
577 | flash[:notice] = l(:notice_successful_update) unless issues.empty? | |
575 | else |
|
578 | else | |
576 | flash[:error] = l(:notice_failed_to_save_issues, |
|
579 | flash[:error] = l(:notice_failed_to_save_issues, | |
577 | :count => unsaved_issue_ids.size, |
|
580 | :count => unsaved_issue_ids.size, | |
578 | :total => issues.size, |
|
581 | :total => issues.size, | |
579 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
582 | :ids => '#' + unsaved_issue_ids.join(', #')) | |
580 | end |
|
583 | end | |
581 | end |
|
584 | end | |
582 | end |
|
585 | end |
General Comments 0
You need to be logged in to leave comments.
Login now