Commit 6d093d84 authored by Douwe Maan's avatar Douwe Maan

Show prettier error message when license file is invalid.

parent 6ff860d1
......@@ -203,7 +203,7 @@ gem 'request_store'
gem "virtus"
gem 'addressable'
gem "gitlab-license"
gem "gitlab-license", "~> 0.0.2"
group :development do
gem 'brakeman', require: false
......
......@@ -209,7 +209,7 @@ GEM
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3)
gitlab-license (0.0.1)
gitlab-license (0.0.2)
gitlab-linguist (3.0.1)
charlock_holmes (~> 0.6.6)
escape_utils (~> 0.2.4)
......@@ -707,7 +707,7 @@ DEPENDENCIES
github-markup
gitlab-flowdock-git-hook (~> 0.4.2)
gitlab-grack (~> 2.0.2)
gitlab-license
gitlab-license (~> 0.0.2)
gitlab-linguist (~> 3.0.1)
gitlab_emoji (~> 0.1)
gitlab_git (~> 7.1.10)
......
module LicenseHelper
def license_message(signed_in: signed_in?, is_admin: (current_user && current_user.is_admin?))
if License.current
yes_license_message(signed_in, is_admin)
else
no_license_message(signed_in, is_admin)
end
@license_message ||=
if License.current
yes_license_message(signed_in, is_admin)
else
no_license_message(signed_in, is_admin)
end
end
private
......
......@@ -48,7 +48,12 @@ class License < ActiveRecord::Base
def license
return nil unless self.data
@license ||= Gitlab::License.import(self.data)
@license ||=
begin
Gitlab::License.import(self.data)
rescue Gitlab::License::ImportError
nil
end
end
def license?
......@@ -95,8 +100,7 @@ class License < ActiveRecord::Base
def valid_license
return if license?
# TODO: Clearer message
self.errors.add(:license, "is invalid.")
self.errors.add(:base, "The license file is invalid. Make sure it is exactly as you received it from GitLab B.V.")
end
def active_user_count
......@@ -107,6 +111,8 @@ class License < ActiveRecord::Base
return if active_user_count <= restricted_user_count
self.errors.add(:base, "This license allows #{restricted_user_count} active users. This GitLab installation currently has #{active_user_count}, i.e. #{active_user_count - restricted_user_count} too many.")
message = "This license allows #{restricted_user_count} active users. "
message << "This GitLab installation currently has #{active_user_count}, i.e. #{active_user_count - restricted_user_count} too many."
self.errors.add(:base, message)
end
end
......@@ -3,7 +3,7 @@
= icon('bullhorn')
= broadcast_message.message
- if (message = license_message) && message.present?
- if license_message.present?
.broadcast-message
= icon('bullhorn')
= message
= license_message
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
# TODO: Validate encryptionkey
begin
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
end
# Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true)
if message.present?
# TODO: Change
warn "WARNING: #{message}"
end
# TODO: Warn about too many users
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