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