From 99720002d5f95642eaf096f217cf6b355351a524 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 10 May 2016 10:51:09 -0700 Subject: [PATCH] Use current active user count to determine whether license is valid. Previously, the EE license check used the historical maximum to determine whether an admin has enough seats for the license. Let's say a customer has a 5-seat license, and sometime during the year he had 20 users. If he/she trims back to 4 users, the 5-seat license won't work anymore. Right now the workaround is to issue a license for 20 users. Closes #550 --- CHANGELOG-EE | 1 + app/models/license.rb | 4 ++-- spec/models/license_spec.rb | 37 +++++++------------------------------ 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/CHANGELOG-EE b/CHANGELOG-EE index 679437d58afd11..73c29115d3b7f2 100644 --- a/CHANGELOG-EE +++ b/CHANGELOG-EE @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.8.0 (unreleased) + - Use current active user count to determine whether license is valid - [Elastic] Database indexer prints its status - [Elastic][Fix] Database indexer skips projects with invalid HEAD reference - [Elastic] More efficient snippets search diff --git a/app/models/license.rb b/app/models/license.rb index 2278725562766c..5211199c1f5979 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -108,7 +108,7 @@ def active_user_count restricted_user_count = self.restrictions[:active_user_count] date_range = (self.starts_at - 1.year)..self.starts_at - active_user_count = HistoricalData.during(date_range).maximum(:active_user_count) || 0 + active_user_count = User.active.count return unless active_user_count @@ -117,7 +117,7 @@ def active_user_count overage = active_user_count - restricted_user_count message = "" - message << "During the year before this license started, this GitLab installation had " + message << "This GitLab installation currently has " message << "#{number_with_delimiter active_user_count} active #{"user".pluralize(active_user_count)}, " message << "exceeding this license's limit of #{number_with_delimiter restricted_user_count} by " message << "#{number_with_delimiter overage} #{"user".pluralize(overage)}. " diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index cb952eb6e74ed7..75afba4adf8ac3 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -23,10 +23,13 @@ end end - describe "Historical active user count" do + describe "Active user count" do let(:active_user_count) { User.active.count + 10 } let(:date) { License.current.starts_at } - let!(:historical_data) { HistoricalData.create!(date: date, active_user_count: active_user_count) } + + before do + allow(User).to receive(:active).and_return(Array.new(active_user_count)) + end context "when there is no active user count restriction" do it "is valid" do @@ -39,34 +42,8 @@ gl_license.restrictions = { active_user_count: active_user_count - 1 } end - context "when the license started" do - it "is invalid" do - expect(license).not_to be_valid - end - end - - context "after the license started" do - let(:date) { Date.today } - - it "is valid" do - expect(license).to be_valid - end - end - - context "in the year before the license started" do - let(:date) { License.current.starts_at - 6.months } - - it "is invalid" do - expect(license).not_to be_valid - end - end - - context "earlier than a year before the license started" do - let(:date) { License.current.starts_at - 2.years } - - it "is valid" do - expect(license).to be_valid - end + it "is invalid" do + expect(license).not_to be_valid end end -- GitLab