Commit 65bd0608 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'vs-fix-validation-for-admin-settings-user-cap' into 'master'

Fix validations for user cap setting

See merge request gitlab-org/gitlab!46546
parents 11f384ed f7e0c562
...@@ -95,11 +95,15 @@ module EE ...@@ -95,11 +95,15 @@ module EE
validate :allowed_frameworks, if: :compliance_frameworks_changed? validate :allowed_frameworks, if: :compliance_frameworks_changed?
validates :new_user_signups_cap, validates :new_user_signups_cap,
numericality: { only_integer: true, allow_blank: true,
allow_nil: true, numericality: { only_integer: true, greater_than: 0 }
greater_than: 0 }
validates :new_user_signups_cap, validates :new_user_signups_cap,
numericality: { less_than_or_equal_to: proc { License.current&.restricted_user_count } }, allow_blank: true,
numericality: {
only_integer: true,
greater_than: 0,
less_than_or_equal_to: proc { License.current&.restricted_user_count }
},
if: proc { License.current&.restricted_user_count? } if: proc { License.current&.restricted_user_count? }
after_commit :update_personal_access_tokens_lifetime, if: :saved_change_to_max_personal_access_token_lifetime? after_commit :update_personal_access_tokens_lifetime, if: :saved_change_to_max_personal_access_token_lifetime?
......
...@@ -88,6 +88,8 @@ RSpec.describe ApplicationSetting do ...@@ -88,6 +88,8 @@ RSpec.describe ApplicationSetting do
it { is_expected.to allow_value(nil).for(:new_user_signups_cap) } it { is_expected.to allow_value(nil).for(:new_user_signups_cap) }
it { is_expected.to allow_value(1).for(:new_user_signups_cap) } it { is_expected.to allow_value(1).for(:new_user_signups_cap) }
it { is_expected.to allow_value(10).for(:new_user_signups_cap) } it { is_expected.to allow_value(10).for(:new_user_signups_cap) }
it { is_expected.to allow_value("").for(:new_user_signups_cap) }
it { is_expected.not_to allow_value("value").for(:new_user_signups_cap) }
it { is_expected.not_to allow_value(-1).for(:new_user_signups_cap) } it { is_expected.not_to allow_value(-1).for(:new_user_signups_cap) }
it { is_expected.not_to allow_value(2.5).for(:new_user_signups_cap) } it { is_expected.not_to allow_value(2.5).for(:new_user_signups_cap) }
...@@ -175,6 +177,7 @@ RSpec.describe ApplicationSetting do ...@@ -175,6 +177,7 @@ RSpec.describe ApplicationSetting do
it { is_expected.to allow_value(max_active_user_count - 1).for(:new_user_signups_cap) } it { is_expected.to allow_value(max_active_user_count - 1).for(:new_user_signups_cap) }
it { is_expected.to allow_value(max_active_user_count).for(:new_user_signups_cap) } it { is_expected.to allow_value(max_active_user_count).for(:new_user_signups_cap) }
it { is_expected.to allow_value(nil).for(:new_user_signups_cap) }
it { is_expected.not_to allow_value(max_active_user_count + 1).for(:new_user_signups_cap) } it { is_expected.not_to allow_value(max_active_user_count + 1).for(:new_user_signups_cap) }
end end
end end
......
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