Commit f8e7c520 authored by Krasimir Angelov's avatar Krasimir Angelov Committed by Arturo Herrero

Do not mark bot users as pending approval when User Cap is enabled

When User cap is enabled we mark all newly created users as pending
approval, even those that are not humans. This prevents creation of
project access tokens - at the time when we try to create the token the
associated bot users is not approved.

This updates `Users::BuildService#set_pending_approval_state` to mark
users as pending approval only if they are `human?`.

See https://gitlab.com/gitlab-org/gitlab/-/issues/323191.
parent ba8bd0de
...@@ -105,6 +105,8 @@ module EE ...@@ -105,6 +105,8 @@ module EE
def set_pending_approval_state(user) def set_pending_approval_state(user)
return unless ::Gitlab::CurrentSettings.should_apply_user_signup_cap? return unless ::Gitlab::CurrentSettings.should_apply_user_signup_cap?
return unless user.human?
user.state = ::User::BLOCKED_PENDING_APPROVAL_STATE user.state = ::User::BLOCKED_PENDING_APPROVAL_STATE
end end
end end
......
---
title: Do not mark bot users as pending approval when User Cap is enabled
merge_request: 56287
author:
type: fixed
...@@ -8,6 +8,31 @@ RSpec.describe Users::BuildService do ...@@ -8,6 +8,31 @@ RSpec.describe Users::BuildService do
{ name: 'John Doe', username: 'jduser', email: 'jd@example.com', password: 'mydummypass' } { name: 'John Doe', username: 'jduser', email: 'jd@example.com', password: 'mydummypass' }
end end
context 'with non admin user' do
let(:non_admin) { create(:user) }
context 'when user signup cap is set' do
before do
allow(Gitlab::CurrentSettings).to receive(:new_user_signups_cap).and_return(10)
end
it 'does not set the user state to blocked_pending_approval for non human users' do
params = {
name: 'Project Bot',
email: 'project_bot@example.com',
username: 'project_bot',
user_type: 'project_bot',
skip_confirmation: true
}
service = described_class.new(non_admin, params)
user = service.execute(skip_authorization: true)
expect(user).to be_active
end
end
end
context 'with an admin user' do context 'with an admin user' do
let!(:admin_user) { create(:admin) } let!(:admin_user) { create(:admin) }
let(:service) { described_class.new(admin_user, ActionController::Parameters.new(params).permit!) } let(:service) { described_class.new(admin_user, ActionController::Parameters.new(params).permit!) }
......
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