##// END OF EJS Templates
Refactor: Move the updating of an Issue to the #update method....
Eric Davis -
r3372:c68d853bf4cf
parent child
Show More
@@ -198,6 +198,31 class IssuesController < ApplicationController
198 @issue.safe_attributes = attrs
198 @issue.safe_attributes = attrs
199 end
199 end
200
200
201 respond_to do |format|
202 format.html { }
203 format.xml { }
204 end
205 end
206
207 #--
208 # Start converting to the Rails REST controllers
209 #++
210 def update
211 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
212 @priorities = IssuePriority.all
213 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
214 @time_entry = TimeEntry.new
215
216 @notes = params[:notes]
217 journal = @issue.init_journal(User.current, @notes)
218 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
219 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
220 attrs = params[:issue].dup
221 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
222 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
223 @issue.safe_attributes = attrs
224 end
225
201 if request.get?
226 if request.get?
202 # nop
227 # nop
203 else
228 else
@@ -237,13 +262,6 class IssuesController < ApplicationController
237 attachments.each(&:destroy)
262 attachments.each(&:destroy)
238 end
263 end
239
264
240 #--
241 # Start converting to the Rails REST controllers
242 #++
243 def update
244 edit
245 end
246
247 def reply
265 def reply
248 journal = Journal.find(params[:journal_id]) if params[:journal_id]
266 journal = Journal.find(params[:journal_id]) if params[:journal_id]
249 if journal
267 if journal
@@ -126,7 +126,8 ActionController::Routing::Routes.draw do |map|
126 issues_actions.connect 'issues.:format', :action => 'new', :format => /xml/
126 issues_actions.connect 'issues.:format', :action => 'new', :format => /xml/
127 end
127 end
128 issues_routes.with_options :conditions => {:method => :put} do |issues_actions|
128 issues_routes.with_options :conditions => {:method => :put} do |issues_actions|
129 issues_actions.connect 'issues/:id.:format', :action => 'edit', :id => /\d+/, :format => /xml/
129 issues_actions.connect 'issues/:id/edit', :action => 'update', :id => /\d+/
130 issues_actions.connect 'issues/:id.:format', :action => 'update', :id => /\d+/, :format => /xml/
130 end
131 end
131 issues_routes.with_options :conditions => {:method => :delete} do |issues_actions|
132 issues_routes.with_options :conditions => {:method => :delete} do |issues_actions|
132 issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/
133 issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/
@@ -114,7 +114,7 class IssuesApiTest < ActionController::IntegrationTest
114 def test_update_routing
114 def test_update_routing
115 assert_routing(
115 assert_routing(
116 {:method => :put, :path => '/issues/1.xml'},
116 {:method => :put, :path => '/issues/1.xml'},
117 :controller => 'issues', :action => 'edit', :id => '1', :format => 'xml'
117 :controller => 'issues', :action => 'update', :id => '1', :format => 'xml'
118 )
118 )
119 end
119 end
120
120
@@ -69,7 +69,7 class IssuesTest < ActionController::IntegrationTest
69 log_user('jsmith', 'jsmith')
69 log_user('jsmith', 'jsmith')
70 set_tmp_attachments_directory
70 set_tmp_attachments_directory
71
71
72 post 'issues/1/edit',
72 put 'issues/1/edit',
73 :notes => 'Some notes',
73 :notes => 'Some notes',
74 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
74 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
75 assert_redirected_to "issues/1"
75 assert_redirected_to "issues/1"
General Comments 0
You need to be logged in to leave comments. Login now