Commit fda2b5ad authored by Douwe Maan's avatar Douwe Maan

Only look at year before license was issued.

parent d180f404
......@@ -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)}. "
......
......@@ -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:
......
......@@ -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
......
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