Commit 236d5f0f authored by Alper Akgun's avatar Alper Akgun Committed by Imre Farkas

Hide repeated trial offers on self-hosted

On self-hosted instances when a trial license expires we currently
offer new repeated trials to the admins. With these changes we track
trial ends date at instance level and do not suggest repeated trials
to admins
parent 0ada9da5
---
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
t.boolean "pendo_enabled", default: false, null: false
t.string "pendo_url", limit: 255
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.string "eks_account_id", limit: 128
t.string "eks_access_key_id", limit: 128
......
......@@ -35,6 +35,7 @@ class Admin::LicensesController < Admin::ApplicationController
respond_with(@license, location: admin_license_path) do
if @license.save
@license.update_trial_setting
flash[:notice] = _('The license was successfully uploaded and is now active. You can see the details below.')
end
end
......
......@@ -262,6 +262,14 @@ class License < ApplicationRecord
def global_feature?(feature)
GLOBAL_FEATURES.include?(feature)
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
def data_filename
......@@ -426,6 +434,17 @@ class License < ApplicationRecord
historical_max
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
def restricted_attr(name, default = nil)
......
- page_title "License"
- page_title s_('License|License')
%h3.page-title
Your License
= s_('License|Your License')
= render "upload_buy_license"
- if params[:trial_key].present?
= render "upload_trial_license"
......@@ -13,6 +13,12 @@
.container.blank-state-container
.text-center
= custom_icon("missing_license")
%h4.qa-missing-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.
= link_to 'Start free trial', new_trial_url, class: "btn btn-success btn-start-trial prepend-top-10"
%h4.qa-missing-license= s_('License|You do not have a license.')
- if License.eligible_for_trial?
%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
end
describe 'Upload license' do
render_views
it 'redirects back when no license is entered/uploaded' do
post :create, params: { license: { data: '' } }
expect(response).to redirect_to new_admin_license_path
expect(flash[:alert]).to include 'Please enter or upload a license.'
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
describe 'GET show' do
......
......@@ -647,6 +647,67 @@ describe License do
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)
gl_license.restrictions = {
active_user_count: opts[:restricted_user_count],
......
......@@ -10103,6 +10103,27 @@ msgstr ""
msgid "Licenses"
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."
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