Commit 50fd0c36 authored by Alper Akgun's avatar Alper Akgun Committed by James Lopez

"Start a trial" menu item in top user dropdown

Users are used to find trial and upgrade links in the user menu in
most applications. We add this to top user menu only for gitlab.com
users which are eligible for trials
parent 6cfc61ab
......@@ -95,6 +95,14 @@ module UsersHelper
tabs
end
def trials_link_url
'https://about.gitlab.com/free-trial/'
end
def trials_allowed?(user)
false
end
def get_current_user_menu_items
items = []
......@@ -105,6 +113,7 @@ module UsersHelper
items << :help
items << :profile if can?(current_user, :read_user, current_user)
items << :settings if can?(current_user, :update_user, current_user)
items << :start_trial if trials_allowed?(current_user)
items
end
......
......@@ -18,6 +18,11 @@
- if current_user_menu?(:profile)
%li
= link_to s_("CurrentUser|Profile"), current_user, class: 'profile-link', data: { user: current_user.username }
- if current_user_menu?(:start_trial)
%li
%a.profile-link{ href: trials_link_url }
= s_("CurrentUser|Start a trial")
= emoji_icon('rocket')
- if current_user_menu?(:settings)
%li
= link_to s_("CurrentUser|Settings"), profile_path, data: { qa_selector: 'settings_link' }
......
---
title: Add start a trial option in the top-right user dropdown
merge_request: 19632
author:
type: added
......@@ -5,5 +5,19 @@ module EE
def users_sentence(users, link_class: nil)
users.map { |user| link_to(user.name, user, class: link_class) }.to_sentence.html_safe
end
def trials_link_url
new_trial_registration_path
end
private
def trials_allowed?(user)
return unless user
return unless ::Gitlab.com?
return unless ::Feature.enabled?(:improved_trial_signup)
user.any_namespace_without_trial?
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe UsersHelper do
describe '#current_user_menu_items' do
let(:user) { create(:user) }
using RSpec::Parameterized::TableSyntax
subject(:items) { helper.current_user_menu_items }
where(:user?, :gitlab_com?, :improved_trial_signup_feature_enabled?, :user_eligible?, :should_include_start_trial?) do
true | true | true | true | true
true | true | true | false | false
true | true | false | true | false
true | true | false | false | false
true | false | true | true | false
true | false | true | false | false
true | false | false | true | false
true | false | false | false | false
false | true | true | true | false
false | true | true | false | false
false | true | false | true | false
false | true | false | false | false
false | false | true | true | false
false | false | true | false | false
false | false | false | true | false
false | false | false | false | false
end
with_them do
before do
allow(helper).to receive(:current_user) { user? ? user : nil }
allow(helper).to receive(:can?).and_return(false)
allow(::Gitlab).to receive(:com?) { gitlab_com? }
stub_feature_flags(improved_trial_signup: improved_trial_signup_feature_enabled?)
allow(user).to receive(:any_namespace_without_trial?) { user_eligible? }
end
it do
if should_include_start_trial?
expect(items).to include(:start_trial)
else
expect(items).not_to include(:start_trial)
end
end
end
end
end
......@@ -4958,6 +4958,9 @@ msgstr ""
msgid "CurrentUser|Settings"
msgstr ""
msgid "CurrentUser|Start a trial"
msgstr ""
msgid "Custom CI configuration path"
msgstr ""
......
......@@ -76,6 +76,10 @@ describe UsersHelper do
allow(helper).to receive(:can?).and_return(false)
end
after do
expect(items).not_to include(:start_trial)
end
it 'includes all default items' do
expect(items).to include(:help, :sign_out)
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