Commit a55576d0 authored by Imre Farkas's avatar Imre Farkas

Merge branch '35440-Hide-start-trial-buttons-for-expired-namespaces' into 'master'

Hide repeated trial offers on self-hosted instances

See merge request gitlab-org/gitlab!19511
parents 0ada9da5 236d5f0f
---
title: Hide repeated trial offers on self-hosted instances
merge_request: 19511
author:
type: changed
# frozen_string_literal: true
class AddLicenseDetailsToApplicationSettings < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :application_settings, :license_trial_ends_on, :date, null: true
end
end
...@@ -345,6 +345,7 @@ ActiveRecord::Schema.define(version: 2019_11_05_140942) do ...@@ -345,6 +345,7 @@ ActiveRecord::Schema.define(version: 2019_11_05_140942) do
t.boolean "pendo_enabled", default: false, null: false t.boolean "pendo_enabled", default: false, null: false
t.string "pendo_url", limit: 255 t.string "pendo_url", limit: 255
t.integer "deletion_adjourned_period", default: 7, null: false t.integer "deletion_adjourned_period", default: 7, null: false
t.date "license_trial_ends_on"
t.boolean "eks_integration_enabled", default: false, null: false t.boolean "eks_integration_enabled", default: false, null: false
t.string "eks_account_id", limit: 128 t.string "eks_account_id", limit: 128
t.string "eks_access_key_id", limit: 128 t.string "eks_access_key_id", limit: 128
......
...@@ -35,6 +35,7 @@ class Admin::LicensesController < Admin::ApplicationController ...@@ -35,6 +35,7 @@ class Admin::LicensesController < Admin::ApplicationController
respond_with(@license, location: admin_license_path) do respond_with(@license, location: admin_license_path) do
if @license.save if @license.save
@license.update_trial_setting
flash[:notice] = _('The license was successfully uploaded and is now active. You can see the details below.') flash[:notice] = _('The license was successfully uploaded and is now active. You can see the details below.')
end end
end end
......
...@@ -262,6 +262,14 @@ class License < ApplicationRecord ...@@ -262,6 +262,14 @@ class License < ApplicationRecord
def global_feature?(feature) def global_feature?(feature)
GLOBAL_FEATURES.include?(feature) GLOBAL_FEATURES.include?(feature)
end end
def eligible_for_trial?
Gitlab::CurrentSettings.license_trial_ends_on.nil?
end
def trial_ends_on
Gitlab::CurrentSettings.license_trial_ends_on
end
end end
def data_filename def data_filename
...@@ -426,6 +434,17 @@ class License < ApplicationRecord ...@@ -426,6 +434,17 @@ class License < ApplicationRecord
historical_max historical_max
end end
def update_trial_setting
return unless license.restrictions[:trial]
return if license.expires_at.nil?
settings = ApplicationSetting.current
return if settings.nil?
return if settings.license_trial_ends_on.present?
settings.update license_trial_ends_on: license.expires_at
end
private private
def restricted_attr(name, default = nil) def restricted_attr(name, default = nil)
......
- page_title "License" - page_title s_('License|License')
%h3.page-title %h3.page-title
Your License = s_('License|Your License')
= render "upload_buy_license" = render "upload_buy_license"
- if params[:trial_key].present? - if params[:trial_key].present?
= render "upload_trial_license" = render "upload_trial_license"
...@@ -13,6 +13,12 @@ ...@@ -13,6 +13,12 @@
.container.blank-state-container .container.blank-state-container
.text-center .text-center
= custom_icon("missing_license") = custom_icon("missing_license")
%h4.qa-missing-license You do not have a license. %h4.qa-missing-license= s_('License|You do not have a license.')
%p.trial-description You can start a free trial of GitLab Ultimate without any obligation or payment details. - if License.eligible_for_trial?
= link_to 'Start free trial', new_trial_url, class: "btn btn-success btn-start-trial prepend-top-10" %p.trial-description= s_('License|You can start a free trial of GitLab Ultimate without any obligation or payment details.')
= link_to 'Start free trial', new_trial_url, target: '_blank', class: "btn btn-success btn-start-trial prepend-top-10"
- else
%p.trial-description
= s_('License|Your free trial of GitLab Ultimate expired on %{trial_ends_on}.').html_safe % {trial_ends_on: License.trial_ends_on}
= s_('License|You can restore access to the Gold features at any time by upgrading.')
= link_to s_('License|Buy license'), ::EE::SUBSCRIPTIONS_PLANS_URL, target: '_blank', rel: 'noopener noreferrer nofollow', class: "btn btn-success btn-buy-license"
...@@ -10,12 +10,56 @@ describe Admin::LicensesController do ...@@ -10,12 +10,56 @@ describe Admin::LicensesController do
end end
describe 'Upload license' do describe 'Upload license' do
render_views
it 'redirects back when no license is entered/uploaded' do it 'redirects back when no license is entered/uploaded' do
post :create, params: { license: { data: '' } } post :create, params: { license: { data: '' } }
expect(response).to redirect_to new_admin_license_path expect(response).to redirect_to new_admin_license_path
expect(flash[:alert]).to include 'Please enter or upload a license.' expect(flash[:alert]).to include 'Please enter or upload a license.'
end end
it 'renders new with an alert when an invalid license is entered/uploaded' do
post :create, params: { license: { data: 'GA!89-)GaRBAGE' } }
expect(response).to render_template(:new)
expect(response.body).to include('The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.')
end
it 'redirects to show when a valid license is entered/uploaded' do
gl_license = build(:gitlab_license, restrictions: {
trial: false,
plan: License::PREMIUM_PLAN,
active_user_count: 1,
previous_user_count: 1
})
license = build(:license, data: gl_license.export)
post :create, params: { license: { data: license.data } }
expect(response).to redirect_to(admin_license_path)
end
context 'Trials' do
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
it 'redirects to show when a valid trial license is entered/uploaded' do
gl_license = build(:gitlab_license,
expires_at: Date.tomorrow,
restrictions: {
trial: true,
plan: License::PREMIUM_PLAN,
active_user_count: 1,
previous_user_count: 1
})
license = build(:license, data: gl_license.export)
post :create, params: { license: { data: license.data } }
expect(response).to redirect_to(admin_license_path)
end
end
end end
describe 'GET show' do describe 'GET show' do
......
...@@ -647,6 +647,67 @@ describe License do ...@@ -647,6 +647,67 @@ describe License do
end end
end end
describe 'Trial Licenses' do
before do
ApplicationSetting.create_from_defaults
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
describe 'Update trial setting' do
context 'when the license is not trial' do
before do
gl_license.restrictions = { trial: false }
gl_license.expires_at = Date.tomorrow
end
it 'returns nil' do
updated = license.update_trial_setting
expect(updated).to be_nil
expect(ApplicationSetting.current.license_trial_ends_on).to be_nil
end
end
context 'when the license is the very first trial' do
let(:tomorrow) { Date.tomorrow }
before do
gl_license.restrictions = { trial: true }
gl_license.expires_at = tomorrow
end
it 'is eligible for trial' do
expect(described_class.eligible_for_trial?).to be_truthy
end
it 'updates the trial setting' do
updated = license.update_trial_setting
expect(updated).to be_truthy
expect(described_class.eligible_for_trial?).to be_falsey
expect(ApplicationSetting.current.license_trial_ends_on).to eq(tomorrow)
end
end
context 'when the license is a repeated trial' do
let(:yesterday) { Date.yesterday }
before do
gl_license.restrictions = { trial: true }
gl_license.expires_at = Date.tomorrow
ApplicationSetting.current.update license_trial_ends_on: yesterday
end
it 'does not update existing trial setting' do
updated = license.update_trial_setting
expect(updated).to be_falsey
expect(ApplicationSetting.current.license_trial_ends_on).to eq(yesterday)
end
it 'is not eligible for trial' do
expect(described_class.eligible_for_trial?).to be_falsey
end
end
end
end
def set_restrictions(opts) def set_restrictions(opts)
gl_license.restrictions = { gl_license.restrictions = {
active_user_count: opts[:restricted_user_count], active_user_count: opts[:restricted_user_count],
......
...@@ -10103,6 +10103,27 @@ msgstr "" ...@@ -10103,6 +10103,27 @@ msgstr ""
msgid "Licenses" msgid "Licenses"
msgstr "" msgstr ""
msgid "License|Buy license"
msgstr ""
msgid "License|License"
msgstr ""
msgid "License|You can restore access to the Gold features at any time by upgrading."
msgstr ""
msgid "License|You can start a free trial of GitLab Ultimate without any obligation or payment details."
msgstr ""
msgid "License|You do not have a license."
msgstr ""
msgid "License|Your License"
msgstr ""
msgid "License|Your free trial of GitLab Ultimate expired on %{trial_ends_on}."
msgstr ""
msgid "Limit display of time tracking units to hours." msgid "Limit display of time tracking units to hours."
msgstr "" msgstr ""
......
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