Commit b0a132e6 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'vs-user-limit-count-banner-hide-for-over-license' into 'master'

Do not display user limit count banner for licenses with over capacity

Closes #219996

See merge request gitlab-org/gitlab!33597
parents c2613cd6 4ddcecab
...@@ -17,6 +17,9 @@ module LicenseMonitoringHelper ...@@ -17,6 +17,9 @@ module LicenseMonitoringHelper
def show_active_user_count_threshold_banner? def show_active_user_count_threshold_banner?
return if ::Gitlab.com? return if ::Gitlab.com?
return if current_license.nil? || current_license.trial?
return if user_dismissed?(UserCalloutsHelper::ACTIVE_USER_COUNT_THRESHOLD)
return if license_is_over_capacity?
current_user&.admin? && active_user_count_threshold_reached? current_user&.admin? && active_user_count_threshold_reached?
end end
...@@ -30,7 +33,6 @@ module LicenseMonitoringHelper ...@@ -30,7 +33,6 @@ module LicenseMonitoringHelper
end end
def active_user_count_threshold_reached? def active_user_count_threshold_reached?
return if current_license.nil? || current_license.trial?
return if total_user_count.nil? || total_user_count == 1 return if total_user_count.nil? || total_user_count == 1
active_user_count_threshold[:value] >= if active_user_count_threshold[:percentage] active_user_count_threshold[:value] >= if active_user_count_threshold[:percentage]
...@@ -48,16 +50,12 @@ module LicenseMonitoringHelper ...@@ -48,16 +50,12 @@ module LicenseMonitoringHelper
strong_memoize(:current_license_overage) { current_license.overage_with_historical_max } strong_memoize(:current_license_overage) { current_license.overage_with_historical_max }
end end
def current_active_users_count
strong_memoize(:current_active_users_count) { current_license.current_active_users_count }
end
def total_user_count def total_user_count
strong_memoize(:total_user_count) { current_license.restricted_user_count } strong_memoize(:total_user_count) { current_license.restricted_user_count }
end end
def remaining_user_count def remaining_user_count
strong_memoize(:remaining_user_count) { total_user_count - current_active_users_count } strong_memoize(:remaining_user_count) { total_user_count - current_license.maximum_user_count }
end end
def active_user_count_threshold def active_user_count_threshold
......
...@@ -31,12 +31,12 @@ RSpec.describe 'Display approaching user count limit banner', :js do ...@@ -31,12 +31,12 @@ RSpec.describe 'Display approaching user count limit banner', :js do
end end
end end
before do
create(:historical_data, date: license.created_at + 1.month, active_user_count: active_user_count)
end
context 'with reached user count threshold' do context 'with reached user count threshold' do
before do let(:active_user_count) { license_seats_limit - 1 }
# +1 created admin on line 8
# +1 created user on line 9
create_list(:user, 7)
end
context 'when admin is logged in' do context 'when admin is logged in' do
before do before do
...@@ -44,6 +44,16 @@ RSpec.describe 'Display approaching user count limit banner', :js do ...@@ -44,6 +44,16 @@ RSpec.describe 'Display approaching user count limit banner', :js do
end end
it_behaves_like 'a visible banner' it_behaves_like 'a visible banner'
context 'when banner was dismissed' do
before do
visit root_dashboard_path
find('.gl-alert-dismiss').click
end
it_behaves_like 'a hidden banner'
end
end end
context 'when regular user is logged in' do context 'when regular user is logged in' do
...@@ -75,7 +85,19 @@ RSpec.describe 'Display approaching user count limit banner', :js do ...@@ -75,7 +85,19 @@ RSpec.describe 'Display approaching user count limit banner', :js do
end end
end end
context 'when active user count is above license user count' do
let(:active_user_count) { license_seats_limit + 2 }
before do
gitlab_sign_in(admin)
end
it_behaves_like 'a hidden banner'
end
context 'without license' do context 'without license' do
let(:active_user_count) { license_seats_limit }
before do before do
allow(License).to receive(:current).and_return(nil) allow(License).to receive(:current).and_return(nil)
end end
...@@ -84,6 +106,8 @@ RSpec.describe 'Display approaching user count limit banner', :js do ...@@ -84,6 +106,8 @@ RSpec.describe 'Display approaching user count limit banner', :js do
end end
context 'with trial license' do context 'with trial license' do
let(:active_user_count) { license_seats_limit }
before do before do
allow(License).to receive(:trial?).and_return(true) allow(License).to receive(:trial?).and_return(true)
end end
......
...@@ -11,13 +11,13 @@ RSpec.describe LicenseMonitoringHelper do ...@@ -11,13 +11,13 @@ RSpec.describe LicenseMonitoringHelper do
create(:license, data: build(:gitlab_license, restrictions: { active_user_count: license_seats_limit }).export) create(:license, data: build(:gitlab_license, restrictions: { active_user_count: license_seats_limit }).export)
end end
before do
create(:historical_data, date: license.created_at + 1.month, active_user_count: active_user_count)
end
describe '#show_users_over_license_banner?' do describe '#show_users_over_license_banner?' do
subject { helper.show_users_over_license_banner? } subject { helper.show_users_over_license_banner? }
before do
create(:historical_data, date: license.created_at + 1.month, active_user_count: active_user_count)
end
context 'when admin is logged in' do context 'when admin is logged in' do
before do before do
allow(helper).to receive(:current_user).and_return(admin) allow(helper).to receive(:current_user).and_return(admin)
...@@ -74,27 +74,23 @@ RSpec.describe LicenseMonitoringHelper do ...@@ -74,27 +74,23 @@ RSpec.describe LicenseMonitoringHelper do
end end
describe '#show_active_user_count_threshold_banner?' do describe '#show_active_user_count_threshold_banner?' do
let_it_be(:current_active_users_count) { 1 } let_it_be(:active_user_count) { 1 }
subject { helper.show_active_user_count_threshold_banner? } subject { helper.show_active_user_count_threshold_banner? }
before do
allow(helper).to receive(:current_active_users_count).and_return(current_active_users_count)
end
context 'when admin user is logged in' do context 'when admin user is logged in' do
before do before do
allow(helper).to receive(:current_user).and_return(admin) allow(helper).to receive(:current_user).and_return(admin)
end end
context 'when active users count is above the threshold' do context 'when active users count is above the threshold' do
let(:current_active_users_count) { license_seats_limit - 1 } let(:active_user_count) { license_seats_limit - 1 }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when active users count is below the threshold' do context 'when active users count is below the threshold' do
let(:current_active_users_count) { 1 } let(:active_user_count) { 1 }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
...@@ -106,13 +102,13 @@ RSpec.describe LicenseMonitoringHelper do ...@@ -106,13 +102,13 @@ RSpec.describe LicenseMonitoringHelper do
end end
context 'when active users count is above the threshold' do context 'when active users count is above the threshold' do
let(:current_active_users_count) { license_seats_limit - 1 } let(:active_user_count) { license_seats_limit - 1 }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'when active users count is below the threshold' do context 'when active users count is below the threshold' do
let(:current_active_users_count) { 1 } let(:active_user_count) { 1 }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
...@@ -124,13 +120,13 @@ RSpec.describe LicenseMonitoringHelper do ...@@ -124,13 +120,13 @@ RSpec.describe LicenseMonitoringHelper do
end end
context 'when active users count is above the threshold' do context 'when active users count is above the threshold' do
let(:current_active_users_count) { license_seats_limit - 1 } let(:active_user_count) { license_seats_limit - 1 }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'when active users count is below the threshold' do context 'when active users count is below the threshold' do
let(:current_active_users_count) { 1 } let(:active_user_count) { 1 }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
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