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 ...@@ -275,7 +275,7 @@ module EE
def using_license_seat? def using_license_seat?
return false unless active? return false unless active?
return false if support_bot? || ghost? return false if internal?
return false unless License.current return false unless License.current
if License.current.exclude_guests_from_active_count? 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 ...@@ -638,61 +638,73 @@ describe User do
end end
context 'when user is active' do context 'when user is active' do
context 'when user is a support bot' do context 'when user is internal' do
let(:user) { create(:user, bot_type: 'support_bot') } using RSpec::Parameterized::TableSyntax
it 'returns false' do where(:bot_type) do
expect(user.using_license_seat?).to eq false User.bot_types.keys
end end
end
context 'when user is a ghost' do with_them do
let(:user) { create(:user, ghost: true) } context 'when user is a bot' do
let(:user) { create(:user, bot_type: bot_type) }
it 'returns false' do it 'returns false' do
expect(user.using_license_seat?).to eq false expect(user.using_license_seat?).to eq false
end
end
end end
end
context 'when license is nil (core/free/default)' do context 'when user is a ghost' do
before do let(:user) { create(:user, ghost: true) }
allow(License).to receive(:current).and_return(nil)
end
it 'returns false if license is nil (core/free/default)' do it 'returns false' do
expect(user.using_license_seat?).to eq false expect(user.using_license_seat?).to eq false
end
end end
end end
context 'user is guest' do context 'when user is not internal' do
let(:project_guest_user) { create(:project_member, :guest).user } context 'when license is nil (core/free/default)' do
before do
it 'returns false if license is ultimate' do allow(License).to receive(:current).and_return(nil)
create(:license, plan: License::ULTIMATE_PLAN) 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 end
it 'returns true if license is not ultimate and not nil' do context 'user is guest' do
create(:license, plan: License::STARTER_PLAN) let(:project_guest_user) { create(:project_member, :guest).user }
expect(project_guest_user.using_license_seat?).to eq true it 'returns false if license is ultimate' do
end create(:license, plan: License::ULTIMATE_PLAN)
end
context 'user is admin without projects' do expect(project_guest_user.using_license_seat?).to eq false
let(:user) { create(:user, admin: true) } end
it 'returns false if license is ultimate' do it 'returns true if license is not ultimate and not nil' do
create(:license, plan: License::ULTIMATE_PLAN) 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 end
it 'returns true if license is not ultimate and not nil' do context 'user is admin without projects' do
create(:license, plan: License::STARTER_PLAN) 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 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