diff --git a/CHANGELOG-EE b/CHANGELOG-EE index 679437d58afd11c6d3fa6248241aee4cbd1410f7..73c29115d3b7f218eaff942a438a32f35aa23014 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 2278725562766c4ea45f40d62dfe59b8f3bc728d..5211199c1f59799f0f677894f5841793fcd82763 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 cb952eb6e74ed7759ad807207e8dd1930161d794..75afba4adf8ac31603643fa0d2ec231c65d1d038 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