diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-10-28 14:31:59 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-10-28 14:31:59 +0000 |
commit | 0af6f347580dd7c331f16aa50904d010fad19e23 (patch) | |
tree | 62abc086a5c11385d04901dba5c0b050a2346034 /app/controllers | |
parent | bb4acc02d06d507424057ea41eebe54fdb224b85 (diff) | |
download | redmine-0af6f347580dd7c331f16aa50904d010fad19e23.tar.gz redmine-0af6f347580dd7c331f16aa50904d010fad19e23.zip |
Added the hability to copy an issue.
It can be done from the 'issue/show' view or from the context menu on the issue list.
The Copy functionality is of course only available if the user is allowed to create an issue.
It copies the issue attributes and the custom fields values.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@873 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/issues_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 38 |
2 files changed, 21 insertions, 18 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index d3949cbee..228597931 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -174,6 +174,7 @@ class IssuesController < ApplicationController @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) @can = {:edit => User.current.allowed_to?(:edit_issues, @project), :change_status => User.current.allowed_to?(:change_issue_status, @project), + :add => User.current.allowed_to?(:add_issues, @project), :move => User.current.allowed_to?(:move_issues, @project), :delete => User.current.allowed_to?(:delete_issues, @project)} render :layout => false diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 377073fc9..394e545d0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -192,43 +192,45 @@ class ProjectsController < ApplicationController end # Add a new issue to @project + # The new issue will be created from an existing one if copy_from parameter is given def add_issue - @tracker = Tracker.find(params[:tracker_id]) - @priorities = Enumeration::get_values('IPRI') + @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue]) + @issue.project = @project + @issue.author = User.current + @issue.tracker ||= Tracker.find(params[:tracker_id]) default_status = IssueStatus.default unless default_status - flash.now[:error] = 'No default issue status defined. Please check your configuration.' + flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' render :nothing => true, :layout => true return - end - @issue = Issue.new(:project => @project, :tracker => @tracker) + end @issue.status = default_status @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user + if request.get? - @issue.start_date = Date.today - @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } + @issue.start_date ||= Date.today + @custom_values = @issue.custom_values.empty? ? + @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } : + @issue.custom_values else - @issue.attributes = params[:issue] - requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) + # Check that the user is allowed to apply the requested status @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status - - @issue.author_id = self.logged_in_user.id if self.logged_in_user - # Multiple file upload - @attachments = [] - params[:attachments].each { |a| - @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 - } if params[:attachments] and params[:attachments].is_a? Array - @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } + @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]) } @issue.custom_values = @custom_values if @issue.save - @attachments.each(&:save) + if params[:attachments] && params[:attachments].is_a?(Array) + # Save attachments + params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0} + end flash[:notice] = l(:notice_successful_create) Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') redirect_to :action => 'list_issues', :id => @project + return end end + @priorities = Enumeration::get_values('IPRI') end # Show filtered/sorted issues list of @project |