Validate key uniqueness across Key and DeployKey tables
This commit is contained in:
parent
c973fce606
commit
5b4382e12e
3 changed files with 15 additions and 0 deletions
7
lib/unique_public_key_validator.rb
Normal file
7
lib/unique_public_key_validator.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class UniquePublicKeyValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
if (DeployKey.where('key = ? AND id !=?', record.key , record.id).count > 0 || Key.where('key = ? AND id !=?', record.key , record.id).count > 0)
|
||||
record.errors.add :key, 'already exist.'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue