Skip to content
Snippets Groups Projects
Commit c897e3bf authored by Douwe Maan's avatar Douwe Maan
Browse files

Merge branch 'cherry-fix' into '7-11-stable-ee'

Cherry pick missed cherry picks into stable

cc @sytse @patricio

See merge request !405
parents abeabac3 bf17386a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,6 +3,8 @@ class HistoricalData < ActiveRecord::Base
 
# HistoricalData.during((Date.today - 1.year)..Date.today).average(:active_user_count)
scope :during, ->(range) { where(date: range) }
# HistoricalData.up_until(Date.today - 1.month).average(:active_user_count)
scope :up_until, ->(date) { where("date <= :date", date: date) }
 
class << self
def track!
Loading
Loading
Loading
Loading
@@ -96,17 +96,15 @@ def active_user_count
return unless self.license? && self.restricted?(:active_user_count)
 
restricted_user_count = self.restrictions[:active_user_count]
active_user_count = User.active.count
historical_active_user_count = HistoricalData.maximum(:active_user_count) || 0
 
date_range = (self.starts_at - 1.year)..self.starts_at
active_user_count = HistoricalData.during(date_range).maximum(:active_user_count) || 0
return unless active_user_count
 
return if max_active_user_count < restricted_user_count
return if active_user_count < restricted_user_count
 
overage = max_active_user_count - restricted_user_count
overage = active_user_count - restricted_user_count
 
message = ""
message << "During the year before this license started, this GitLab installation had "
Loading
Loading
@@ -114,7 +112,7 @@ def 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)}. "
message << "Please upload a license for at least "
message << "#{number_with_delimiter max_active_user_count} #{"user".pluralize(max_active_user_count)}."
message << "#{number_with_delimiter active_user_count} #{"user".pluralize(active_user_count)}."
 
self.errors.add(:base, message)
end
Loading
Loading
Loading
Loading
@@ -65,7 +65,8 @@
%strong
Exceeds license limit
 
- historical = HistoricalData.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:
Loading
Loading
Loading
Loading
@@ -8,13 +8,19 @@
end
 
describe ".during" do
it "returns the historical data during the given period" do
it "returns the historical data during the specified period" do
expect(HistoricalData.during(Date.new(2014, 1, 1)..Date.new(2014, 12, 31)).average(:active_user_count)).to eq(650)
end
end
 
describe ".up_until" do
it "returns the historical data up until the specified date" do
expect(HistoricalData.up_until(Date.new(2014, 6, 1)).average(:active_user_count)).to eq(350)
end
end
describe ".at" do
it "returns the historical data at the given date" do
it "returns the historical data at the specified date" do
expect(HistoricalData.at(Date.new(2014, 8, 1)).active_user_count).to eq(800)
end
end
Loading
Loading
Loading
Loading
@@ -44,31 +44,29 @@
expect(license).to_not be_valid
end
end
end
 
context "after the license started" do
let(:date) { Date.today }
 
it "is valid" do
expect(license).to be_valid
it "is valid" do
expect(license).to be_valid
end
end
end
end
 
context "in the year before the license started" do
let(:date) { License.current.starts_at - 6.months }
 
context "when there is no active user count restriction" do
it "is valid" do
expect(license).to be_valid
it "is invalid" do
expect(license).to_not be_valid
end
end
end
 
context "earlier than a year before the license started" do
let(:date) { License.current.starts_at - 2.years }
 
it "is invalid" do
expect(license).to_not be_valid
it "is valid" do
expect(license).to be_valid
end
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment