Commit 01b2bb37 authored by Ruben Davila's avatar Ruben Davila

Add small fixes and refactors after last code review

parent 2f031c25
......@@ -10,9 +10,13 @@ class Admin::TrialsController < Admin::ApplicationController
if save_license
redirect_to admin_license_url, notice: 'Your trial license was successfully activated'
else
flash.now[:alert] = "An error occurred while generating the trial license, please try again a few minutes.<br>
If the error persist please try by creating the license from
<a href='https://about.gitlab.com/free-trial/' target='_blank'>this page</a>.".html_safe
message = <<~MSG
An error occurred while generating the trial license, please try again a few minutes.<br>
If the error persist please try by creating the license from
<a href="https://about.gitlab.com/free-trial/" target="_blank">this page</a>.
MSG
flash.now[:alert] = message.html_safe
render :new
end
end
......@@ -24,7 +28,7 @@ class Admin::TrialsController < Admin::ApplicationController
def save_license
result = HTTParty.post("#{Gitlab::SUBSCRIPTIONS_URL}/trials", body: params)
if false
if result.ok?
@license.data = result['license_key']
@license.save
else
......
......@@ -12,19 +12,8 @@ module LicenseHelper
HistoricalData.max_historical_user_count
end
def license_message(signed_in: signed_in?, is_admin: (current_user&.admin?))
yes_license_message(signed_in, is_admin) if current_license
end
private
def current_license
return @current_license if defined?(@current_license)
@current_license = License.current
end
def yes_license_message(signed_in, is_admin)
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?)
return unless current_license
return unless signed_in
return unless (is_admin && current_license.notify_admins?) || current_license.notify_users?
......@@ -37,7 +26,7 @@ module LicenseHelper
message << "will expire in #{pluralize(current_license.remaining_days, 'day')}."
end
message << link_to('Buy now!', "#{Gitlab::SUBSCRIPTIONS_URL}/plans", target: '_blank') if is_trial
message << link_to('Buy now!', Gitlab::SUBSCRIPTIONS_PLANS_URL, target: '_blank') if is_trial
if current_license.expired? && current_license.will_block_changes?
message << 'Pushing code and creation of issues and merge requests'
......@@ -64,5 +53,11 @@ module LicenseHelper
message.join(' ').html_safe
end
def current_license
return @current_license if defined?(@current_license)
@current_license = License.current
end
extend self
end
......@@ -157,7 +157,7 @@ class License < ActiveRecord::Base
end
def block_changes?
!!current&.block_changes?
current&.block_changes?
end
def load_license
......
= link_to 'Buy License', "#{Gitlab::SUBSCRIPTIONS_URL}/plans", target: '_blank', rel: 'noopener noreferrer nofollow', class: "btn btn-new btn-inverted pull-right btn-buy-license"
= link_to 'Buy License', Gitlab::SUBSCRIPTIONS_PLANS_URL, target: '_blank', rel: 'noopener noreferrer nofollow', class: "btn btn-new btn-inverted pull-right btn-buy-license"
= link_to 'Upload New License', new_admin_license_path, class: "btn pull-right btn-upload-license append-right-10"
......@@ -35,7 +35,7 @@
Expired:
- else
Expires:
- if @license.will_expire?
- if @license.will_expire? && @license.active?
%strong= time_ago_with_tooltip(@license.expires_at)
- if @license.trial?
%span Free trial will expire in #{pluralize(@license.remaining_days, 'day')}
......
......@@ -4,6 +4,7 @@ module Gitlab
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}
COM_URL = 'https://gitlab.com'.freeze
SUBSCRIPTIONS_URL = 'https://customers.gitlab.com'.freeze
SUBSCRIPTIONS_PLANS_URL = "#{SUBSCRIPTIONS_URL}/plans".freeze
def self.com?
# Check `gl_subdomain?` as well to keep parity with gitlab.com
......
......@@ -16,7 +16,7 @@ describe Admin::LicensesController do
end
end
describe 'GET #show' do
describe 'GET show' do
context 'with an existent license' do
it 'renders the license details' do
allow(License).to receive(:current).and_return(create(:license))
......
......@@ -293,7 +293,7 @@ describe License do
end
it "returns false" do
expect(described_class.block_changes?).to eq(false)
expect(described_class.block_changes?).to be_falsey
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