mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
c7567c9a6d
Added an ability to specify your own behavior on mass assingment protection, controlled by option: ActiveModel::MassAssignmentSecurity.mass_assignment_sanitizer
40 lines
665 B
Ruby
40 lines
665 B
Ruby
require 'set'
|
|
|
|
module ActiveModel
|
|
module MassAssignmentSecurity
|
|
class PermissionSet < Set
|
|
|
|
def +(values)
|
|
super(values.map(&:to_s))
|
|
end
|
|
|
|
def include?(key)
|
|
super(remove_multiparameter_id(key))
|
|
end
|
|
|
|
def deny?(key)
|
|
raise NotImplementedError, "#deny?(key) suppose to be overwritten"
|
|
end
|
|
|
|
protected
|
|
|
|
def remove_multiparameter_id(key)
|
|
key.to_s.gsub(/\(.+/, '')
|
|
end
|
|
end
|
|
|
|
class WhiteList < PermissionSet
|
|
|
|
def deny?(key)
|
|
!include?(key)
|
|
end
|
|
end
|
|
|
|
class BlackList < PermissionSet
|
|
|
|
def deny?(key)
|
|
include?(key)
|
|
end
|
|
end
|
|
end
|
|
end
|