Commit 1adcbbb4 authored by James Lopez's avatar James Lopez

fix validation

parent 5a8eddc7
...@@ -4,17 +4,25 @@ class LdapGroupLink < ActiveRecord::Base ...@@ -4,17 +4,25 @@ class LdapGroupLink < ActiveRecord::Base
BLANK_ATTRIBUTES = %w[cn filter].freeze BLANK_ATTRIBUTES = %w[cn filter].freeze
validates :cn, :group_access, :group_id, presence: true, unless: :filter with_options if: :cn do |link|
validates :cn, uniqueness: { scope: [:group_id, :provider] }, unless: :filter link.validates :cn, :group_access, :group_id, presence: true, unless: :filter
validates :filter, :group_access, :group_id, presence: true, unless: :cn link.validates :cn, uniqueness: { scope: [:group_id, :provider] }, if: :cn
validates :filter, uniqueness: { scope: [:group_id, :provider] }, unless: :cn link.validates :filter, absence: true
validates :filter, ldap_filter: true, unless: :cn end
with_options if: :filter do |link|
link.validates :filter, :group_access, :group_id, presence: true
link.validates :filter, uniqueness: { scope: [:group_id, :provider] }
link.validates :filter, ldap_filter: true
link.validates :cn, absence: true
end
validates :group_access, inclusion: { in: Gitlab::Access.all_values } validates :group_access, inclusion: { in: Gitlab::Access.all_values }
validates :provider, presence: true validates :provider, presence: true
scope :with_provider, ->(provider) { where(provider: provider) } scope :with_provider, ->(provider) { where(provider: provider) }
before_save :nullify_blank_attributes before_validation :nullify_blank_attributes
def access_field def access_field
group_access group_access
......
...@@ -20,6 +20,12 @@ describe LdapGroupLink do ...@@ -20,6 +20,12 @@ describe LdapGroupLink do
group_link.provider = 'ldapalt' group_link.provider = 'ldapalt'
expect(group_link).to be_valid expect(group_link).to be_valid
end end
it 'is invalid when a filter is also present' do
link = build(:ldap_group_link, filter: '(a=b)', group_id: 1, provider: 'ldapmain', cn: 'group1')
expect(link).not_to be_valid
end
end end
describe 'filter' do describe 'filter' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment