mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) validate oauth2 providers have User.uid mapped
This commit is contained in:
parent
153d50be77
commit
9191e1f9cd
@ -23,6 +23,7 @@ class AuthProvider < ApplicationRecord
|
|||||||
|
|
||||||
validates :providable_type, inclusion: { in: PROVIDABLE_TYPES }
|
validates :providable_type, inclusion: { in: PROVIDABLE_TYPES }
|
||||||
validates :name, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true
|
||||||
|
validates_with OAuth2ProviderValidator, if: -> { providable_type == 'OAuth2Provider' }
|
||||||
|
|
||||||
before_create :set_initial_state
|
before_create :set_initial_state
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
class OAuth2Provider < ApplicationRecord
|
class OAuth2Provider < ApplicationRecord
|
||||||
has_one :auth_provider, as: :providable
|
has_one :auth_provider, as: :providable
|
||||||
|
|
||||||
validates_with OAuth2ProviderValidator
|
|
||||||
|
|
||||||
def domain
|
def domain
|
||||||
URI(base_url).scheme + '://' + URI(base_url).host
|
URI(base_url).scheme + '://' + URI(base_url).host
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
# Validates the presence of the User.uid mapping
|
# Validates the presence of the User.uid mapping
|
||||||
class OAuth2ProviderValidator < ActiveModel::Validator
|
class OAuth2ProviderValidator < ActiveModel::Validator
|
||||||
def validate(record)
|
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'
|
mapping.local_model == 'user' && mapping.local_field == 'uid'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user