Commit dbe84d92 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'exclude_bots_from_license_seat_usage' into 'master'

Exclude GitLab generated bot users from using a license seat

See merge request gitlab-org/gitlab!24275
parents 95edb274 762f5222
......@@ -275,7 +275,7 @@ module EE
def using_license_seat?
return false unless active?
return false if support_bot? || ghost?
return false if internal?
return false unless License.current
if License.current.exclude_guests_from_active_count?
......
---
title: Exclude GitLab generated bot users from using a license seat
merge_request: 24275
author:
type: changed
......@@ -638,61 +638,73 @@ describe User do
end
context 'when user is active' do
context 'when user is a support bot' do
let(:user) { create(:user, bot_type: 'support_bot') }
context 'when user is internal' do
using RSpec::Parameterized::TableSyntax
it 'returns false' do
expect(user.using_license_seat?).to eq false
where(:bot_type) do
User.bot_types.keys
end
end
context 'when user is a ghost' do
let(:user) { create(:user, ghost: true) }
with_them do
context 'when user is a bot' do
let(:user) { create(:user, bot_type: bot_type) }
it 'returns false' do
expect(user.using_license_seat?).to eq false
it 'returns false' do
expect(user.using_license_seat?).to eq false
end
end
end
end
context 'when license is nil (core/free/default)' do
before do
allow(License).to receive(:current).and_return(nil)
end
context 'when user is a ghost' do
let(:user) { create(:user, ghost: true) }
it 'returns false if license is nil (core/free/default)' do
expect(user.using_license_seat?).to eq false
it 'returns false' do
expect(user.using_license_seat?).to eq false
end
end
end
context 'user is guest' do
let(:project_guest_user) { create(:project_member, :guest).user }
it 'returns false if license is ultimate' do
create(:license, plan: License::ULTIMATE_PLAN)
context 'when user is not internal' do
context 'when license is nil (core/free/default)' do
before do
allow(License).to receive(:current).and_return(nil)
end
expect(project_guest_user.using_license_seat?).to eq false
it 'returns false if license is nil (core/free/default)' do
expect(user.using_license_seat?).to eq false
end
end
it 'returns true if license is not ultimate and not nil' do
create(:license, plan: License::STARTER_PLAN)
context 'user is guest' do
let(:project_guest_user) { create(:project_member, :guest).user }
expect(project_guest_user.using_license_seat?).to eq true
end
end
it 'returns false if license is ultimate' do
create(:license, plan: License::ULTIMATE_PLAN)
context 'user is admin without projects' do
let(:user) { create(:user, admin: true) }
expect(project_guest_user.using_license_seat?).to eq false
end
it 'returns false if license is ultimate' do
create(:license, plan: License::ULTIMATE_PLAN)
it 'returns true if license is not ultimate and not nil' do
create(:license, plan: License::STARTER_PLAN)
expect(user.using_license_seat?).to eq false
expect(project_guest_user.using_license_seat?).to eq true
end
end
it 'returns true if license is not ultimate and not nil' do
create(:license, plan: License::STARTER_PLAN)
context 'user is admin without projects' do
let(:user) { create(:user, admin: true) }
it 'returns false if license is ultimate' do
create(:license, plan: License::ULTIMATE_PLAN)
expect(user.using_license_seat?).to eq false
end
it 'returns true if license is not ultimate and not nil' do
create(:license, plan: License::STARTER_PLAN)
expect(user.using_license_seat?).to eq true
expect(user.using_license_seat?).to eq true
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