Commit 648b8941 authored by Corinna Wiesner's avatar Corinna Wiesner Committed by Douglas Barbosa Alexandre

Change conditions when user uses license seat

Only show license badge and if user is using a seat when not on
Gitlab.com.
parent 24f16072
...@@ -12,7 +12,7 @@ module EE ...@@ -12,7 +12,7 @@ module EE
def user_badges_in_admin_section(user) def user_badges_in_admin_section(user)
super(user).tap do |badges| super(user).tap do |badges|
if user.using_license_seat? if !::Gitlab.com? && user.using_license_seat?
it_s_you_index = badges.index { |badge| badge[:text] == "It's you!" } || -1 it_s_you_index = badges.index { |badge| badge[:text] == "It's you!" } || -1
badges.insert(it_s_you_index, { text: s_('AdminUsers|Is using seat'), variant: 'light' }) badges.insert(it_s_you_index, { text: s_('AdminUsers|Is using seat'), variant: 'light' })
......
...@@ -275,6 +275,7 @@ module EE ...@@ -275,6 +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 unless License.current return false unless License.current
if License.current.exclude_guests_from_active_count? if License.current.exclude_guests_from_active_count?
......
%li - unless Gitlab.com?
%span.light= _("Is using license seat:") %li
%strong %span.light= _("Is using license seat:")
= @user.using_license_seat? ? _("Yes") : _("No") %strong
= @user.using_license_seat? ? _("Yes") : _("No")
---
title: Change conditions when user uses license seat
merge_request: 23522
author:
type: fixed
...@@ -38,9 +38,12 @@ describe UsersHelper do ...@@ -38,9 +38,12 @@ describe UsersHelper do
before do before do
allow(helper).to receive(:current_user).and_return(build(:user)) allow(helper).to receive(:current_user).and_return(build(:user))
allow(::Gitlab).to receive(:com?) { gitlab_com? }
end end
context 'with user who is using a license seat' do context 'when Gitlab.com? is true' do
let(:gitlab_com?) { true }
before do before do
allow(user).to receive(:using_license_seat?).and_return(true) allow(user).to receive(:using_license_seat?).and_return(true)
end end
...@@ -55,22 +58,50 @@ describe UsersHelper do ...@@ -55,22 +58,50 @@ describe UsersHelper do
expect(subject).to eq( expect(subject).to eq(
[ [
{ text: 'Admin', variant: 'success' }, { text: 'Admin', variant: 'success' },
{ text: 'Is using seat', variant: 'light' },
{ text: "It's you!", variant: nil } { text: "It's you!", variant: nil }
] ]
) )
end end
end end
it { expect(subject).to eq([text: 'Is using seat', variant: 'light']) } it { expect(subject).not_to eq([text: 'Is using seat', variant: 'light']) }
end end
context 'with user who is not using a license seat' do context 'when Gitlab.com? is false' do
before do let(:gitlab_com?) { false }
allow(user).to receive(:using_license_seat?).and_return(false)
context 'when user uses a license seat' do
before do
allow(user).to receive(:using_license_seat?).and_return(true)
end
context 'when user is an admin and the current_user' do
before do
allow(helper).to receive(:current_user).and_return(user)
allow(user).to receive(:admin?).and_return(true)
end
it do
expect(subject).to eq(
[
{ text: 'Admin', variant: 'success' },
{ text: 'Is using seat', variant: 'light' },
{ text: "It's you!", variant: nil }
]
)
end
end
it { expect(subject).to eq([text: 'Is using seat', variant: 'light']) }
end end
it { expect(subject).to eq([]) } context 'when user does not use a license seat' do
before do
allow(user).to receive(:using_license_seat?).and_return(false)
end
it { expect(subject).to eq([]) }
end
end end
end end
end end
...@@ -638,6 +638,22 @@ describe User do ...@@ -638,6 +638,22 @@ 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
let(:user) { create(:user, bot_type: 'support_bot') }
it 'returns false' do
expect(user.using_license_seat?).to eq false
end
end
context 'when user is a ghost' do
let(:user) { create(:user, ghost: true) }
it 'returns false' do
expect(user.using_license_seat?).to eq false
end
end
context 'when license is nil (core/free/default)' do context 'when license is nil (core/free/default)' do
before do before do
allow(License).to receive(:current).and_return(nil) allow(License).to receive(:current).and_return(nil)
......
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