Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8200 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2011-12-13 20:40:03 +00:00
parent 59c1141e08
commit 7d501eaf81
5 changed files with 30 additions and 8 deletions
+11 -3
View File
@@ -44,14 +44,22 @@ module Redmine
# Example:
# book.safe_attributes # => ['title', 'pages']
# book.safe_attributes(book.author) # => ['title', 'pages', 'isbn']
def safe_attribute_names(user=User.current)
def safe_attribute_names(user=nil)
return @safe_attribute_names if @safe_attribute_names && user.nil?
names = []
self.class.safe_attributes.collect do |attrs, options|
if options[:if].nil? || options[:if].call(self, user)
if options[:if].nil? || options[:if].call(self, user || User.current)
names += attrs.collect(&:to_s)
end
end
names.uniq
names.uniq!
@safe_attribute_names = names if user.nil?
names
end
# Returns true if attr can be set by user or the current user
def safe_attribute?(attr, user=nil)
safe_attribute_names(user).include?(attr.to_s)
end
# Returns a hash with unsafe attributes removed