Commit 8022fef7 authored by Corinna Wiesner's avatar Corinna Wiesner

Show specific content for future-dated licenses

When a current license already exists and a future-dated license is
uploaded the current license's information and breakdown as well as a
license history is displayed. But when no current license exists and a
future-dated license is uploaded then an information message and the
license history is displayed.
parent dc2fbc70
...@@ -7,10 +7,10 @@ class Admin::LicensesController < Admin::ApplicationController ...@@ -7,10 +7,10 @@ class Admin::LicensesController < Admin::ApplicationController
respond_to :html respond_to :html
def show def show
if @license.blank? if @license.present? || License.future_dated_only?
render :missing
else
@licenses = License.history @licenses = License.history
else
render :missing
end end
end end
...@@ -65,6 +65,7 @@ class Admin::LicensesController < Admin::ApplicationController ...@@ -65,6 +65,7 @@ class Admin::LicensesController < Admin::ApplicationController
def license def license
@license ||= begin @license ||= begin
License.reset_current License.reset_current
License.reset_future_dated
License.current License.current
end end
end end
......
...@@ -5,13 +5,21 @@ ...@@ -5,13 +5,21 @@
- else - else
%h3.page-title %h3.page-title
Your License Your License
- if @license.trial? - if @license&.trial?
= render "upload_buy_license" = render "upload_buy_license"
- else - else
= link_to 'Upload New License', new_admin_license_path, class: "btn btn-success float-right" = link_to 'Upload New License', new_admin_license_path, class: "btn btn-success float-right"
%hr %hr
- if License.future_dated_only?
.gl-alert.gl-alert-info
= sprite_icon('information-o', size: 16, css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title')
.gl-alert-body
%h4.gl-alert-title= s_('You do not have an active license')
= s_('You have a license(s) that activates at a future date. Please see the License History table below.')
- if @license.present?
.row .row
.col-md-6 .col-md-6
.card .card
...@@ -78,13 +86,15 @@ ...@@ -78,13 +86,15 @@
= render "breakdown", license: @license = render "breakdown", license: @license
- if @licenses.any? - if @licenses.any?
- licensee_keys = @licenses.first.licensee.keys
%h4 License History %h4 License History
.card#license_history .card#license_history
%table.table %table.table
%thead.card-header %thead.card-header
%tr %tr
- @license.licensee.keys.each do |label| - licensee_keys.each do |label|
%th= label %th= label
%th Plan %th Plan
%th Uploaded on %th Uploaded on
...@@ -94,7 +104,7 @@ ...@@ -94,7 +104,7 @@
%tbody %tbody
- @licenses.each do |license| - @licenses.each do |license|
%tr{ class: ('gl-bg-blue-50 font-weight-bold gl-text-blue-500' if license == @license), data: { testid: ('license-current' if license == @license) } } %tr{ class: ('gl-bg-blue-50 font-weight-bold gl-text-blue-500' if license == @license), data: { testid: ('license-current' if license == @license) } }
- @license.licensee.keys.each do |label| - licensee_keys.each do |label|
%td= license.licensee[label] %td= license.licensee[label]
%td %td
%span %span
......
---
title: Show specific content for future-dated licenses
merge_request: 31463
author:
type: added
...@@ -36,6 +36,7 @@ describe "Admin uploads license" do ...@@ -36,6 +36,7 @@ describe "Admin uploads license" do
it "installs license" do 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.") 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("You have a license(s) that activates at a future date. Please see the License History table below.")
end end
end end
end end
...@@ -77,6 +78,7 @@ describe "Admin uploads license" do ...@@ -77,6 +78,7 @@ describe "Admin uploads license" do
context "when license starts in the future" do context "when license starts in the future" do
let_it_be(:license) { build(:gitlab_license, starts_at: Date.current + 1.month) } let_it_be(:license) { build(:gitlab_license, starts_at: Date.current + 1.month) }
context "when a current license exists" do
it "uploads license" do it "uploads license" do
attach_and_upload(path) attach_and_upload(path)
...@@ -84,6 +86,21 @@ describe "Admin uploads license" do ...@@ -84,6 +86,21 @@ describe "Admin uploads license" do
.and have_content(license.licensee.each_value.first) .and have_content(license.licensee.each_value.first)
end end
end end
context "when no current license exists" do
before do
allow(License).to receive(:current).and_return(nil)
end
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)
.and have_content("You have a license(s) that activates at a future date. Please see the License History table below.")
end
end
end
end end
context "when license is invalid" do context "when license is invalid" do
......
...@@ -44,12 +44,10 @@ describe "Admin views license" do ...@@ -44,12 +44,10 @@ describe "Admin views license" do
end end
context "when viewing license history", :aggregate_failures do context "when viewing license history", :aggregate_failures do
let_it_be(:license) { create(:license) }
it "shows licensee" do it "shows licensee" do
license_history = page.find("#license_history") license_history = page.find("#license_history")
License.all.each do |license| License.history.each do |license|
expect(license_history).to have_content(license.licensee.each_value.first) expect(license_history).to have_content(license.licensee.each_value.first)
end end
end end
...@@ -83,4 +81,44 @@ describe "Admin views license" do ...@@ -83,4 +81,44 @@ describe "Admin views license" do
end end
end end
end end
context "when existing licenses only contain a future-dated license" do
let_it_be(:license) { create(:license, data: create(:gitlab_license, starts_at: Date.current + 1.month).export) }
before do
License.where.not(id: license.id).delete_all
visit(admin_license_path)
end
context "when viewing license history" do
it "shows licensee" do
license_history = page.find("#license_history")
expect(license_history).to have_content(license.licensee.each_value.first)
end
it "has no highlighted license", :aggregate_failures do
license_history = page.find("#license_history")
expect(license_history).not_to have_selector("[data-testid='license-current']")
end
it "shows only the future-dated license", :aggregate_failures do
license_history = page.find("#license_history")
license_history_row = license_history.find('tbody tr', match: :first)
expect(license_history).to have_css('tbody tr', count: 1)
expect(license_history_row).to have_content(license.licensee[:name])
expect(license_history_row).to have_content(license.licensee[:email])
expect(license_history_row).to have_content(license.licensee[:company])
expect(license_history_row).to have_content(license.plan.capitalize)
expect(license_history_row).to have_content(license.created_at)
expect(license_history_row).to have_content(license.starts_at)
expect(license_history_row).to have_content(license.expires_at)
expect(license_history_row).to have_content(license.restrictions[:active_user_count])
end
end
end
end end
...@@ -24606,6 +24606,9 @@ msgstr "" ...@@ -24606,6 +24606,9 @@ msgstr ""
msgid "You didn't renew your %{strong}%{plan_name}%{strong_close} subscription so it was downgraded to the GitLab Core Plan." msgid "You didn't renew your %{strong}%{plan_name}%{strong_close} subscription so it was downgraded to the GitLab Core Plan."
msgstr "" msgstr ""
msgid "You do not have an active license"
msgstr ""
msgid "You do not have any subscriptions yet" msgid "You do not have any subscriptions yet"
msgstr "" msgstr ""
...@@ -24654,6 +24657,9 @@ msgstr "" ...@@ -24654,6 +24657,9 @@ msgstr ""
msgid "You don’t have access to Value Stream Analytics for this group" msgid "You don’t have access to Value Stream Analytics for this group"
msgstr "" msgstr ""
msgid "You have a license(s) that activates at a future date. Please see the License History table below."
msgstr ""
msgid "You have been granted %{access_level} access to the %{source_link} %{source_type}." msgid "You have been granted %{access_level} access to the %{source_link} %{source_type}."
msgstr "" 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