Commit 764bead2 authored by Stan Hu's avatar Stan Hu

Merge branch '325541_use_licensee_methods' into 'master'

Use licensee methods

See merge request gitlab-org/gitlab!59364
parents c2f72d60 74e6b606
......@@ -361,7 +361,7 @@ class License < ApplicationRecord
end
def data_filename
company_name = self.licensee["Company"] || self.licensee.each_value.first
company_name = self.licensee_company || self.licensee.each_value.first
clean_company_name = company_name.gsub(/[^A-Za-z0-9]/, "")
"#{clean_company_name}.gitlab-license"
end
......
......@@ -34,10 +34,10 @@ module HistoricalUserData
def header_csv
CSV.generate do |csv|
csv << ['License Key', license.data]
csv << ['Email', license.licensee['Email']]
csv << ['Email', license.licensee_email]
csv << ['License Start Date', license.starts_at&.to_s(:csv)]
csv << ['License End Date', license.expires_at&.to_s(:csv)]
csv << ['Company', license.licensee['Company']]
csv << ['Company', license.licensee_company]
csv << ['Generated At', Time.current.to_s(:csv)]
csv << ['']
end
......
......@@ -11,7 +11,7 @@
= render 'admin/licenses/license_status'
%span.gl-ml-5
= _('Licensed to:')
%strong= @license.licensee['Name']
= "(#{@license.licensee['Email']})"
%strong= @license.licensee_name
= "(#{@license.licensee_email})"
%div
= link_to 'View details', admin_license_path, class: "gl-button btn btn-default"
......@@ -21,7 +21,7 @@ class ActiveUserCountThresholdWorker # rubocop:disable Scalability/IdempotentWor
.to_set
# rubocop:enable CodeReuse/ActiveRecord
recipients << license.licensee["Email"] if license.licensee["Email"]
recipients << license.licensee_email if license.licensee_email
LicenseMailer.approaching_active_user_count_limit(recipients.to_a)
end
......
......@@ -755,6 +755,24 @@ RSpec.describe License do
end
end
describe "#data_filename" do
subject { license.data_filename }
context 'when licensee includes company information' do
let(:gl_license) do
build(:gitlab_license, licensee: { 'Company' => ' Example & Partner Inc. 2 ', 'Name' => 'User Example' })
end
it { is_expected.to eq('ExamplePartnerInc2.gitlab-license') }
end
context 'when licensee does not include company information' do
let(:gl_license) { build(:gitlab_license, licensee: { 'Name' => 'User Example' }) }
it { is_expected.to eq('UserExample.gitlab-license') }
end
end
describe "#md5" do
it "returns the same MD5 for licenses with carriage returns and those without" do
other_license = build(:license, data: license.data.gsub("\n", "\r\n"))
......
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