diff --git a/app/models/license.rb b/app/models/license.rb index 6d4ed3f2ba..fee3cfe11e 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -96,15 +96,18 @@ class License < ActiveRecord::Base return unless self.license? && self.restricted?(:active_user_count) restricted_user_count = self.restrictions[:active_user_count] + + date_range = (self.issued_at - 1.year)..self.issued_at + active_user_count = HistoricalData.during(date_range).maximum(:active_user_count) || 0 - active_user_count = HistoricalData.up_until(self.issued_at).maximum(:active_user_count) || 0 + return unless active_user_count return if active_user_count < restricted_user_count overage = active_user_count - restricted_user_count message = "" - message << "At one point, this GitLab installation had " + message << "During the year before this license was issued, this GitLab installation had " 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/app/views/admin/licenses/show.html.haml b/app/views/admin/licenses/show.html.haml index 3b4c960de7..021d4d65c6 100644 --- a/app/views/admin/licenses/show.html.haml +++ b/app/views/admin/licenses/show.html.haml @@ -65,7 +65,8 @@ %strong Exceeds license limit - - historical = HistoricalData.up_until(@license.issued_at).maximum(:active_user_count) + - date_range = (Date.today - 1.year)..Date.today + - historical = HistoricalData.during(date_range).maximum(:active_user_count) - if historical %li %span.light Maximum active users: diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index 94707f36dd..165c9b16f9 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -53,13 +53,21 @@ describe License do end end - context "before the license was issued" do + context "in the year before the license was issued" do let(:date) { License.current.issued_at - 6.months } it "is invalid" do expect(license).to_not be_valid end end + + context "earlier than a year before the license was issued" do + let(:date) { License.current.issued_at - 2.years } + + it "is valid" do + expect(license).to be_valid + end + end end context "when the active user count restriction is not exceeded" do