summaryrefslogtreecommitdiffstats
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-08 11:16:54 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-08 11:16:54 +0000
commit121bc44cc504b3086c35d40f984d75d978c59fb0 (patch)
treece23bebc4b702daad08241c105f36bba18bee68d /app/models/issue.rb
parentf134eeef459e7027b43500cc6a3b7306882c10b7 (diff)
downloadredmine-121bc44cc504b3086c35d40f984d75d978c59fb0.tar.gz
redmine-121bc44cc504b3086c35d40f984d75d978c59fb0.zip
Use the regular issue form to copy a single issue.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8552 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 4e4deb5db..1259361da 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -127,12 +127,14 @@ class Issue < ActiveRecord::Base
(project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : []
end
+ # Copies attributes from another issue, arg can be an id or an Issue
def copy_from(arg)
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
self.status = issue.status
self.author = User.current
+ @copied_from = issue
self
end
@@ -143,6 +145,11 @@ class Issue < ActiveRecord::Base
copy
end
+ # Returns true if the issue is a copy
+ def copy?
+ @copied_from.present?
+ end
+
# Moves/copies an issue to a new project and tracker
# Returns the moved/copied issue on success, false on failure
def move_to_project(new_project, new_tracker=nil, options={})
@@ -255,7 +262,9 @@ class Issue < ActiveRecord::Base
safe_attributes 'project_id',
:if => lambda {|issue, user|
- if user.allowed_to?(:move_issues, issue.project)
+ if issue.new_record?
+ issue.copy?
+ elsif user.allowed_to?(:move_issues, issue.project)
projects = Issue.allowed_target_projects_on_move(user)
projects.include?(issue.project) && projects.size > 1
end