Commit 4ddcecab authored by Vitaly Slobodin's avatar Vitaly Slobodin

Do now show user limit banner for overage licenses

parent d59c77bb
......@@ -17,6 +17,9 @@ module LicenseMonitoringHelper
def show_active_user_count_threshold_banner?
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?
end
......@@ -30,7 +33,6 @@ module LicenseMonitoringHelper
end
def active_user_count_threshold_reached?
return if current_license.nil? || current_license.trial?
return if total_user_count.nil? || total_user_count == 1
active_user_count_threshold[:value] >= if active_user_count_threshold[:percentage]
......@@ -48,16 +50,12 @@ module LicenseMonitoringHelper
strong_memoize(:current_license_overage) { current_license.overage_with_historical_max }
end
def current_active_users_count
strong_memoize(:current_active_users_count) { current_license.current_active_users_count }
end
def total_user_count
strong_memoize(:total_user_count) { current_license.restricted_user_count }
end
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
def active_user_count_threshold
......
......@@ -31,12 +31,12 @@ RSpec.describe 'Display approaching user count limit banner', :js do
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
before do
# +1 created admin on line 8
# +1 created user on line 9
create_list(:user, 7)
end
let(:active_user_count) { license_seats_limit - 1 }
context 'when admin is logged in' do
before do
......@@ -44,6 +44,16 @@ RSpec.describe 'Display approaching user count limit banner', :js do
end
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
context 'when regular user is logged in' do
......@@ -75,7 +85,19 @@ RSpec.describe 'Display approaching user count limit banner', :js do
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
let(:active_user_count) { license_seats_limit }
before do
allow(License).to receive(:current).and_return(nil)
end
......@@ -84,6 +106,8 @@ RSpec.describe 'Display approaching user count limit banner', :js do
end
context 'with trial license' do
let(:active_user_count) { license_seats_limit }
before do
allow(License).to receive(:trial?).and_return(true)
end
......
......@@ -11,13 +11,13 @@ RSpec.describe LicenseMonitoringHelper do
create(:license, data: build(:gitlab_license, restrictions: { active_user_count: license_seats_limit }).export)
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
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
before do
allow(helper).to receive(:current_user).and_return(admin)
......@@ -74,27 +74,23 @@ RSpec.describe LicenseMonitoringHelper do
end
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? }
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
before do
allow(helper).to receive(:current_user).and_return(admin)
end
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 }
end
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 }
end
......@@ -106,13 +102,13 @@ RSpec.describe LicenseMonitoringHelper do
end
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 }
end
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 }
end
......@@ -124,13 +120,13 @@ RSpec.describe LicenseMonitoringHelper do
end
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 }
end
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 }
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