2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/mongoid/validators/tenant_validator.rb', line 2
def validate_each(object, attribute, value)
if options[:immutable]
if object.send(:attribute_changed?, attribute) and object.send(:attribute_was, attribute)
object.errors.add(attribute, 'is immutable and cannot be updated')
end
end
if value and Mongoid::Multitenancy.current_tenant and value != Mongoid::Multitenancy.current_tenant.id
object.errors.add(attribute, "not authorized")
end
if !options[:optional] and value.nil?
object.errors.add(attribute, 'is mandatory')
end
end
|