Mercurial > hg > soundsoftware-site
comparison app/controllers/issues_controller.rb @ 37:94944d00e43c
* Update to SVN trunk rev 4411
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 19 Nov 2010 13:24:41 +0000 |
parents | 40f7cfd4df19 |
children | 35c1d1c098e6 af80e5618e9b |
comparison
equal
deleted
inserted
replaced
22:40f7cfd4df19 | 37:94944d00e43c |
---|---|
19 menu_item :new_issue, :only => [:new, :create] | 19 menu_item :new_issue, :only => [:new, :create] |
20 default_search_scope :issues | 20 default_search_scope :issues |
21 | 21 |
22 before_filter :find_issue, :only => [:show, :edit, :update] | 22 before_filter :find_issue, :only => [:show, :edit, :update] |
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy] | 23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy] |
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move] | |
24 before_filter :find_project, :only => [:new, :create] | 25 before_filter :find_project, :only => [:new, :create] |
25 before_filter :authorize, :except => [:index] | 26 before_filter :authorize, :except => [:index] |
26 before_filter :find_optional_project, :only => [:index] | 27 before_filter :find_optional_project, :only => [:index] |
27 before_filter :check_for_default_issue_status, :only => [:new, :create] | 28 before_filter :check_for_default_issue_status, :only => [:new, :create] |
28 before_filter :build_new_issue_from_params, :only => [:new, :create] | 29 before_filter :build_new_issue_from_params, :only => [:new, :create] |
29 accept_key_auth :index, :show | 30 accept_key_auth :index, :show, :create, :update, :destroy |
30 | 31 |
31 rescue_from Query::StatementInvalid, :with => :query_statement_invalid | 32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
32 | 33 |
33 helper :journals | 34 helper :journals |
34 helper :projects | 35 helper :projects |
147 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } | 148 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } |
148 format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false } | 149 format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false } |
149 end | 150 end |
150 end | 151 end |
151 end | 152 end |
152 | 153 |
153 # Attributes that can be updated on workflow transition (without :edit permission) | |
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) | |
156 | |
157 def edit | 154 def edit |
158 update_issue_from_params | 155 update_issue_from_params |
159 | 156 |
160 @journal = @issue.current_journal | 157 @journal = @issue.current_journal |
161 | 158 |
191 end | 188 end |
192 | 189 |
193 # Bulk edit a set of issues | 190 # Bulk edit a set of issues |
194 def bulk_edit | 191 def bulk_edit |
195 @issues.sort! | 192 @issues.sort! |
196 @available_statuses = Workflow.available_statuses(@project) | 193 @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w} |
197 @custom_fields = @project.all_issue_custom_fields | 194 @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c} |
195 @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a} | |
196 @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t} | |
198 end | 197 end |
199 | 198 |
200 def bulk_update | 199 def bulk_update |
201 @issues.sort! | 200 @issues.sort! |
202 attributes = parse_params_for_bulk_issue_attributes(params) | 201 attributes = parse_params_for_bulk_issue_attributes(params) |
239 end | 238 end |
240 end | 239 end |
241 end | 240 end |
242 @issues.each(&:destroy) | 241 @issues.each(&:destroy) |
243 respond_to do |format| | 242 respond_to do |format| |
244 format.html { redirect_to :action => 'index', :project_id => @project } | 243 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) } |
245 format.xml { head :ok } | 244 format.xml { head :ok } |
246 format.json { head :ok } | 245 format.json { head :ok } |
247 end | 246 end |
248 end | 247 end |
249 | 248 |
268 def update_issue_from_params | 267 def update_issue_from_params |
269 @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | 268 @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
270 @priorities = IssuePriority.all | 269 @priorities = IssuePriority.all |
271 @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | 270 @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
272 @time_entry = TimeEntry.new | 271 @time_entry = TimeEntry.new |
272 @time_entry.attributes = params[:time_entry] | |
273 | 273 |
274 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) | 274 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) |
275 @issue.init_journal(User.current, @notes) | 275 @issue.init_journal(User.current, @notes) |
276 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | 276 @issue.safe_attributes = params[:issue] |
277 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |
278 attrs = params[:issue].dup | |
279 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |
280 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |
281 @issue.safe_attributes = attrs | |
282 end | |
283 | |
284 end | 277 end |
285 | 278 |
286 # TODO: Refactor, lots of extra code in here | 279 # TODO: Refactor, lots of extra code in here |
280 # TODO: Changing tracker on an existing issue should not trigger this | |
287 def build_new_issue_from_params | 281 def build_new_issue_from_params |
288 if params[:id].blank? | 282 if params[:id].blank? |
289 @issue = Issue.new | 283 @issue = Issue.new |
290 @issue.copy_from(params[:copy_from]) if params[:copy_from] | 284 @issue.copy_from(params[:copy_from]) if params[:copy_from] |
291 @issue.project = @project | 285 @issue.project = @project |
298 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | 292 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
299 if @issue.tracker.nil? | 293 if @issue.tracker.nil? |
300 render_error l(:error_no_tracker_in_project) | 294 render_error l(:error_no_tracker_in_project) |
301 return false | 295 return false |
302 end | 296 end |
297 @issue.start_date ||= Date.today | |
303 if params[:issue].is_a?(Hash) | 298 if params[:issue].is_a?(Hash) |
304 @issue.safe_attributes = params[:issue] | 299 @issue.safe_attributes = params[:issue] |
305 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | 300 if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record? |
301 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] | |
302 end | |
306 end | 303 end |
307 @issue.author = User.current | 304 @issue.author = User.current |
308 @issue.start_date ||= Date.today | |
309 @priorities = IssuePriority.all | 305 @priorities = IssuePriority.all |
310 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | 306 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) |
311 end | 307 end |
312 | 308 |
313 def check_for_default_issue_status | 309 def check_for_default_issue_status |