# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
\r
class IssuesController < ApplicationController\r
- layout 'base'\r
- before_filter :find_project, :authorize\r
+ layout 'base'\r
+ before_filter :find_project, :authorize\r
\r
- helper :custom_fields\r
- include CustomFieldsHelper\r
-
- def show
- @status_options = @issue.status.workflows.find(:all, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user\r
+ helper :custom_fields\r
+ include CustomFieldsHelper\r
+
+ def show
+ @status_options = @issue.status.workflows.find(:all, :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user\r
@custom_values = @issue.custom_values.find(:all, :include => :custom_field)\r
- end
+ end
- def edit\r
- @priorities = Enumeration::get_values('IPRI')\r
- \r
- if request.get?\r
- @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }\r
- else\r
- # Retrieve custom fields and values\r
- @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }\r
- @issue.custom_values = @custom_values\r
- @issue.attributes = params[:issue]\r
- if @issue.save
- flash[:notice] = l(:notice_successful_update)\r
- redirect_to :action => 'show', :id => @issue
- end\r
- end
- end\r
- \r
- def change_status\r
- @history = @issue.histories.build(params[:history]) \r
+ def edit\r
+ @priorities = Enumeration::get_values('IPRI')\r
+ if request.get?\r
+ @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }\r
+ else\r
+ begin\r
+ # Retrieve custom fields and values\r
+ @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }\r
+ @issue.custom_values = @custom_values\r
+ @issue.attributes = params[:issue]\r
+ if @issue.save
+ flash[:notice] = l(:notice_successful_update)\r
+ redirect_to :action => 'show', :id => @issue
+ end\r
+ rescue ActiveRecord::StaleObjectError\r
+ # Optimistic locking exception\r
+ flash[:notice] = l(:notice_locking_conflict)\r
+ end\r
+ end
+ end\r
+\r
+ def change_status\r
+ @history = @issue.histories.build(params[:history]) \r
@status_options = @issue.status.workflows.find(:all, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user\r
- \r
- if params[:confirm]\r
- @history.author_id = self.logged_in_user.id if self.logged_in_user\r
- \r
- if @history.save \r
- @issue.status = @history.status\r
- @issue.fixed_version_id = (params[:issue][:fixed_version_id])\r
- @issue.assigned_to_id = (params[:issue][:assigned_to_id]) \r
- if @issue.save\r
- flash[:notice] = l(:notice_successful_update)\r
- Mailer.deliver_issue_change_status(@issue) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?\r
- redirect_to :action => 'show', :id => @issue\r
- end
- end\r
- end \r
+ if params[:confirm]\r
+ begin\r
+ @history.author_id = self.logged_in_user.id if self.logged_in_user\r
+ @issue.status = @history.status\r
+ @issue.fixed_version_id = (params[:issue][:fixed_version_id])\r
+ @issue.assigned_to_id = (params[:issue][:assigned_to_id])\r
+ @issue.lock_version = (params[:issue][:lock_version])\r
+ if @issue.save\r
+ flash[:notice] = l(:notice_successful_update)\r
+ Mailer.deliver_issue_change_status(@issue) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?\r
+ redirect_to :action => 'show', :id => @issue\r
+ end\r
+ rescue ActiveRecord::StaleObjectError\r
+ # Optimistic locking exception\r
+ flash[:notice] = l(:notice_locking_conflict)\r
+ end\r
+ end \r
@assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }\r
-
- end
-
- def destroy
- @issue.destroy
- redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
- end\r
- \r
+ end
+
+ def destroy
+ @issue.destroy
+ redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
+ end\r
+\r
def add_attachment\r
# Save the attachment\r
if params[:attachment][:file].size > 0\r
\r
private\r
def find_project\r
- @issue = Issue.find(params[:id])\r
+ @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])\r
@project = @issue.project\r
end
end