Commit 4a0f1a11 authored by Ruben Davila's avatar Ruben Davila

Add helper method to get remaining days before expiration of the license

parent bcd814ac
class TrialsController < ApplicationController class TrialsController < ApplicationController
before_filter :check_presence_of_license before_action :check_presence_of_license
def new def new
end end
......
...@@ -18,7 +18,7 @@ module LicenseHelper ...@@ -18,7 +18,7 @@ module LicenseHelper
def trial_license_message def trial_license_message
return unless signed_in? && current_license&.trial? return unless signed_in? && current_license&.trial?
return unless 7.days.since(Date.today) >= current_license.expires_at return if current_license.remaining_days > 7
buy_now_link = link_to('Buy now!', "#{Gitlab::SUBSCRIPTIONS_URL}/plans", target: '_blank') buy_now_link = link_to('Buy now!', "#{Gitlab::SUBSCRIPTIONS_URL}/plans", target: '_blank')
message = message =
......
...@@ -265,6 +265,12 @@ class License < ActiveRecord::Base ...@@ -265,6 +265,12 @@ class License < ActiveRecord::Base
restricted_attr(:trial) restricted_attr(:trial)
end end
def remaining_days
return if expired?
(expires_at - Date.today).to_i
end
private private
def restricted_attr(name, default = nil) def restricted_attr(name, default = nil)
......
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
- if @license.will_expire? - if @license.will_expire?
%strong= time_ago_with_tooltip(@license.expires_at) %strong= time_ago_with_tooltip(@license.expires_at)
- if @license.trial? - if @license.trial?
- remaining_days = (@license.expires_at - Date.today).to_i %span= "(Free trial will expire in #{pluralize(@license.remaining_days, 'day')})"
%span= "(Free trial will expire in #{pluralize(remaining_days, 'day')})"
- else - else
%strong Never %strong Never
......
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