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