Commit de07d0e9 authored by Stan Hu's avatar Stan Hu

Warn admin if current active count exceeds license

Closes #393
parent fcaa2c25
......@@ -9,6 +9,7 @@ v 8.8.0 (unreleased)
- [Elastic] Add rake task for clearing indexing status
- [Elastic] Improve code search
- [Elastic] Fix encoding issues during indexing
- Warn admin if current active count exceeds license
- Set KRB5 as default clone protocol when Kerberos is enabled and user is logged in (Borja Aparicio)
- Reduce emails-on-push HTML size by using a simple monospace font
- API requests to /internal/authorized_keys are now tagged properly
......
module LicenseHelper
def current_active_user_count
User.active.count
end
def license_message(signed_in: signed_in?, is_admin: (current_user && current_user.is_admin?))
@license_message ||=
if License.current
......@@ -33,13 +37,15 @@ module LicenseHelper
return unless signed_in
return unless (license.notify_admins? && is_admin) || license.notify_users?
return unless ((license.notify_admins? || license.warn_upgrade_license_message?) && is_admin) || license.notify_users?
message = []
message << "The GitLab Enterprise Edition license"
message << (license.expired? ? "expired" : "will expire")
message << "on #{license.expires_at}."
unless license.warn_upgrade_license_message?
message << "The GitLab Enterprise Edition license"
message << (license.expired? ? "expired" : "will expire")
message << "on #{license.expires_at}."
end
if license.expired? && license.will_block_changes?
message << "Pushing code and creation of issues and merge requests"
......@@ -50,18 +56,24 @@ module LicenseHelper
else
"will be disabled on #{license.block_changes_at}."
end
end
message <<
if is_admin
"Upload a new license in the admin area"
else
"Ask an admin to upload a new license"
end
message <<
if is_admin
"Upload a new license in the admin area"
else
"Ask an admin to upload a new license"
end
message << "to"
message << (license.block_changes? ? "restore" : "ensure uninterrupted")
message << "service."
message << "to"
message << (license.block_changes? ? "restore" : "ensure uninterrupted")
message << "service."
elsif license.warn_upgrade_license_message?
message << "Your GitLab license currently covers #{license.user_count}"
message << "users, but it looks like your site has grown to"
message << "#{current_active_user_count} users. Please contact"
message << "sales@gitlab.com to increase the seats on your license."
message << "Thank you for choosing GitLab."
end
message.join(" ")
end
......
......@@ -86,6 +86,24 @@ class License < ActiveRecord::Base
add_ons[code].to_i > 0
end
def user_count
return unless self.license? && self.restricted?(:active_user_count)
self.restrictions[:active_user_count]
end
def warn_upgrade_license_message?
restricted_user_count = user_count
return unless restricted_user_count
return false unless Time.now >= self.starts_at + 3.months
active_user_count = User.active.count
restricted_user_count && active_user_count > restricted_user_count
end
private
def reset_current
......@@ -103,9 +121,9 @@ class License < ActiveRecord::Base
end
def active_user_count
return unless self.license? && self.restricted?(:active_user_count)
restricted_user_count = user_count
restricted_user_count = self.restrictions[:active_user_count]
return unless restricted_user_count
date_range = (self.starts_at - 1.year)..self.starts_at
active_user_count = HistoricalData.during(date_range).maximum(:active_user_count) || 0
......
require 'spec_helper'
describe LicenseHelper do
describe '#license_message' do
context 'no license installed' do
before do
expect(License).to receive(:current).and_return(nil)
end
it 'admin user' do
admin_msg = 'No GitLab Enterprise Edition license has been provided yet. Pushing code and creation of issues and merge requests has been disabled. Upload a license in the admin area to activate this functionality.'
expect(license_message(signed_in: true, is_admin: true)).to eq(admin_msg)
end
it 'normal user' do
user_msg = 'No GitLab Enterprise Edition license has been provided yet. Pushing code and creation of issues and merge requests has been disabled. Ask an admin to upload a license to activate this functionality.'
expect(license_message(signed_in: true, is_admin: false)).to eq(user_msg)
end
end
context 'license available' do
let(:license) { create(:license) }
before do
allow(License).to receive(:current).and_return(license)
end
it 'warn for overusage' do
allow(license).to receive(:starts_at).and_return(Time.now - 3.months)
allow(license).to receive(:expired?).and_return(false)
allow(license).to receive(:restricted?).and_return(true)
allow(license).to receive(:notify_admins?).and_return(true)
allow(license).to receive(:restrictions).and_return({ active_user_count: 50 })
allow(User).to receive(:active).and_return(Array.new(100))
warn_msg = 'Your GitLab license currently covers 50 users, but it looks like your site has grown to 100 users. Please contact sales@gitlab.com to increase the seats on your license. Thank you for choosing GitLab.'
expect(license_message(signed_in: true, is_admin: true)).to eq(warn_msg)
end
end
end
end
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