diff options
Diffstat (limited to 'app/validators/abstract_path_validator.rb')
-rw-r--r-- | app/validators/abstract_path_validator.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/app/validators/abstract_path_validator.rb b/app/validators/abstract_path_validator.rb index 45ac695c5ec..ff390a624c5 100644 --- a/app/validators/abstract_path_validator.rb +++ b/app/validators/abstract_path_validator.rb @@ -26,11 +26,22 @@ class AbstractPathValidator < ActiveModel::EachValidator return end - full_path = record.build_full_path - return unless full_path + if build_full_path_to_validate_against_reserved_names? + path_to_validate_against_reserved_names = record.build_full_path + return unless path_to_validate_against_reserved_names + else + path_to_validate_against_reserved_names = value + end - unless self.class.valid_path?(full_path) + unless self.class.valid_path?(path_to_validate_against_reserved_names) record.errors.add(attribute, "#{value} is a reserved name") end end + + def build_full_path_to_validate_against_reserved_names? + # By default, entities using the `Routable` concern can build full paths. + # But entities like `Organization` do not have a parent, and hence cannot build full paths, + # and this method can be overridden to return `false` in such cases. + true + end end |