Commit 82808dc3 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch...

Merge branch '260378-free-gitlab-com-namespaces-should-display-seats-currently-in-use' into 'master'

Return seats in use for free or trial subscriptions

See merge request gitlab-org/gitlab!44973
parents f15d0f5d 15f4fd53
......@@ -56,7 +56,9 @@ export default () => ({
value: null,
colClass: 'number',
popover: {
content: s__('SubscriptionTable|Usage count is performed once a day at 12:00 PM.'),
content: s__(
'SubscriptionTable|This is the number of seats you will be required to purchase if you update to a paid plan.',
),
},
},
{
......
......@@ -2,6 +2,7 @@
class GitlabSubscription < ApplicationRecord
include EachBatch
include Gitlab::Utils::StrongMemoize
default_value_for(:start_date) { Date.today }
before_update :log_previous_state_for_update
......@@ -90,8 +91,23 @@ class GitlabSubscription < ApplicationRecord
self.hosted_plan = Plan.find_by(name: code)
end
# We need to show seats in use for free or trial subscriptions
# in order to make it easy for customers to get this information.
def seats_in_use
return super unless Feature.enabled?(:seats_in_use_for_free_or_trial)
return super if has_a_paid_hosted_plan? || !hosted?
seats_in_use_now
end
private
def seats_in_use_now
strong_memoize(:seats_in_use_now) do
calculate_seats_in_use
end
end
def log_previous_state_for_update
attrs = self.attributes.merge(self.attributes_in_database)
log_previous_state_to_history(:gitlab_subscription_updated, attrs)
......
......@@ -9,7 +9,7 @@
- plans_data.each do |plan|
= render 'shared/billings/billing_plan', namespace: namespace, plan: plan, current_plan: current_plan
- if namespace.actual_plan&.paid?
- if namespace.gitlab_subscription&.has_a_paid_hosted_plan?
.center.gl-mb-7
&= s_('BillingPlans|If you would like to downgrade your plan please contact %{support_link_start}Customer Support%{support_link_end}.').html_safe % { support_link_start: support_link_start, support_link_end: support_link_end }
......
---
title: Return seats in use for free or trial subscriptions
merge_request: 44973
author:
type: changed
---
name: seats_in_use_for_free_or_trial
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44973
rollout_issue_url:
type: development
group: group::provision
default_enabled: false
......@@ -107,6 +107,18 @@ RSpec.describe 'Billing plan pages', :feature do
end
end
shared_examples 'used seats rendering for non paid subscriptions' do
before do
visit page_path
end
it 'displays the number of seats', :js do
page.within('.js-subscription-table') do
expect(page).to have_selector('p.property-value.gl-mt-2.gl-mb-0.number', text: '1')
end
end
end
context 'users profile billing page' do
let(:page_path) { profile_billings_path }
......@@ -343,6 +355,13 @@ RSpec.describe 'Billing plan pages', :feature do
it_behaves_like 'can contact sales'
end
context 'on free' do
let(:plan) { free_plan }
let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan) }
it_behaves_like 'used seats rendering for non paid subscriptions'
end
end
end
......@@ -386,8 +405,8 @@ RSpec.describe 'Billing plan pages', :feature do
expect(page).to have_selector('.js-subscription-table')
end
it_behaves_like 'downgradable plan'
it_behaves_like 'non-upgradable plan'
it_behaves_like 'used seats rendering for non paid subscriptions'
end
end
end
......
......@@ -200,6 +200,79 @@ RSpec.describe GitlabSubscription do
end
end
describe '#seats_in_use' do
let(:group) { create(:group) }
let!(:group_member) { create(:group_member, :developer, user: create(:user), group: group) }
let(:hosted_plan) { nil }
let(:seats_in_use) { 5 }
let(:trial) { false }
let(:gitlab_subscription) do
create(:gitlab_subscription, namespace: group, trial: trial, hosted_plan: hosted_plan, seats_in_use: seats_in_use)
end
shared_examples 'a disabled feature' do
context 'when feature flag is disabled' do
before do
stub_feature_flags(seats_in_use_for_free_or_trial: false)
end
it 'returns the previously calculated seats in use' do
expect(subject).to eq(5)
end
end
end
subject { gitlab_subscription.seats_in_use }
context 'with a paid hosted plan' do
let(:hosted_plan) { gold_plan }
it 'returns the previously calculated seats in use' do
expect(subject).to eq(5)
end
context 'when seats in use is 0' do
let(:seats_in_use) { 0 }
it 'returns 0 too' do
expect(subject).to eq(0)
end
end
end
context 'with a trial plan' do
let(:hosted_plan) { gold_plan }
let(:trial) { true }
it 'returns the current seats in use' do
expect(subject).to eq(1)
end
it_behaves_like 'a disabled feature'
end
context 'with a free plan' do
let(:hosted_plan) { free_plan }
it 'returns the current seats in use' do
expect(subject).to eq(1)
end
it_behaves_like 'a disabled feature'
end
context 'with a self hosted plan' do
before do
gitlab_subscription.update!(namespace: nil)
end
it 'returns the previously calculated seats in use' do
expect(subject).to eq(5)
end
end
end
describe '#expired?' do
let(:gitlab_subscription) { create(:gitlab_subscription, end_date: end_date) }
......
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