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
::Gitlab::ExpiringSubscriptionMessage.new(
subscribable: decorated_subscription,
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
).message
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
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
stub_feature_flags(subscribable_banner: true)
assign(:display_subscription_banner, true)
end
context 'when instance variable true' do
context 'when should_check_namespace_plan is true' do
before do
assign(:display_subscription_banner, true)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
context 'when should_check_namespace_plan is true' do
before do
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
context 'when a project exists' do
let(:entity) { create(:project) }
it_behaves_like 'when a subscription exists'
before do
assign(:project, entity)
end
context 'when a group exists' do
let(:entity) { create(:group) }
before do
assign(:group, entity)
end
it_behaves_like 'when a subscription exists'
end
it_behaves_like 'when a subscription exists'
end
context 'when should_check_namespace_plan is false' do
context 'when a group exists' do
let(:entity) { create(:group) }
before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(false)
assign(:group, entity)
end
it 'returns the current license' do
expect(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end
it_behaves_like 'when a subscription exists'
end
end
context 'when instance variable false' do
context 'when should_check_namespace_plan is false' do
before do
assign(:display_subscription_banner, false)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(false)
end
it 'returns the current license' do
......@@ -77,18 +59,30 @@ RSpec.describe EE::SubscribableBannerHelper do
expect(subject).to eq(license)
end
end
end
context 'with a future dated license' do
let(:gl_license) { build(:gitlab_license, starts_at: Date.current + 1.month) }
context 'when instance variable false' do
before do
assign(:display_subscription_banner, false)
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
before do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
it 'returns the current license' do
expect(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end
end
it 'returns the current license' do
allow(License).to receive(:current).and_return(license)
expect(subject).to eq(license)
end
context 'with a future dated license' do
let(:gl_license) { build(:gitlab_license, starts_at: Date.current + 1.month) }
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
......@@ -98,9 +92,9 @@ RSpec.describe EE::SubscribableBannerHelper do
let(:message) { double(:message) }
context 'when feature flag is enabled' do
context 'when subscribable_subscription_banner feature flag is enabled' do
before do
stub_feature_flags(subscribable_banner: true)
stub_feature_flags(subscribable_subscription_banner: true)
end
context 'when instance variable true' do
......@@ -122,7 +116,7 @@ RSpec.describe EE::SubscribableBannerHelper 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(: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(::Gitlab::ExpiringSubscriptionMessage).to receive(:new).with(
......@@ -137,9 +131,11 @@ RSpec.describe EE::SubscribableBannerHelper do
end
end
let(:root_namespace) { create(:group_with_plan) }
let(:namespace) { create(:group, :nested, parent: root_namespace) }
context 'when a project is present' do
let(:entity) { create(:project, namespace: namespace) }
let(:namespace) { create(:namespace_with_plan) }
before do
assign(:project, entity)
......@@ -149,8 +145,7 @@ RSpec.describe EE::SubscribableBannerHelper do
end
context 'when a group is present' do
let(:entity) { create(:group_with_plan) }
let(:namespace) { entity }
let(:entity) { namespace }
before do
assign(:project, nil)
......@@ -200,6 +195,19 @@ RSpec.describe EE::SubscribableBannerHelper do
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
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