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,22 +11,32 @@ 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) }
expect(page).to have_content("The license was successfully uploaded and is now active")
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
......@@ -51,14 +61,28 @@ 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") }
it "uploads license" do
attach_and_upload(path)
context "when license is active immediately" do
let_it_be(:license) { build(:gitlab_license) }
it "uploads license" do
attach_and_upload(path)
expect(page).to have_content("The license was successfully uploaded and is now active.")
.and have_content(license.licensee.each_value.first)
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 is now active.")
.and have_content(license.licensee.each_value.first)
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
......
......@@ -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