##// END OF EJS Templates
IssuesController#destroy accepts POST only (#4107)....
Jean-Philippe Lang -
r2866:9aa2b6b9a464
parent child
Show More
@@ -1,509 +1,513
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, :reply]
22 before_filter :find_issue, :only => [:show, :edit, :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]
24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu]
25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :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 helper :journals
29 helper :journals
30 helper :projects
30 helper :projects
31 include ProjectsHelper
31 include ProjectsHelper
32 helper :custom_fields
32 helper :custom_fields
33 include CustomFieldsHelper
33 include CustomFieldsHelper
34 helper :issue_relations
34 helper :issue_relations
35 include IssueRelationsHelper
35 include IssueRelationsHelper
36 helper :watchers
36 helper :watchers
37 include WatchersHelper
37 include WatchersHelper
38 helper :attachments
38 helper :attachments
39 include AttachmentsHelper
39 include AttachmentsHelper
40 helper :queries
40 helper :queries
41 helper :sort
41 helper :sort
42 include SortHelper
42 include SortHelper
43 include IssuesHelper
43 include IssuesHelper
44 helper :timelog
44 helper :timelog
45 include Redmine::Export::PDF
45 include Redmine::Export::PDF
46
46
47 verify :method => :post,
48 :only => :destroy,
49 :render => { :nothing => true, :status => :method_not_allowed }
50
47 def index
51 def index
48 retrieve_query
52 retrieve_query
49 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
53 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
50 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
54 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
51
55
52 if @query.valid?
56 if @query.valid?
53 limit = per_page_option
57 limit = per_page_option
54 respond_to do |format|
58 respond_to do |format|
55 format.html { }
59 format.html { }
56 format.atom { }
60 format.atom { }
57 format.csv { limit = Setting.issues_export_limit.to_i }
61 format.csv { limit = Setting.issues_export_limit.to_i }
58 format.pdf { limit = Setting.issues_export_limit.to_i }
62 format.pdf { limit = Setting.issues_export_limit.to_i }
59 end
63 end
60 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
64 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
61 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
65 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
62 @issues = Issue.find :all, :order => [@query.group_by_sort_order, sort_clause].compact.join(','),
66 @issues = Issue.find :all, :order => [@query.group_by_sort_order, sort_clause].compact.join(','),
63 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
67 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
64 :conditions => @query.statement,
68 :conditions => @query.statement,
65 :limit => limit,
69 :limit => limit,
66 :offset => @issue_pages.current.offset
70 :offset => @issue_pages.current.offset
67 respond_to do |format|
71 respond_to do |format|
68 format.html {
72 format.html {
69 if @query.grouped?
73 if @query.grouped?
70 # Retrieve the issue count by group
74 # Retrieve the issue count by group
71 @issue_count_by_group = begin
75 @issue_count_by_group = begin
72 Issue.count(:group => @query.group_by, :include => [:status, :project], :conditions => @query.statement)
76 Issue.count(:group => @query.group_by, :include => [:status, :project], :conditions => @query.statement)
73 # Rails will raise an (unexpected) error if there's only a nil group value
77 # Rails will raise an (unexpected) error if there's only a nil group value
74 rescue ActiveRecord::RecordNotFound
78 rescue ActiveRecord::RecordNotFound
75 {nil => @issue_count}
79 {nil => @issue_count}
76 end
80 end
77 end
81 end
78 render :template => 'issues/index.rhtml', :layout => !request.xhr?
82 render :template => 'issues/index.rhtml', :layout => !request.xhr?
79 }
83 }
80 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
84 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
81 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
85 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
82 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
86 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
83 end
87 end
84 else
88 else
85 # Send html if the query is not valid
89 # Send html if the query is not valid
86 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
90 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
87 end
91 end
88 rescue ActiveRecord::RecordNotFound
92 rescue ActiveRecord::RecordNotFound
89 render_404
93 render_404
90 end
94 end
91
95
92 def changes
96 def changes
93 retrieve_query
97 retrieve_query
94 sort_init 'id', 'desc'
98 sort_init 'id', 'desc'
95 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
99 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
96
100
97 if @query.valid?
101 if @query.valid?
98 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
102 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
99 :conditions => @query.statement,
103 :conditions => @query.statement,
100 :limit => 25,
104 :limit => 25,
101 :order => "#{Journal.table_name}.created_on DESC"
105 :order => "#{Journal.table_name}.created_on DESC"
102 end
106 end
103 @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)
104 render :layout => false, :content_type => 'application/atom+xml'
108 render :layout => false, :content_type => 'application/atom+xml'
105 rescue ActiveRecord::RecordNotFound
109 rescue ActiveRecord::RecordNotFound
106 render_404
110 render_404
107 end
111 end
108
112
109 def show
113 def show
110 @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")
111 @journals.each_with_index {|j,i| j.indice = i+1}
115 @journals.each_with_index {|j,i| j.indice = i+1}
112 @journals.reverse! if User.current.wants_comments_in_reverse_order?
116 @journals.reverse! if User.current.wants_comments_in_reverse_order?
113 @changesets = @issue.changesets
117 @changesets = @issue.changesets
114 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
118 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
115 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
119 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
116 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
120 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
117 @priorities = IssuePriority.all
121 @priorities = IssuePriority.all
118 @time_entry = TimeEntry.new
122 @time_entry = TimeEntry.new
119 respond_to do |format|
123 respond_to do |format|
120 format.html { render :template => 'issues/show.rhtml' }
124 format.html { render :template => 'issues/show.rhtml' }
121 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
125 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
122 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
126 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
123 end
127 end
124 end
128 end
125
129
126 # Add a new issue
130 # Add a new issue
127 # The new issue will be created from an existing one if copy_from parameter is given
131 # The new issue will be created from an existing one if copy_from parameter is given
128 def new
132 def new
129 @issue = Issue.new
133 @issue = Issue.new
130 @issue.copy_from(params[:copy_from]) if params[:copy_from]
134 @issue.copy_from(params[:copy_from]) if params[:copy_from]
131 @issue.project = @project
135 @issue.project = @project
132 # Tracker must be set before custom field values
136 # Tracker must be set before custom field values
133 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
137 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
134 if @issue.tracker.nil?
138 if @issue.tracker.nil?
135 render_error l(:error_no_tracker_in_project)
139 render_error l(:error_no_tracker_in_project)
136 return
140 return
137 end
141 end
138 if params[:issue].is_a?(Hash)
142 if params[:issue].is_a?(Hash)
139 @issue.attributes = params[:issue]
143 @issue.attributes = params[:issue]
140 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
144 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
141 end
145 end
142 @issue.author = User.current
146 @issue.author = User.current
143
147
144 default_status = IssueStatus.default
148 default_status = IssueStatus.default
145 unless default_status
149 unless default_status
146 render_error l(:error_no_default_issue_status)
150 render_error l(:error_no_default_issue_status)
147 return
151 return
148 end
152 end
149 @issue.status = default_status
153 @issue.status = default_status
150 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
154 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
151
155
152 if request.get? || request.xhr?
156 if request.get? || request.xhr?
153 @issue.start_date ||= Date.today
157 @issue.start_date ||= Date.today
154 else
158 else
155 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
159 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
156 # Check that the user is allowed to apply the requested status
160 # Check that the user is allowed to apply the requested status
157 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
161 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
158 if @issue.save
162 if @issue.save
159 attach_files(@issue, params[:attachments])
163 attach_files(@issue, params[:attachments])
160 flash[:notice] = l(:notice_successful_create)
164 flash[:notice] = l(:notice_successful_create)
161 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
165 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
162 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
166 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
163 { :action => 'show', :id => @issue })
167 { :action => 'show', :id => @issue })
164 return
168 return
165 end
169 end
166 end
170 end
167 @priorities = IssuePriority.all
171 @priorities = IssuePriority.all
168 render :layout => !request.xhr?
172 render :layout => !request.xhr?
169 end
173 end
170
174
171 # Attributes that can be updated on workflow transition (without :edit permission)
175 # Attributes that can be updated on workflow transition (without :edit permission)
172 # TODO: make it configurable (at least per role)
176 # TODO: make it configurable (at least per role)
173 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
177 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
174
178
175 def edit
179 def edit
176 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
180 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
177 @priorities = IssuePriority.all
181 @priorities = IssuePriority.all
178 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
182 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
179 @time_entry = TimeEntry.new
183 @time_entry = TimeEntry.new
180
184
181 @notes = params[:notes]
185 @notes = params[:notes]
182 journal = @issue.init_journal(User.current, @notes)
186 journal = @issue.init_journal(User.current, @notes)
183 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
187 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
184 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
188 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
185 attrs = params[:issue].dup
189 attrs = params[:issue].dup
186 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
190 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
187 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
191 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
188 @issue.attributes = attrs
192 @issue.attributes = attrs
189 end
193 end
190
194
191 if request.post?
195 if request.post?
192 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
196 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
193 @time_entry.attributes = params[:time_entry]
197 @time_entry.attributes = params[:time_entry]
194 attachments = attach_files(@issue, params[:attachments])
198 attachments = attach_files(@issue, params[:attachments])
195 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
199 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
196
200
197 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
201 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
198
202
199 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
203 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
200 # Log spend time
204 # Log spend time
201 if User.current.allowed_to?(:log_time, @project)
205 if User.current.allowed_to?(:log_time, @project)
202 @time_entry.save
206 @time_entry.save
203 end
207 end
204 if !journal.new_record?
208 if !journal.new_record?
205 # Only send notification if something was actually changed
209 # Only send notification if something was actually changed
206 flash[:notice] = l(:notice_successful_update)
210 flash[:notice] = l(:notice_successful_update)
207 end
211 end
208 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
212 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
209 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
213 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
210 end
214 end
211 end
215 end
212 rescue ActiveRecord::StaleObjectError
216 rescue ActiveRecord::StaleObjectError
213 # Optimistic locking exception
217 # Optimistic locking exception
214 flash.now[:error] = l(:notice_locking_conflict)
218 flash.now[:error] = l(:notice_locking_conflict)
215 # Remove the previously added attachments if issue was not updated
219 # Remove the previously added attachments if issue was not updated
216 attachments.each(&:destroy)
220 attachments.each(&:destroy)
217 end
221 end
218
222
219 def reply
223 def reply
220 journal = Journal.find(params[:journal_id]) if params[:journal_id]
224 journal = Journal.find(params[:journal_id]) if params[:journal_id]
221 if journal
225 if journal
222 user = journal.user
226 user = journal.user
223 text = journal.notes
227 text = journal.notes
224 else
228 else
225 user = @issue.author
229 user = @issue.author
226 text = @issue.description
230 text = @issue.description
227 end
231 end
228 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
232 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
229 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
233 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
230 render(:update) { |page|
234 render(:update) { |page|
231 page.<< "$('notes').value = \"#{content}\";"
235 page.<< "$('notes').value = \"#{content}\";"
232 page.show 'update'
236 page.show 'update'
233 page << "Form.Element.focus('notes');"
237 page << "Form.Element.focus('notes');"
234 page << "Element.scrollTo('update');"
238 page << "Element.scrollTo('update');"
235 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
239 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
236 }
240 }
237 end
241 end
238
242
239 # Bulk edit a set of issues
243 # Bulk edit a set of issues
240 def bulk_edit
244 def bulk_edit
241 if request.post?
245 if request.post?
242 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
246 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
243 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
247 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
244 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
248 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
245 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
249 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
246 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
250 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
247 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
251 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
248
252
249 unsaved_issue_ids = []
253 unsaved_issue_ids = []
250 @issues.each do |issue|
254 @issues.each do |issue|
251 journal = issue.init_journal(User.current, params[:notes])
255 journal = issue.init_journal(User.current, params[:notes])
252 issue.priority = priority if priority
256 issue.priority = priority if priority
253 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
257 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
254 issue.category = category if category || params[:category_id] == 'none'
258 issue.category = category if category || params[:category_id] == 'none'
255 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
259 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
256 issue.start_date = params[:start_date] unless params[:start_date].blank?
260 issue.start_date = params[:start_date] unless params[:start_date].blank?
257 issue.due_date = params[:due_date] unless params[:due_date].blank?
261 issue.due_date = params[:due_date] unless params[:due_date].blank?
258 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
262 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
259 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
263 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
260 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
264 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
261 # Don't save any change to the issue if the user is not authorized to apply the requested status
265 # Don't save any change to the issue if the user is not authorized to apply the requested status
262 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
266 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
263 # Keep unsaved issue ids to display them in flash error
267 # Keep unsaved issue ids to display them in flash error
264 unsaved_issue_ids << issue.id
268 unsaved_issue_ids << issue.id
265 end
269 end
266 end
270 end
267 if unsaved_issue_ids.empty?
271 if unsaved_issue_ids.empty?
268 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
272 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
269 else
273 else
270 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
274 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
271 :total => @issues.size,
275 :total => @issues.size,
272 :ids => '#' + unsaved_issue_ids.join(', #'))
276 :ids => '#' + unsaved_issue_ids.join(', #'))
273 end
277 end
274 redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
278 redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
275 return
279 return
276 end
280 end
277 # Find potential statuses the user could be allowed to switch issues to
281 # Find potential statuses the user could be allowed to switch issues to
278 @available_statuses = Workflow.find(:all, :include => :new_status,
282 @available_statuses = Workflow.find(:all, :include => :new_status,
279 :conditions => {:role_id => User.current.roles_for_project(@project).collect(&:id)}).collect(&:new_status).compact.uniq.sort
283 :conditions => {:role_id => User.current.roles_for_project(@project).collect(&:id)}).collect(&:new_status).compact.uniq.sort
280 @custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
284 @custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
281 end
285 end
282
286
283 def move
287 def move
284 @allowed_projects = []
288 @allowed_projects = []
285 # find projects to which the user is allowed to move the issue
289 # find projects to which the user is allowed to move the issue
286 if User.current.admin?
290 if User.current.admin?
287 # admin is allowed to move issues to any active (visible) project
291 # admin is allowed to move issues to any active (visible) project
288 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
292 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
289 else
293 else
290 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
294 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
291 end
295 end
292 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
296 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
293 @target_project ||= @project
297 @target_project ||= @project
294 @trackers = @target_project.trackers
298 @trackers = @target_project.trackers
295 if request.post?
299 if request.post?
296 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
300 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
297 unsaved_issue_ids = []
301 unsaved_issue_ids = []
298 @issues.each do |issue|
302 @issues.each do |issue|
299 issue.init_journal(User.current)
303 issue.init_journal(User.current)
300 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker, params[:copy_options])
304 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker, params[:copy_options])
301 end
305 end
302 if unsaved_issue_ids.empty?
306 if unsaved_issue_ids.empty?
303 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
307 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
304 else
308 else
305 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
309 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
306 :total => @issues.size,
310 :total => @issues.size,
307 :ids => '#' + unsaved_issue_ids.join(', #'))
311 :ids => '#' + unsaved_issue_ids.join(', #'))
308 end
312 end
309 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
313 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
310 return
314 return
311 end
315 end
312 render :layout => false if request.xhr?
316 render :layout => false if request.xhr?
313 end
317 end
314
318
315 def destroy
319 def destroy
316 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
320 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
317 if @hours > 0
321 if @hours > 0
318 case params[:todo]
322 case params[:todo]
319 when 'destroy'
323 when 'destroy'
320 # nothing to do
324 # nothing to do
321 when 'nullify'
325 when 'nullify'
322 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
326 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
323 when 'reassign'
327 when 'reassign'
324 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
328 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
325 if reassign_to.nil?
329 if reassign_to.nil?
326 flash.now[:error] = l(:error_issue_not_found_in_project)
330 flash.now[:error] = l(:error_issue_not_found_in_project)
327 return
331 return
328 else
332 else
329 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
333 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
330 end
334 end
331 else
335 else
332 # display the destroy form
336 # display the destroy form
333 return
337 return
334 end
338 end
335 end
339 end
336 @issues.each(&:destroy)
340 @issues.each(&:destroy)
337 redirect_to :action => 'index', :project_id => @project
341 redirect_to :action => 'index', :project_id => @project
338 end
342 end
339
343
340 def gantt
344 def gantt
341 @gantt = Redmine::Helpers::Gantt.new(params)
345 @gantt = Redmine::Helpers::Gantt.new(params)
342 retrieve_query
346 retrieve_query
343 if @query.valid?
347 if @query.valid?
344 events = []
348 events = []
345 # Issues that have start and due dates
349 # Issues that have start and due dates
346 events += Issue.find(:all,
350 events += Issue.find(:all,
347 :order => "start_date, due_date",
351 :order => "start_date, due_date",
348 :include => [:tracker, :status, :assigned_to, :priority, :project],
352 :include => [:tracker, :status, :assigned_to, :priority, :project],
349 :conditions => ["(#{@query.statement}) AND (((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]
353 :conditions => ["(#{@query.statement}) AND (((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]
350 )
354 )
351 # Issues that don't have a due date but that are assigned to a version with a date
355 # Issues that don't have a due date but that are assigned to a version with a date
352 events += Issue.find(:all,
356 events += Issue.find(:all,
353 :order => "start_date, effective_date",
357 :order => "start_date, effective_date",
354 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
358 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
355 :conditions => ["(#{@query.statement}) AND (((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]
359 :conditions => ["(#{@query.statement}) AND (((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]
356 )
360 )
357 # Versions
361 # Versions
358 events += Version.find(:all, :include => :project,
362 events += Version.find(:all, :include => :project,
359 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
363 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
360
364
361 @gantt.events = events
365 @gantt.events = events
362 end
366 end
363
367
364 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
368 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
365
369
366 respond_to do |format|
370 respond_to do |format|
367 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
371 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
368 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
372 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
369 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
373 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
370 end
374 end
371 end
375 end
372
376
373 def calendar
377 def calendar
374 if params[:year] and params[:year].to_i > 1900
378 if params[:year] and params[:year].to_i > 1900
375 @year = params[:year].to_i
379 @year = params[:year].to_i
376 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
380 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
377 @month = params[:month].to_i
381 @month = params[:month].to_i
378 end
382 end
379 end
383 end
380 @year ||= Date.today.year
384 @year ||= Date.today.year
381 @month ||= Date.today.month
385 @month ||= Date.today.month
382
386
383 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
387 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
384 retrieve_query
388 retrieve_query
385 if @query.valid?
389 if @query.valid?
386 events = []
390 events = []
387 events += Issue.find(:all,
391 events += Issue.find(:all,
388 :include => [:tracker, :status, :assigned_to, :priority, :project],
392 :include => [:tracker, :status, :assigned_to, :priority, :project],
389 :conditions => ["(#{@query.statement}) AND ((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
393 :conditions => ["(#{@query.statement}) AND ((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
390 )
394 )
391 events += Version.find(:all, :include => :project,
395 events += Version.find(:all, :include => :project,
392 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
396 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
393
397
394 @calendar.events = events
398 @calendar.events = events
395 end
399 end
396
400
397 render :layout => false if request.xhr?
401 render :layout => false if request.xhr?
398 end
402 end
399
403
400 def context_menu
404 def context_menu
401 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
405 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
402 if (@issues.size == 1)
406 if (@issues.size == 1)
403 @issue = @issues.first
407 @issue = @issues.first
404 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
408 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
405 end
409 end
406 projects = @issues.collect(&:project).compact.uniq
410 projects = @issues.collect(&:project).compact.uniq
407 @project = projects.first if projects.size == 1
411 @project = projects.first if projects.size == 1
408
412
409 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
413 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
410 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
414 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
411 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
415 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
412 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
416 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
413 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
417 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
414 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
418 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
415 }
419 }
416 if @project
420 if @project
417 @assignables = @project.assignable_users
421 @assignables = @project.assignable_users
418 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
422 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
419 end
423 end
420
424
421 @priorities = IssuePriority.all.reverse
425 @priorities = IssuePriority.all.reverse
422 @statuses = IssueStatus.find(:all, :order => 'position')
426 @statuses = IssueStatus.find(:all, :order => 'position')
423 @back = request.env['HTTP_REFERER']
427 @back = request.env['HTTP_REFERER']
424
428
425 render :layout => false
429 render :layout => false
426 end
430 end
427
431
428 def update_form
432 def update_form
429 @issue = Issue.new(params[:issue])
433 @issue = Issue.new(params[:issue])
430 render :action => :new, :layout => false
434 render :action => :new, :layout => false
431 end
435 end
432
436
433 def preview
437 def preview
434 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
438 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
435 @attachements = @issue.attachments if @issue
439 @attachements = @issue.attachments if @issue
436 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
440 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
437 render :partial => 'common/preview'
441 render :partial => 'common/preview'
438 end
442 end
439
443
440 private
444 private
441 def find_issue
445 def find_issue
442 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
446 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
443 @project = @issue.project
447 @project = @issue.project
444 rescue ActiveRecord::RecordNotFound
448 rescue ActiveRecord::RecordNotFound
445 render_404
449 render_404
446 end
450 end
447
451
448 # Filter for bulk operations
452 # Filter for bulk operations
449 def find_issues
453 def find_issues
450 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
454 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
451 raise ActiveRecord::RecordNotFound if @issues.empty?
455 raise ActiveRecord::RecordNotFound if @issues.empty?
452 projects = @issues.collect(&:project).compact.uniq
456 projects = @issues.collect(&:project).compact.uniq
453 if projects.size == 1
457 if projects.size == 1
454 @project = projects.first
458 @project = projects.first
455 else
459 else
456 # TODO: let users bulk edit/move/destroy issues from different projects
460 # TODO: let users bulk edit/move/destroy issues from different projects
457 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
461 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
458 end
462 end
459 rescue ActiveRecord::RecordNotFound
463 rescue ActiveRecord::RecordNotFound
460 render_404
464 render_404
461 end
465 end
462
466
463 def find_project
467 def find_project
464 @project = Project.find(params[:project_id])
468 @project = Project.find(params[:project_id])
465 rescue ActiveRecord::RecordNotFound
469 rescue ActiveRecord::RecordNotFound
466 render_404
470 render_404
467 end
471 end
468
472
469 def find_optional_project
473 def find_optional_project
470 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
474 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
471 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
475 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
472 allowed ? true : deny_access
476 allowed ? true : deny_access
473 rescue ActiveRecord::RecordNotFound
477 rescue ActiveRecord::RecordNotFound
474 render_404
478 render_404
475 end
479 end
476
480
477 # Retrieve query from session or build a new query
481 # Retrieve query from session or build a new query
478 def retrieve_query
482 def retrieve_query
479 if !params[:query_id].blank?
483 if !params[:query_id].blank?
480 cond = "project_id IS NULL"
484 cond = "project_id IS NULL"
481 cond << " OR project_id = #{@project.id}" if @project
485 cond << " OR project_id = #{@project.id}" if @project
482 @query = Query.find(params[:query_id], :conditions => cond)
486 @query = Query.find(params[:query_id], :conditions => cond)
483 @query.project = @project
487 @query.project = @project
484 session[:query] = {:id => @query.id, :project_id => @query.project_id}
488 session[:query] = {:id => @query.id, :project_id => @query.project_id}
485 sort_clear
489 sort_clear
486 else
490 else
487 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
491 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
488 # Give it a name, required to be valid
492 # Give it a name, required to be valid
489 @query = Query.new(:name => "_")
493 @query = Query.new(:name => "_")
490 @query.project = @project
494 @query.project = @project
491 if params[:fields] and params[:fields].is_a? Array
495 if params[:fields] and params[:fields].is_a? Array
492 params[:fields].each do |field|
496 params[:fields].each do |field|
493 @query.add_filter(field, params[:operators][field], params[:values][field])
497 @query.add_filter(field, params[:operators][field], params[:values][field])
494 end
498 end
495 else
499 else
496 @query.available_filters.keys.each do |field|
500 @query.available_filters.keys.each do |field|
497 @query.add_short_filter(field, params[field]) if params[field]
501 @query.add_short_filter(field, params[field]) if params[field]
498 end
502 end
499 end
503 end
500 @query.group_by = params[:group_by]
504 @query.group_by = params[:group_by]
501 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by}
505 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by}
502 else
506 else
503 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
507 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
504 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by])
508 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by])
505 @query.project = @project
509 @query.project = @project
506 end
510 end
507 end
511 end
508 end
512 end
509 end
513 end
General Comments 0
You need to be logged in to leave comments. Login now