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