Commit fe2902d6 authored by Corinna Wiesner's avatar Corinna Wiesner

Show all licenses in the license history

This change will show all licenses in the license history and not just
past licenses. Therefore the current license we also be highlighted for
easier identification.
parent 0df5ceb0
......@@ -10,7 +10,7 @@ class Admin::LicensesController < Admin::ApplicationController
if @license.blank?
render :missing
else
@previous_licenses = License.previous
@licenses = License.history
end
end
......
......@@ -230,7 +230,6 @@ class License < ApplicationRecord
after_create :reset_current
after_destroy :reset_current
scope :previous, -> { order(created_at: :desc).offset(1) }
scope :recent, -> { reorder(id: :desc) }
class << self
......@@ -291,6 +290,10 @@ class License < ApplicationRecord
ANY_PLAN_FEATURES.include?(feature)
end
def history
all.sort_by { |license| [license.starts_at, license.created_at, license.expires_at] }.reverse
end
end
def data_filename
......
......@@ -77,7 +77,7 @@
= render "breakdown", license: @license
- if @previous_licenses.any?
- if @licenses.any?
%h4 License History
.card#license_history
......@@ -92,8 +92,8 @@
%th Expires on
%th Active users
%tbody
- @previous_licenses.each do |license|
%tr
- @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) } }
- @license.licensee.keys.each do |label|
%td= license.licensee[label]
%td
......
---
title: Show all licenses and highlight current license in license history
merge_request: 30172
author:
type: added
......@@ -43,16 +43,30 @@ describe "Admin views license" do
end
end
context "when viewing license history" do
context "when viewing license history", :aggregate_failures do
let_it_be(:license) { create(:license) }
it "shows licensee" do
license_history = page.find("#license_history")
License.previous.each do |license|
License.all.each do |license|
expect(license_history).to have_content(license.licensee.each_value.first)
end
end
it "highlights the current license with a css class", :aggregate_failures do
license_history = page.find("#license_history")
highlighted_license_row = license_history.find("[data-testid='license-current']")
expect(highlighted_license_row).to have_content(license.licensee[:name])
expect(highlighted_license_row).to have_content(license.licensee[:email])
expect(highlighted_license_row).to have_content(license.licensee[:company])
expect(highlighted_license_row).to have_content(license.plan.capitalize)
expect(highlighted_license_row).to have_content(license.created_at)
expect(highlighted_license_row).to have_content(license.starts_at)
expect(highlighted_license_row).to have_content(license.expires_at)
expect(highlighted_license_row).to have_content(license.restrictions[:active_user_count])
end
end
end
......
......@@ -737,6 +737,33 @@ describe License do
end
end
describe '.history' do
before(:all) do
described_class.delete_all
end
it 'returns the licenses sorted by created_at, starts_at and expires_at descending' do
today = Date.current
now = Time.current
past_license = create(:license, created_at: now - 1.month, data: build(:gitlab_license, starts_at: today - 1.month, expires_at: today + 11.months).export)
expired_license = create(:license, created_at: now, data: build(:gitlab_license, starts_at: today - 1.year, expires_at: today - 1.month).export)
future_license = create(:license, created_at: now, data: build(:gitlab_license, starts_at: today + 1.month, expires_at: today + 13.months).export)
another_license = create(:license, created_at: now, data: build(:gitlab_license, starts_at: today - 1.month, expires_at: today + 1.year).export)
current_license = create(:license, created_at: now, data: build(:gitlab_license, starts_at: today - 15.days, expires_at: today + 11.months).export)
expect(described_class.history.map(&:id)).to eq(
[
future_license.id,
current_license.id,
another_license.id,
past_license.id,
expired_license.id
]
)
end
end
describe '#edition' do
let(:ultimate) { build(:license, plan: 'ultimate') }
let(:premium) { build(:license, plan: 'premium') }
......
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