Commit 4e306ccf authored by Mark Chao's avatar Mark Chao

Update expiry setting when license is created

Fix API license endpoint not updating expiry setting bug.
parent 00d64e00
---
title: Hide repeated trial offers on self-hosted instances
merge_request: 54550
author:
type: fixed
...@@ -39,8 +39,6 @@ class Admin::LicensesController < Admin::ApplicationController ...@@ -39,8 +39,6 @@ class Admin::LicensesController < Admin::ApplicationController
respond_with(@license, location: admin_license_path) do respond_with(@license, location: admin_license_path) do
if @license.save if @license.save
@license.update_trial_setting
notice = if @license.started? notice = if @license.started?
_('The license was successfully uploaded and is now active. You can see the details below.') _('The license was successfully uploaded and is now active. You can see the details below.')
else else
......
...@@ -240,6 +240,7 @@ class License < ApplicationRecord ...@@ -240,6 +240,7 @@ class License < ApplicationRecord
before_validation :reset_license, if: :data_changed? before_validation :reset_license, if: :data_changed?
after_create :reset_current after_create :reset_current
after_create :update_trial_setting
after_destroy :reset_current after_destroy :reset_current
after_commit :reset_future_dated, on: [:create, :destroy] after_commit :reset_future_dated, on: [:create, :destroy]
after_commit :reset_previous, on: [:create, :destroy] after_commit :reset_previous, on: [:create, :destroy]
......
...@@ -1229,9 +1229,9 @@ RSpec.describe License do ...@@ -1229,9 +1229,9 @@ RSpec.describe License do
gl_license.expires_at = Date.tomorrow gl_license.expires_at = Date.tomorrow
end end
it 'returns nil' do it 'does nothing' do
updated = license.update_trial_setting license.save
expect(updated).to be_nil
expect(ApplicationSetting.current.license_trial_ends_on).to be_nil expect(ApplicationSetting.current.license_trial_ends_on).to be_nil
end end
end end
...@@ -1248,10 +1248,9 @@ RSpec.describe License do ...@@ -1248,10 +1248,9 @@ RSpec.describe License do
expect(described_class.eligible_for_trial?).to be_truthy expect(described_class.eligible_for_trial?).to be_truthy
end end
it 'updates the trial setting' do it 'updates the trial setting during create' do
updated = license.update_trial_setting license.save
expect(updated).to be_truthy
expect(described_class.eligible_for_trial?).to be_falsey expect(described_class.eligible_for_trial?).to be_falsey
expect(ApplicationSetting.current.license_trial_ends_on).to eq(tomorrow) expect(ApplicationSetting.current.license_trial_ends_on).to eq(tomorrow)
end end
...@@ -1267,8 +1266,8 @@ RSpec.describe License do ...@@ -1267,8 +1266,8 @@ RSpec.describe License do
end end
it 'does not update existing trial setting' do it 'does not update existing trial setting' do
updated = license.update_trial_setting license.save
expect(updated).to be_falsey
expect(ApplicationSetting.current.license_trial_ends_on).to eq(yesterday) expect(ApplicationSetting.current.license_trial_ends_on).to eq(yesterday)
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