summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-02-25 17:01:10 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-02-25 17:01:10 +0000
commit3de1f2e157487b64a10127eeb007ab3879b325d9 (patch)
tree8a3c5fa173a93302bc9fcdde8d0beda2f3e7b4c7 /app
parentc68d853bf4cfd9bf60df3166317b0dcea0702461 (diff)
downloadredmine-3de1f2e157487b64a10127eeb007ab3879b325d9.tar.gz
redmine-3de1f2e157487b64a10127eeb007ab3879b325d9.zip
Refactor: Extracted the duplication from the last commit into a new method
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3487 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/issues_controller.rb59
1 files changed, 27 insertions, 32 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index ff75659d7..d30924a80 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -183,20 +183,7 @@ class IssuesController < ApplicationController
UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
def edit
- @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
+ update_issue_from_params
respond_to do |format|
format.html { }
@@ -208,20 +195,7 @@ class IssuesController < ApplicationController
# 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
+ update_issue_from_params
if request.get?
# nop
@@ -230,18 +204,18 @@ class IssuesController < ApplicationController
@time_entry.attributes = params[:time_entry]
if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid?
attachments = attach_files(@issue, params[:attachments])
- attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
- call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
+ attachments.each {|a| @journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
+ call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal})
if @issue.save
# Log spend time
if User.current.allowed_to?(:log_time, @project)
@time_entry.save
end
- if !journal.new_record?
+ if !@journal.new_record?
# Only send notification if something was actually changed
flash[:notice] = l(:notice_successful_update)
end
- call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
+ call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal})
respond_to do |format|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
format.xml { head :ok }
@@ -584,4 +558,25 @@ private
sort_clear
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
end
+
+ # Used by #edit and #update to set some common instance variables
+ # from the params
+ # TODO: Refactor, not everything in here is needed by #edit
+ def update_issue_from_params
+ @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
+
+ end
end