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