validate the uniqueness of submitter roles

This commit is contained in:
Alex Turchyn
2024-10-15 20:10:47 +03:00
committed by Pete Matsyburka
parent 3ebaacbb7a
commit 6f90147a11
3 changed files with 37 additions and 0 deletions
+9
View File
@@ -65,6 +65,15 @@ module Params
raise_error(message || "#{key} must follow the #{regexp.source} format")
end
def unique(params, key, message: nil)
return unless params.is_a?(Array)
return if params.none?
return if params.all? { |p| p[key].blank? }
return if params.pluck(key).uniq.size == params.pluck(key).size
raise_error(message || "#{key} must be unique")
end
def in_path(params, path = [])
old_path = @current_path