Skip to content

Commit

Permalink
Refactor: Move the updating of an Issue to the #update method.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3486 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Feb 25, 2010
1 parent 19d4ddf commit c68d853
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
32 changes: 25 additions & 7 deletions app/controllers/issues_controller.rb
Expand Up @@ -198,6 +198,31 @@ def edit
@issue.safe_attributes = attrs
end

respond_to do |format|
format.html { }
format.xml { }
end
end

#--
# Start converting to the Rails REST controllers
#++
def update
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@priorities = IssuePriority.all
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
@time_entry = TimeEntry.new

@notes = params[:notes]
journal = @issue.init_journal(User.current, @notes)
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
attrs = params[:issue].dup
attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
@issue.safe_attributes = attrs
end

if request.get?
# nop
else
Expand Down Expand Up @@ -237,13 +262,6 @@ def edit
attachments.each(&:destroy)
end

#--
# Start converting to the Rails REST controllers
#++
def update
edit
end

def reply
journal = Journal.find(params[:journal_id]) if params[:journal_id]
if journal
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -126,7 +126,8 @@
issues_actions.connect 'issues.:format', :action => 'new', :format => /xml/
end
issues_routes.with_options :conditions => {:method => :put} do |issues_actions|
issues_actions.connect 'issues/:id.:format', :action => 'edit', :id => /\d+/, :format => /xml/
issues_actions.connect 'issues/:id/edit', :action => 'update', :id => /\d+/
issues_actions.connect 'issues/:id.:format', :action => 'update', :id => /\d+/, :format => /xml/
end
issues_routes.with_options :conditions => {:method => :delete} do |issues_actions|
issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/
Expand Down
2 changes: 1 addition & 1 deletion test/integration/issues_api_test.rb
Expand Up @@ -114,7 +114,7 @@ def test_create_failure
def test_update_routing
assert_routing(
{:method => :put, :path => '/issues/1.xml'},
:controller => 'issues', :action => 'edit', :id => '1', :format => 'xml'
:controller => 'issues', :action => 'update', :id => '1', :format => 'xml'
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/issues_test.rb
Expand Up @@ -69,7 +69,7 @@ def test_issue_attachements
log_user('jsmith', 'jsmith')
set_tmp_attachments_directory

post 'issues/1/edit',
put 'issues/1/edit',
:notes => 'Some notes',
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
assert_redirected_to "issues/1"
Expand Down

0 comments on commit c68d853

Please sign in to comment.