2022-04-11 17:27:56 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Validates the presence of the User.uid mapping
|
2022-04-20 14:12:22 +02:00
|
|
|
class UserUidMappedValidator < ActiveModel::Validator
|
2022-04-11 17:27:56 +02:00
|
|
|
def validate(record)
|
2022-04-20 14:12:22 +02:00
|
|
|
return unless %w[OAuth2Provider OpenIdConnectProvider].include?(record.providable_type)
|
2022-04-12 10:25:48 +02:00
|
|
|
|
|
|
|
return if record.auth_provider_mappings.any? do |mapping|
|
2022-04-11 17:27:56 +02:00
|
|
|
mapping.local_model == 'user' && mapping.local_field == 'uid'
|
|
|
|
end
|
|
|
|
|
2022-04-12 13:54:47 +02:00
|
|
|
record.errors.add(:uid, I18n.t('authentication_providers.matching_between_User_uid_and_API_required'))
|
2022-04-11 17:27:56 +02:00
|
|
|
end
|
|
|
|
end
|