Commit 39ac64a8 authored by Stan Hu's avatar Stan Hu

Merge branch '295308-subscription-banner-owners-only' into 'master'

Show subscription expiration banner only for top-level group owners

See merge request gitlab-org/gitlab!54908
parents 6ebd07e7 be326b7f
...@@ -51,7 +51,7 @@ module EE ...@@ -51,7 +51,7 @@ module EE
::Gitlab::ExpiringSubscriptionMessage.new( ::Gitlab::ExpiringSubscriptionMessage.new(
subscribable: decorated_subscription, subscribable: decorated_subscription,
signed_in: signed_in?, signed_in: signed_in?,
is_admin: can?(current_user, :owner_access, entity), is_admin: can?(current_user, :owner_access, entity.root_ancestor),
namespace: current_namespace namespace: current_namespace
).message ).message
end end
......
---
title: Show subscription expiration banner only for top-level group owners
merge_request: 54908
author:
type: changed
...@@ -16,60 +16,42 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -16,60 +16,42 @@ RSpec.describe EE::SubscribableBannerHelper do
end end
end end
context 'when feature flag is enabled' do let(:license) { double(:license) }
let(:license) { double(:license) }
context 'when instance variable true' do
before do before do
stub_feature_flags(subscribable_banner: true) assign(:display_subscription_banner, true)
end end
context 'when instance variable true' do context 'when should_check_namespace_plan is true' do
before do before do
assign(:display_subscription_banner, true) allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end end
context 'when should_check_namespace_plan is true' do context 'when a project exists' do
before do let(:entity) { create(:project) }
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
context 'when a project exists' do
let(:entity) { create(:project) }
before do
assign(:project, entity)
end
it_behaves_like 'when a subscription exists' before do
assign(:project, entity)
end end
context 'when a group exists' do it_behaves_like 'when a subscription exists'
let(:entity) { create(:group) }
before do
assign(:group, entity)
end
it_behaves_like 'when a subscription exists'
end
end end
context 'when should_check_namespace_plan is false' do context 'when a group exists' do
let(:entity) { create(:group) }
before do before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(false) assign(:group, entity)
end end
it 'returns the current license' do it_behaves_like 'when a subscription exists'
expect(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end
end end
end end
context 'when instance variable false' do context 'when should_check_namespace_plan is false' do
before do before do
assign(:display_subscription_banner, false) allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(false)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end end
it 'returns the current license' do it 'returns the current license' do
...@@ -77,18 +59,30 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -77,18 +59,30 @@ RSpec.describe EE::SubscribableBannerHelper do
expect(subject).to eq(license) expect(subject).to eq(license)
end end
end end
end
context 'with a future dated license' do context 'when instance variable false' do
let(:gl_license) { build(:gitlab_license, starts_at: Date.current + 1.month) } before do
assign(:display_subscription_banner, false)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
before do it 'returns the current license' do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true) expect(License).to receive(:current).and_return(license)
end expect(subject).to eq(license)
end
end
it 'returns the current license' do context 'with a future dated license' do
allow(License).to receive(:current).and_return(license) let(:gl_license) { build(:gitlab_license, starts_at: Date.current + 1.month) }
expect(subject).to eq(license)
end before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
it 'returns the current license' do
allow(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end end
end end
end end
...@@ -98,9 +92,9 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -98,9 +92,9 @@ RSpec.describe EE::SubscribableBannerHelper do
let(:message) { double(:message) } let(:message) { double(:message) }
context 'when feature flag is enabled' do context 'when subscribable_subscription_banner feature flag is enabled' do
before do before do
stub_feature_flags(subscribable_banner: true) stub_feature_flags(subscribable_subscription_banner: true)
end end
context 'when instance variable true' do context 'when instance variable true' do
...@@ -122,7 +116,7 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -122,7 +116,7 @@ RSpec.describe EE::SubscribableBannerHelper do
it 'calls Gitlab::ExpiringSubscriptionMessage and SubscriptionPresenter if is Gitlab.com?' do it 'calls Gitlab::ExpiringSubscriptionMessage and SubscriptionPresenter if is Gitlab.com?' do
allow(helper).to receive(:signed_in?).and_return(true) allow(helper).to receive(:signed_in?).and_return(true)
allow(helper).to receive(:current_user).and_return(user) allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?).with(user, :owner_access, entity).and_return(true) allow(helper).to receive(:can?).with(user, :owner_access, root_namespace).and_return(true)
expect(SubscriptionPresenter).to receive(:new).with(gitlab_subscription).and_return(decorated_mock) expect(SubscriptionPresenter).to receive(:new).with(gitlab_subscription).and_return(decorated_mock)
expect(::Gitlab::ExpiringSubscriptionMessage).to receive(:new).with( expect(::Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
...@@ -137,9 +131,11 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -137,9 +131,11 @@ RSpec.describe EE::SubscribableBannerHelper do
end end
end end
let(:root_namespace) { create(:group_with_plan) }
let(:namespace) { create(:group, :nested, parent: root_namespace) }
context 'when a project is present' do context 'when a project is present' do
let(:entity) { create(:project, namespace: namespace) } let(:entity) { create(:project, namespace: namespace) }
let(:namespace) { create(:namespace_with_plan) }
before do before do
assign(:project, entity) assign(:project, entity)
...@@ -149,8 +145,7 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -149,8 +145,7 @@ RSpec.describe EE::SubscribableBannerHelper do
end end
context 'when a group is present' do context 'when a group is present' do
let(:entity) { create(:group_with_plan) } let(:entity) { namespace }
let(:namespace) { entity }
before do before do
assign(:project, nil) assign(:project, nil)
...@@ -200,6 +195,19 @@ RSpec.describe EE::SubscribableBannerHelper do ...@@ -200,6 +195,19 @@ RSpec.describe EE::SubscribableBannerHelper do
end end
end end
end end
context 'when subscribable_subscription_banner feature flag is disabled' do
before do
stub_feature_flags(subscribable_subscription_banner: false)
assign(:display_subscription_banner, true)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
it 'returns the license message' do
expect(helper).to receive(:license_message).and_return(message)
expect(subject).to eq(message)
end
end
end end
describe '#display_subscription_banner!' do describe '#display_subscription_banner!' do
......
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