Commit bc6e5559 authored by Robert Speicher's avatar Robert Speicher

Merge branch '299949-limit-trial-status-widget-experiment-participants' into 'master'

Limit trial status widget experiment participants to group owners

See merge request gitlab-org/gitlab!52537
parents b0a9871c 2959c22b
# frozen_string_literal: true
module TrialStatusWidgetHelper
def eligible_for_trial_status_widget_experiment?(group)
group.trial_active?
end
def show_trial_status_widget?(group)
return false unless ::Gitlab::CurrentSettings.should_check_namespace_plan?
return false unless experiment_enabled?(:show_trial_status_in_sidebar, subject: group)
eligible_for_trial_status_widget_experiment?(group)
billing_plans_and_trials_available? &&
trial_status_widget_experiment_enabled?(group) &&
group.trial_active? &&
user_can_administer_group?(group)
end
def trial_days_remaining_in_words(group)
......@@ -22,4 +18,18 @@ module TrialStatusWidgetHelper
num_of_days
) % { plan: plan_title, num: num_of_days, en_dash: '–' }
end
private
def billing_plans_and_trials_available?
::Gitlab::CurrentSettings.should_check_namespace_plan?
end
def trial_status_widget_experiment_enabled?(group)
experiment_enabled?(:show_trial_status_in_sidebar, subject: group)
end
def user_can_administer_group?(group)
can?(current_user, :admin_namespace, group)
end
end
- return unless show_trial_status_widget?(group)
- root_group = group.root_ancestor
- return unless show_trial_status_widget?(root_group)
= nav_link do
#js-trial-status-widget{ data: { href: group_billings_path(group),
#js-trial-status-widget{ data: { href: group_billings_path(root_group),
nav_icon_image_path: image_path('illustrations/golden_tanuki.svg'),
title: trial_days_remaining_in_words(group),
percentage_complete: group.trial_percentage_complete } }
title: trial_days_remaining_in_words(root_group),
percentage_complete: root_group.trial_percentage_complete } }
......@@ -3,64 +3,65 @@
require 'spec_helper'
RSpec.describe TrialStatusWidgetHelper do
let_it_be(:group) { build(:group) }
let!(:subscription) { build(:gitlab_subscription, :active_trial, namespace: group) }
describe '#show_trial_status_widget?' do
let_it_be(:user) { create(:user) }
describe '#eligible_for_trial_status_widget_experiment?' do
subject { helper.eligible_for_trial_status_widget_experiment?(group) }
let(:trials_available) { true }
let(:experiment_enabled) { true }
let(:trial_active) { true }
let(:user_can_admin_group) { true }
let(:group) { instance_double(Group, trial_active?: trial_active) }
context 'when group has an active trial' do
it { is_expected.to be_truthy }
end
before do
# current_user
allow(helper).to receive(:current_user).and_return(user)
context 'when group does not have an active trial' do
before do
allow(group).to receive(:trial_active?).and_return(false)
end
# billing_plans_and_trials_available?
stub_application_setting(check_namespace_plan: trials_available)
it { is_expected.to be_falsy }
# trial_status_widget_experiment_enabled?(group)
allow(helper).to receive(:experiment_enabled?).with(:show_trial_status_in_sidebar, subject: group).and_return(experiment_enabled)
# user_can_administer_group?(group)
allow(helper).to receive(:can?).and_call_original
allow(helper).to receive(:can?).with(user, :admin_namespace, group).and_return(user_can_admin_group)
end
end
describe '#show_trial_status_widget?' do
let(:experiment_enabled) { true }
let(:eligible_for_experiment) { true }
subject { helper.show_trial_status_widget?(group) }
before do
allow(helper).to receive(:experiment_enabled?).with(:show_trial_status_in_sidebar, subject: group).and_return(experiment_enabled)
allow(helper).to receive(:eligible_for_trial_status_widget_experiment?).and_return(eligible_for_experiment)
context 'when all requirements are met for the widget to be shown' do
it { is_expected.to be_truthy }
end
subject { helper.show_trial_status_widget?(group) }
context 'when the app is not configured for billing plans & trials' do
let(:trials_available) { false }
context 'when the check_namespace_plan application setting is off' do
it { is_expected.to be_falsy }
it { is_expected.to be_falsey }
end
context 'when the check_namespace_plan application setting is on' do
before do
stub_application_setting(check_namespace_plan: true)
end
context 'when the experiment is not active or not enabled for the group' do
let(:experiment_enabled) { false }
context 'and the experiment is enabled and the user is eligible for it' do
it { is_expected.to be_truthy }
end
it { is_expected.to be_falsey }
end
context 'but the experiment is not enabled' do
let(:experiment_enabled) { false }
context 'when the group is not in an active trial' do
let(:trial_active) { false }
it { is_expected.to be_falsy }
end
it { is_expected.to be_falsey }
end
context 'but the user is not eligible for the experiment' do
let(:eligible_for_experiment) { false }
context 'when the user is not an admin/owner of the group' do
let(:user_can_admin_group) { false }
it { is_expected.to be_falsy }
end
it { is_expected.to be_falsey }
end
end
describe '#trial_days_remaining_in_words' do
let_it_be(:group) { build(:group) }
let!(:subscription) { build(:gitlab_subscription, :active_trial, namespace: group) }
subject { helper.trial_days_remaining_in_words(group) }
context 'when there are 0 days remaining' 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