1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-17 11:54:22 +01:00

(bug) validate oauth2 providers have User.uid mapped

This commit is contained in:
Sylvain 2022-04-12 10:25:48 +02:00
parent 153d50be77
commit 9191e1f9cd
3 changed files with 4 additions and 3 deletions

View File

@ -23,6 +23,7 @@ class AuthProvider < ApplicationRecord
validates :providable_type, inclusion: { in: PROVIDABLE_TYPES }
validates :name, presence: true, uniqueness: true
validates_with OAuth2ProviderValidator, if: -> { providable_type == 'OAuth2Provider' }
before_create :set_initial_state

View File

@ -5,8 +5,6 @@
class OAuth2Provider < ApplicationRecord
has_one :auth_provider, as: :providable
validates_with OAuth2ProviderValidator
def domain
URI(base_url).scheme + '://' + URI(base_url).host
end

View File

@ -3,7 +3,9 @@
# Validates the presence of the User.uid mapping
class OAuth2ProviderValidator < ActiveModel::Validator
def validate(record)
return if record.auth_provider.auth_provider_mappings.any? do |mapping|
return unless record.providable_type == 'OAuth2Provider'
return if record.auth_provider_mappings.any? do |mapping|
mapping.local_model == 'user' && mapping.local_field == 'uid'
end