diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-03-15 08:27:38 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-03-15 08:27:38 +0000 |
commit | aec989707edc47161192eba74f1a88123b12360a (patch) | |
tree | 5a810a6a3fb4fb76b9cfdb439eedc666bf4d049a /app/models/role.rb | |
parent | 993b60d61eb927cff21ea0b06c1631eb986f6a51 (diff) | |
download | redmine-aec989707edc47161192eba74f1a88123b12360a.tar.gz redmine-aec989707edc47161192eba74f1a88123b12360a.zip |
Workflow copy:
* added the ability the copy an existing workflow when creating a new role (closes #841)
* use a single raw insert statement to copy tracker/role workflow rather than instantiating hundreds/thousands of objects
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1252 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/role.rb')
-rw-r--r-- | app/models/role.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/role.rb b/app/models/role.rb index 015146dc4..6f1fb4768 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -21,7 +21,18 @@ class Role < ActiveRecord::Base BUILTIN_ANONYMOUS = 2 before_destroy :check_deletable - has_many :workflows, :dependent => :delete_all + has_many :workflows, :dependent => :delete_all do + def copy(role) + raise "Can not copy workflow from a #{role.class}" unless role.is_a?(Role) + raise "Can not copy workflow from/to an unsaved role" if proxy_owner.new_record? || role.new_record? + clear + connection.insert "INSERT INTO workflows (tracker_id, old_status_id, new_status_id, role_id)" + + " SELECT tracker_id, old_status_id, new_status_id, #{proxy_owner.id}" + + " FROM workflows" + + " WHERE role_id = #{role.id}" + end + end + has_many :members acts_as_list |