Create role by copy (#9258).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10285 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-09-03 17:04:28 +00:00
parent 1b64e4be5e
commit ca7498c2d6
6 changed files with 52 additions and 2 deletions
+9
View File
@@ -67,6 +67,15 @@ class Role < ActiveRecord::Base
:in => ISSUES_VISIBILITY_OPTIONS.collect(&:first),
:if => lambda {|role| role.respond_to?(:issues_visibility)}
# Copies attributes from another role, arg can be an id or a Role
def copy_from(arg, options={})
return unless arg.present?
role = arg.is_a?(Role) ? arg : Role.find_by_id(arg.to_s)
self.attributes = role.attributes.dup.except("id", "name", "position", "builtin", "permissions")
self.permissions = role.permissions.dup
self
end
def permissions=(perms)
perms = perms.collect {|p| p.to_sym unless p.blank? }.compact.uniq if perms
write_attribute(:permissions, perms)