Commit cbc62341 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'license_badge_for_self_managed' into 'master'

Rework conditions when user uses license seat and when to show the badge

See merge request gitlab-org/gitlab!23522
parents 5c724bd0 648b8941
......@@ -12,7 +12,7 @@ module EE
def user_badges_in_admin_section(user)
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
badges.insert(it_s_you_index, { text: s_('AdminUsers|Is using seat'), variant: 'light' })
......
......@@ -275,6 +275,7 @@ module EE
def using_license_seat?
return false unless active?
return false if support_bot? || ghost?
return false unless License.current
if License.current.exclude_guests_from_active_count?
......
%li
- unless Gitlab.com?
%li
%span.light= _("Is using license seat:")
%strong
= @user.using_license_seat? ? _("Yes") : _("No")
---
title: Change conditions when user uses license seat
merge_request: 23522
author:
type: fixed
......@@ -38,9 +38,39 @@ describe UsersHelper do
before do
allow(helper).to receive(:current_user).and_return(build(:user))
allow(::Gitlab).to receive(:com?) { gitlab_com? }
end
context 'when Gitlab.com? is true' do
let(:gitlab_com?) { true }
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: "It's you!", variant: nil }
]
)
end
end
it { expect(subject).not_to eq([text: 'Is using seat', variant: 'light']) }
end
context 'with user who is using a license seat' do
context 'when Gitlab.com? is false' do
let(:gitlab_com?) { false }
context 'when user uses a license seat' do
before do
allow(user).to receive(:using_license_seat?).and_return(true)
end
......@@ -65,7 +95,7 @@ describe UsersHelper do
it { expect(subject).to eq([text: 'Is using seat', variant: 'light']) }
end
context 'with user who is not using a license seat' do
context 'when user does not use a license seat' do
before do
allow(user).to receive(:using_license_seat?).and_return(false)
end
......@@ -73,4 +103,5 @@ describe UsersHelper do
it { expect(subject).to eq([]) }
end
end
end
end
......@@ -638,6 +638,22 @@ 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') }
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
before do
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