Commit 787ac5e9 authored by Ruben Davila's avatar Ruben Davila

Validate when trying to generate trial license for a second time

parent ad9e65ad
......@@ -40,8 +40,22 @@ class Admin::TrialsController < Admin::ApplicationController
end
def check_presence_of_license
if License.current&.active?
redirect_to admin_license_url, alert: 'You already have an active license key installed on this server.'
if error_message.present?
redirect_to admin_license_url, alert: error_message.html_safe
end
end
private
def error_message
@message ||= if License.trial.present?
<<~MSG
You have already used a free trial, if you want to extend it please contact us at
<a href="mailto:sales@gitlab.com">sales@gitlab.com</a>
MSG
elsif License.current&.active?
'You already have an active license key installed on this server.'
end
end
end
......@@ -166,6 +166,10 @@ class License < ActiveRecord::Base
return unless license && license.valid?
license
end
def trial
all.detect { |license| license.trial? }
end
end
def data_filename
......
require 'spec_helper'
feature "Creating trial license", feature: true do
before do
gitlab_sign_in :admin
end
describe 'GET /admin/trials/new' do
context 'without a previous trial license' do
let!(:license_data) { create(:license, trial: true).data }
let(:body) do
{ 'license_key' => license_data }
end
before { License.destroy_all }
it 'allows the creation of the trial license' do
stub_request(:post, "#{Gitlab::SUBSCRIPTIONS_URL}/trials")
.to_return(body: JSON(body), status: 200, headers: { 'Content-Type' => 'application/json' })
visit new_admin_trials_path
fill_in :first_name, with: 'John'
fill_in :last_name, with: 'Doe'
fill_in :work_email, with: 'john@local.dev'
fill_in :company_name, with: 'GitLab'
fill_in :phone_number, with: '111-111111'
fill_in :number_of_developers, with: 50
fill_in :number_of_users, with: 100
select('United States', from: 'Country')
click_button 'Start your free trial'
expect(page).to have_content('Your trial license was successfully activated')
end
end
context 'with an active license' do
it 'does not render the form and shows an error' do
create(:license)
visit new_admin_trials_path
expect(page).to have_content('You already have an active license key installed on this server')
end
end
context 'with a previous expired trial license' do
it 'does not render the form and shows an error' do
create(:license, trial: true, expired: true)
visit new_admin_trials_path
expect(page).to have_content('You have already used a free trial')
end
end
end
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