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