@@ -183,20 +183,7 class IssuesController < ApplicationController | |||||
183 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
183 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) | |
184 |
|
184 | |||
185 | def edit |
|
185 | def edit | |
186 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
186 | update_issue_from_params | |
187 | @priorities = IssuePriority.all |
|
|||
188 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
|||
189 | @time_entry = TimeEntry.new |
|
|||
190 |
|
||||
191 | @notes = params[:notes] |
|
|||
192 | journal = @issue.init_journal(User.current, @notes) |
|
|||
193 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
|||
194 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
|||
195 | attrs = params[:issue].dup |
|
|||
196 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
|||
197 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
|||
198 | @issue.safe_attributes = attrs |
|
|||
199 | end |
|
|||
200 |
|
187 | |||
201 | respond_to do |format| |
|
188 | respond_to do |format| | |
202 | format.html { } |
|
189 | format.html { } | |
@@ -208,20 +195,7 class IssuesController < ApplicationController | |||||
208 | # Start converting to the Rails REST controllers |
|
195 | # Start converting to the Rails REST controllers | |
209 | #++ |
|
196 | #++ | |
210 | def update |
|
197 | def update | |
211 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
198 | update_issue_from_params | |
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 |
|
199 | |||
226 | if request.get? |
|
200 | if request.get? | |
227 | # nop |
|
201 | # nop | |
@@ -230,18 +204,18 class IssuesController < ApplicationController | |||||
230 | @time_entry.attributes = params[:time_entry] |
|
204 | @time_entry.attributes = params[:time_entry] | |
231 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? |
|
205 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? | |
232 | attachments = attach_files(@issue, params[:attachments]) |
|
206 | attachments = attach_files(@issue, params[:attachments]) | |
233 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
207 | attachments.each {|a| @journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
234 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
208 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal}) | |
235 | if @issue.save |
|
209 | if @issue.save | |
236 | # Log spend time |
|
210 | # Log spend time | |
237 | if User.current.allowed_to?(:log_time, @project) |
|
211 | if User.current.allowed_to?(:log_time, @project) | |
238 | @time_entry.save |
|
212 | @time_entry.save | |
239 | end |
|
213 | end | |
240 | if !journal.new_record? |
|
214 | if !@journal.new_record? | |
241 | # Only send notification if something was actually changed |
|
215 | # Only send notification if something was actually changed | |
242 | flash[:notice] = l(:notice_successful_update) |
|
216 | flash[:notice] = l(:notice_successful_update) | |
243 | end |
|
217 | end | |
244 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
218 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal}) | |
245 | respond_to do |format| |
|
219 | respond_to do |format| | |
246 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
220 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | |
247 | format.xml { head :ok } |
|
221 | format.xml { head :ok } | |
@@ -584,4 +558,25 private | |||||
584 | sort_clear |
|
558 | sort_clear | |
585 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." |
|
559 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." | |
586 | end |
|
560 | end | |
|
561 | ||||
|
562 | # Used by #edit and #update to set some common instance variables | |||
|
563 | # from the params | |||
|
564 | # TODO: Refactor, not everything in here is needed by #edit | |||
|
565 | def update_issue_from_params | |||
|
566 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |||
|
567 | @priorities = IssuePriority.all | |||
|
568 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |||
|
569 | @time_entry = TimeEntry.new | |||
|
570 | ||||
|
571 | @notes = params[:notes] | |||
|
572 | @journal = @issue.init_journal(User.current, @notes) | |||
|
573 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |||
|
574 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |||
|
575 | attrs = params[:issue].dup | |||
|
576 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |||
|
577 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |||
|
578 | @issue.safe_attributes = attrs | |||
|
579 | end | |||
|
580 | ||||
|
581 | end | |||
587 | end |
|
582 | end |
General Comments 0
You need to be logged in to leave comments.
Login now