Commit 28df9ada authored by Ruben Davila's avatar Ruben Davila

Small refactor and fixes from last code review

parent 482eebb9
......@@ -36,9 +36,7 @@ class TrialsController < ApplicationController
end
def check_presence_of_license
current_license = License.current
if current_license && !current_license.expired?
if License.current&.active?
redirect_to admin_license_url
end
end
......
......@@ -157,10 +157,7 @@ class License < ActiveRecord::Base
end
def block_changes?
return false if current.nil?
return false if current.trial?
current.block_changes?
!!current&.block_changes?
end
def load_license
......@@ -226,8 +223,6 @@ class License < ActiveRecord::Base
# keep `add_ons`, therefore this method needs to be backward-compatible in that sense.
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/2019
def add_ons
return {} if trial? && expired?
explicit_add_ons = restricted_attr(:add_ons, {})
plan_features = self.class.features_for_plan(plan)
......@@ -235,6 +230,8 @@ class License < ActiveRecord::Base
end
def feature_available?(code)
return false if trial? && expired?
feature = FEATURE_CODES.fetch(code)
add_ons[feature].to_i > 0
end
......@@ -265,6 +262,10 @@ class License < ActiveRecord::Base
restricted_attr(:trial)
end
def active?
!expired?
end
def remaining_days
return 0 if expired?
......
......@@ -9,7 +9,7 @@
%h4 You do not have a license.
%p You can start a 30 day free trial for all premium features.
%p You can start a free trial of GitLab Enterprise Edition without any obligation or payment details.
= link_to 'Start free trial', new_trial_url, class: "btn btn-new"
......@@ -425,15 +425,6 @@ describe License do
expect(license.add_ons.keys).to include(License::DEPLOY_BOARD_FEATURE, *eep_features)
end
end
context 'with an expired trial license' do
it 'returns an empty Hash' do
described_class.destroy_all
create(:license, trial: true, expired: true)
expect(described_class.current.add_ons).to be_empty
end
end
end
describe '#feature_available?' do
......@@ -460,6 +451,19 @@ describe License do
expect { license.feature_available?(:invalid) }.to raise_error(KeyError)
end
context 'with an expired trial license' do
before(:all) do
described_class.destroy_all
create(:license, trial: true, expired: true)
end
::License::FEATURE_CODES.keys do |feature_code|
it "returns false for #{feature_code}" do
expect(license.feature_available?(feature_code)).to eq(false)
end
end
end
end
def build_license_with_add_ons(add_ons, plan: nil)
......
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