Commit eed3c230 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'refactor-gma_enforcement' into 'master'

Move gma enforcement logic from rails-validation layer to the class

See merge request gitlab-org/gitlab!76579
parents fc277453 5d82b732
...@@ -8,7 +8,7 @@ module EE ...@@ -8,7 +8,7 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
validate :sso_enforcement, if: -> { group && user } validate :sso_enforcement, if: -> { group && user }
validate :gma_enforcement, if: :group, unless: :project_bot validate :gma_enforcement, if: -> { group && user }
validate :group_domain_limitations, if: -> { group && group_has_domain_limitations? }, on: :create validate :group_domain_limitations, if: -> { group && group_has_domain_limitations? }, on: :create
before_destroy :delete_member_branch_protection before_destroy :delete_member_branch_protection
......
...@@ -9,6 +9,8 @@ module Gitlab ...@@ -9,6 +9,8 @@ module Gitlab
end end
def can_add_user?(user) def can_add_user?(user)
return true if user.project_bot?
check_project_membership(user) && check_source_project_membership(user) check_project_membership(user) && check_source_project_membership(user)
end end
......
...@@ -16,6 +16,12 @@ RSpec.describe Gitlab::Auth::GroupSaml::GmaMembershipEnforcer do ...@@ -16,6 +16,12 @@ RSpec.describe Gitlab::Auth::GroupSaml::GmaMembershipEnforcer do
stub_licensed_features(group_saml: true) stub_licensed_features(group_saml: true)
end end
it 'allows adding a project bot to project' do
project_bot = create(:user, :project_bot)
expect(subject.can_add_user?(project_bot)).to be_truthy
end
context 'when user is group-managed' do context 'when user is group-managed' do
it 'allows adding user to project' do it 'allows adding user to project' do
expect(subject.can_add_user?(managed_user)).to be_truthy expect(subject.can_add_user?(managed_user)).to be_truthy
......
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