Commit ae3c210a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'success_message_for_future_license' into 'master'

Differentiate success messages on license upload

See merge request gitlab-org/gitlab!30161
parents 77099a20 e38287c4
......@@ -36,7 +36,14 @@ class Admin::LicensesController < Admin::ApplicationController
respond_with(@license, location: admin_license_path) do
if @license.save
@license.update_trial_setting
flash[:notice] = _('The license was successfully uploaded and is now active. You can see the details below.')
notice = if @license.started?
_('The license was successfully uploaded and is now active. You can see the details below.')
else
_('The license was successfully uploaded and will be active from %{starts_at}. You can see the details below.' % { starts_at: @license.starts_at })
end
flash[:notice] = notice
end
end
end
......
......@@ -469,6 +469,10 @@ class License < ApplicationRecord
[License::STARTER_PLAN, License::PREMIUM_PLAN, License::ULTIMATE_PLAN].include?(plan)
end
def started?
starts_at <= Date.current
end
private
def restricted_attr(name, default = nil)
......
---
title: Show specific success message when uploading a future license
merge_request: 30161
author:
type: added
......@@ -11,25 +11,35 @@ describe "Admin uploads license" do
end
context "when license key is provided in the query string" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
before do
License.destroy_all # rubocop: disable DestroyAll
visit(admin_license_path(trial_key: license.data))
end
it "installs license" do
page.within("#modal-upload-trial-license") do
expect(page).to have_content("Your trial license was issued").and have_button("Install license")
end
click_button("Install license")
end
context "when license is active immediately" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
it "installs license" do
expect(page).to have_content("The license was successfully uploaded and is now active")
end
end
context "when license starts in the future" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }, starts_at: Date.current + 1.month).export) }
it "installs license" do
expect(page).to have_content("The license was successfully uploaded and will be active from #{license.starts_at}. You can see the details below.")
end
end
end
context "when license key is not provided in the query string, as it is a repeat trial" do
before do
License.destroy_all # rubocop: disable DestroyAll
......@@ -51,9 +61,11 @@ describe "Admin uploads license" do
end
context "when license is valid" do
let_it_be(:license) { build(:gitlab_license) }
let_it_be(:path) { Rails.root.join("tmp/valid_license.gitlab-license") }
context "when license is active immediately" do
let_it_be(:license) { build(:gitlab_license) }
it "uploads license" do
attach_and_upload(path)
......@@ -62,6 +74,18 @@ describe "Admin uploads license" do
end
end
context "when license starts in the future" do
let_it_be(:license) { build(:gitlab_license, starts_at: Date.current + 1.month) }
it "uploads license" do
attach_and_upload(path)
expect(page).to have_content("The license was successfully uploaded and will be active from #{license.starts_at}. You can see the details below.")
.and have_content(license.licensee.each_value.first)
end
end
end
context "when license is invalid" do
let_it_be(:license) { build(:gitlab_license, expires_at: Date.yesterday) }
let_it_be(:path) { Rails.root.join("tmp/invalid_license.gitlab-license") }
......
......@@ -808,4 +808,24 @@ describe License do
end
end
end
describe '#started?' do
using RSpec::Parameterized::TableSyntax
where(:starts_at, :result) do
Date.current - 1.month | true
Date.current | true
Date.current + 1.month | false
end
with_them do
let(:gl_license) { build(:gitlab_license, starts_at: starts_at) }
subject { license.started? }
it do
is_expected.to eq(result)
end
end
end
end
......@@ -20660,6 +20660,9 @@ msgstr ""
msgid "The license was successfully uploaded and is now active. You can see the details below."
msgstr ""
msgid "The license was successfully uploaded and will be active from %{starts_at}. You can see the details below."
msgstr ""
msgid "The maximum file size allowed is %{size}."
msgstr ""
......
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