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