1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-05 16:24:21 +01:00
fab-manager/app/validators/user_uid_mapped_validator.rb

15 lines
506 B
Ruby

# frozen_string_literal: true
# Validates the presence of the User.uid mapping
class UserUidMappedValidator < ActiveModel::Validator
def validate(record)
return unless %w[OAuth2Provider OpenIdConnectProvider].include?(record.providable_type)
return if record.auth_provider_mappings.any? do |mapping|
mapping.local_model == 'user' && mapping.local_field == 'uid'
end
record.errors.add(:uid, I18n.t('authentication_providers.matching_between_User_uid_and_API_required'))
end
end