Skip to content

Commit e01bd3f

Browse files
authored
Merge pull request #589 from killbill/kaui_4.1
KAUI 4.1 Release
2 parents 17fa145 + a55e89e commit e01bd3f

87 files changed

Lines changed: 708 additions & 583 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.rubocop.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
require:
2+
- rubocop-performance
3+
- rubocop-rails
4+
- rubocop-rspec
5+
- rubocop-thread_safety
6+
17
inherit_mode:
28
merge:
39
- Exclude
@@ -52,3 +58,48 @@ Style/Documentation:
5258

5359
Style/EmptyElse:
5460
EnforcedStyle: empty
61+
62+
# Rails cops
63+
Rails:
64+
Enabled: true
65+
66+
Rails/I18nLocaleTexts:
67+
Enabled: false
68+
69+
Rails/SkipsModelValidations:
70+
Enabled: false
71+
72+
# RSpec cops
73+
RSpec:
74+
Enabled: true
75+
76+
RSpec/MultipleExpectations:
77+
Enabled: false
78+
79+
RSpec/ExampleLength:
80+
Enabled: false
81+
82+
# Performance cops
83+
Performance:
84+
Enabled: true
85+
86+
# Thread Safety cops
87+
ThreadSafety:
88+
Enabled: true
89+
90+
ThreadSafety/ClassAndModuleAttributes:
91+
Enabled: false
92+
93+
ThreadSafety/DirChdir:
94+
Exclude:
95+
- 'script/sandbox'
96+
97+
# CLI tool uses exit() for control flow
98+
Rails/Exit:
99+
Exclude:
100+
- 'lib/kaui/installer/installer.rb'
101+
102+
# Legacy tests - migration to IntegrationTest is non-trivial
103+
Rails/ActionControllerTestCase:
104+
Exclude:
105+
- 'test/functional/**/*'

Gemfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ group :development do
2424
gem 'puma'
2525
gem 'rails-controller-testing'
2626
gem 'rake'
27-
gem 'rubocop'
2827
gem 'simplecov'
2928

3029
if defined?(JRUBY_VERSION)
@@ -43,6 +42,14 @@ group :development do
4342
end
4443
end
4544

45+
group :development, :test do
46+
gem 'rubocop', require: false
47+
gem 'rubocop-performance', require: false
48+
gem 'rubocop-rails', require: false
49+
gem 'rubocop-rspec', require: false
50+
gem 'rubocop-thread_safety', require: false
51+
end
52+
4653
# gem 'killbill-assets-ui', github: 'killbill/killbill-assets-ui', ref: 'main'
4754
# gem 'killbill-assets-ui', path: '../killbill-assets-ui'
4855
gem 'killbill-assets-ui'

app/controllers/kaui/account_timelines_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def download
7676
if %w[INVOICE ALL].include?(event_type)
7777
@invoices.each do |invoice_stub|
7878
invoice = invoice_stub.invoice_id.present? && @invoices_by_id.key?(invoice_stub.invoice_id) ? @invoices_by_id[invoice_stub.invoice_id] : invoice_stub
79-
target_date = invoice.target_date.present? ? invoice.target_date : '[unknown]'
79+
target_date = invoice.target_date.presence || '[unknown]'
8080
bundle_keys = invoice_stub.bundle_keys.present? ? invoice_stub.bundle_keys.split(',').map { |bundle_key| @bundle_names[bundle_key] }.join(', ') : ''
8181
invoice_details = []
8282
invoice_details << "Amount: #{invoice.amount_to_money} (#{@account.currency})"
@@ -133,7 +133,7 @@ def download
133133
end
134134
end
135135

136-
send_data csv_string, filename: "account-timelines-#{Date.today}.csv", type: 'text/csv'
136+
send_data csv_string, filename: "account-timelines-#{Time.zone.today}.csv", type: 'text/csv'
137137
end
138138

139139
private
@@ -154,7 +154,7 @@ def load_bundle_name_for_timeline(bundle_key)
154154
end
155155

156156
def extract_invoices_by_id(all_invoices)
157-
return {} if all_invoices.nil? || all_invoices.empty?
157+
return {} if all_invoices.blank?
158158

159159
# Convert into Kaui::Invoice to benefit from additional methods xxx_to_money
160160
@invoices_by_id = all_invoices.to_h do |invoice|

app/controllers/kaui/accounts_controller.rb

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def download
5757
query_string = params[:search]
5858

5959
if all_fields_checked
60-
columns = KillBillClient::Model::AccountAttributes.instance_variable_get('@json_attributes')
60+
columns = KillBillClient::Model::AccountAttributes.instance_variable_get(:@json_attributes)
6161
csv_headers = columns.dup
6262
Kaui::Account::REMAPPING_FIELDS.each do |k, v|
6363
index = csv_headers.index(k)
@@ -97,36 +97,7 @@ def download
9797
csv << data
9898
end
9999
end
100-
send_data csv_string, filename: "accounts-#{Date.today}.csv", type: 'text/csv'
101-
end
102-
103-
def new
104-
@account = Kaui::Account.new
105-
end
106-
107-
def create
108-
@account = Kaui::Account.new(params.require(:account).delete_if { |_key, value| value.blank? })
109-
110-
@account.errors.add(:phone, :invalid_phone) if !@account.phone.nil? && !@account.check_account_details_phone?
111-
112-
@account.errors.add(:check_account_details_bill_cycle_day_local, :invalid_bill_cycle_day_local) if !@account.bill_cycle_day_local.nil? && !@account.check_account_details_bill_cycle_day_local?
113-
114-
unless @account.errors.empty?
115-
flash.now[:errors] = @account.errors.messages.values.flatten
116-
render action: :new and return
117-
end
118-
119-
# Transform "1" into boolean
120-
@account.is_migrated = @account.is_migrated == '1'
121-
122-
begin
123-
@account = @account.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
124-
125-
redirect_to account_path(@account.account_id), notice: 'Account was successfully created'
126-
rescue StandardError => e
127-
flash.now[:error] = "Error while creating account: #{as_string(e)}"
128-
render action: :new
129-
end
100+
send_data csv_string, filename: "accounts-#{Time.zone.today}.csv", type: 'text/csv'
130101
end
131102

132103
# rubocop:disable Style/MultilineBlockChain
@@ -140,7 +111,7 @@ def show
140111
fetch_children = promise { @account.children(false, false, 'NONE', cached_options_for_klient) }
141112
fetch_parent = @account.parent_account_id.nil? ? nil : promise { Kaui::Account.find_by_id(@account.parent_account_id, false, false, cached_options_for_klient) }
142113
fetch_overdue_state = promise { @account.overdue(cached_options_for_klient) }
143-
fetch_account_tags = promise { @account.tags(false, 'NONE', cached_options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b } }
114+
fetch_account_tags = promise { @account.tags(false, 'NONE', cached_options_for_klient).sort }
144115
fetch_account_fields = promise { @account.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
145116
fetch_account_emails = promise { Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', cached_options_for_klient) }
146117
fetch_payments = promise { @account.payments(cached_options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) } }
@@ -180,7 +151,7 @@ def show
180151
@custom_fields = wait(fetch_account_fields)
181152
@account_emails = wait(fetch_account_emails)
182153
wait(fetch_payment_methods)
183-
@payment_methods = wait(fetch_payment_methods_with_details).map { |pm_f| wait(pm_f) }.compact
154+
@payment_methods = wait(fetch_payment_methods_with_details).filter_map { |pm_f| wait(pm_f) }
184155
@available_tags = wait(fetch_available_tags)
185156
@children = wait(fetch_children)
186157
@account_parent = @account.parent_account_id.nil? ? nil : wait(fetch_parent)
@@ -198,6 +169,52 @@ def show
198169

199170
params.permit!
200171
end
172+
173+
def new
174+
@account = Kaui::Account.new
175+
end
176+
177+
def edit; end
178+
179+
def create
180+
@account = Kaui::Account.new(params.require(:account).permit!.to_h.compact_blank)
181+
182+
@account.errors.add(:phone, :invalid_phone) if !@account.phone.nil? && !@account.check_account_details_phone?
183+
184+
@account.errors.add(:check_account_details_bill_cycle_day_local, :invalid_bill_cycle_day_local) if !@account.bill_cycle_day_local.nil? && !@account.check_account_details_bill_cycle_day_local?
185+
186+
unless @account.errors.empty?
187+
flash.now[:errors] = @account.errors.messages.values.flatten
188+
render action: :new and return
189+
end
190+
191+
# Transform "1" into boolean
192+
@account.is_migrated = @account.is_migrated == '1'
193+
194+
begin
195+
@account = @account.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
196+
197+
redirect_to account_path(@account.account_id), notice: 'Account was successfully created'
198+
rescue StandardError => e
199+
flash.now[:error] = "Error while creating account: #{as_string(e)}"
200+
render action: :new
201+
end
202+
end
203+
204+
def update
205+
@account = Kaui::Account.new(params.require(:account).permit!.to_h.compact_blank)
206+
@account.account_id = params.require(:account_id)
207+
208+
# Transform "1" into boolean
209+
@account.is_migrated = @account.is_migrated == '1'
210+
211+
@account.update(true, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
212+
213+
redirect_to account_path(@account.account_id), notice: 'Account successfully updated'
214+
rescue StandardError => e
215+
flash.now[:error] = "Error while updating account: #{as_string(e)}"
216+
render action: :edit
217+
end
201218
# rubocop:enable Style/MultilineBlockChain
202219

203220
def destroy
@@ -261,23 +278,6 @@ def next_invoice_date
261278
end
262279
end
263280

264-
def edit; end
265-
266-
def update
267-
@account = Kaui::Account.new(params.require(:account).delete_if { |_key, value| value.blank? })
268-
@account.account_id = params.require(:account_id)
269-
270-
# Transform "1" into boolean
271-
@account.is_migrated = @account.is_migrated == '1'
272-
273-
@account.update(true, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
274-
275-
redirect_to account_path(@account.account_id), notice: 'Account successfully updated'
276-
rescue StandardError => e
277-
flash.now[:error] = "Error while updating account: #{as_string(e)}"
278-
render action: :edit
279-
end
280-
281281
def set_default_payment_method
282282
account_id = params.require(:account_id)
283283
payment_method_id = params.require(:payment_method_id)
@@ -309,7 +309,7 @@ def validate_external_key
309309
end
310310

311311
def link_to_parent
312-
@account = Kaui::Account.new(params.require(:account).delete_if { |_key, value| value.blank? })
312+
@account = Kaui::Account.new(params.require(:account).permit!.to_h.compact_blank)
313313
@account.account_id = params.require(:account_id)
314314
@account.is_payment_delegated_to_parent = @account.is_payment_delegated_to_parent == '1'
315315

app/controllers/kaui/admin_allowed_users_controller.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,50 @@ def index
1212
end
1313
end
1414

15+
def show
16+
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
17+
raise ActiveRecord::RecordNotFound, "Could not find user #{@allowed_user.id}" unless current_user.root? || @allowed_user.kb_username == current_user.kb_username
18+
19+
@roles = roles_for_user(@allowed_user)
20+
21+
tenants_for_current_user = retrieve_tenants_for_current_user
22+
@tenants = Kaui::Tenant.all.select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }
23+
end
24+
1525
def new
1626
@allowed_user = Kaui::AllowedUser.new
1727
@is_killbill_managed = true
1828
@roles = []
1929

2030
# Restore form state if returning from role creation
21-
return unless params[:user_context].present?
31+
return if params[:user_context].blank?
2232

2333
context = params[:user_context]
2434
@allowed_user.kb_username = context[:kb_username]
2535
@allowed_user.description = context[:description]
26-
@roles = context[:roles].to_s.split(',').reject(&:blank?)
36+
@roles = context[:roles].to_s.split(',').compact_blank
2737
@external_checked = context[:external] == '1'
2838
end
2939

40+
def edit
41+
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
42+
@is_killbill_managed = killbill_managed?(@allowed_user, options_for_klient)
43+
44+
# Use roles from context if returning from role creation, otherwise fetch from KB
45+
if params[:user_context].present?
46+
context = params[:user_context]
47+
@roles = context[:roles].to_s.split(',').compact_blank
48+
@allowed_user.description = context[:description] if context[:description].present?
49+
else
50+
@roles = roles_for_user(@allowed_user)
51+
end
52+
end
53+
3054
def create
3155
@is_killbill_managed = nil
3256
@allowed_user = Kaui::AllowedUser.new(allowed_user_params)
3357

34-
existing_user = Kaui::AllowedUser.find_by_kb_username(@allowed_user.kb_username)
58+
existing_user = Kaui::AllowedUser.find_by(kb_username: @allowed_user.kb_username)
3559
if existing_user.blank?
3660
if params[:external] == '1'
3761
# Create locally only
@@ -53,37 +77,13 @@ def create
5377
end
5478
end
5579

56-
def show
57-
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
58-
raise ActiveRecord::RecordNotFound, "Could not find user #{@allowed_user.id}" unless current_user.root? || @allowed_user.kb_username == current_user.kb_username
59-
60-
@roles = roles_for_user(@allowed_user)
61-
62-
tenants_for_current_user = retrieve_tenants_for_current_user
63-
@tenants = Kaui::Tenant.all.select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }
64-
end
65-
66-
def edit
67-
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
68-
@is_killbill_managed = killbill_managed?(@allowed_user, options_for_klient)
69-
70-
# Use roles from context if returning from role creation, otherwise fetch from KB
71-
if params[:user_context].present?
72-
context = params[:user_context]
73-
@roles = context[:roles].to_s.split(',').reject(&:blank?)
74-
@allowed_user.description = context[:description] if context[:description].present?
75-
else
76-
@roles = roles_for_user(@allowed_user)
77-
end
78-
end
79-
8080
def update
8181
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
8282

8383
@allowed_user.description = params[:allowed_user][:description].presence
8484

8585
@allowed_user.update_in_kb!(params[:password].presence,
86-
params[:roles].blank? ? nil : params[:roles].split(','),
86+
params[:roles].presence&.split(','),
8787
current_user.kb_username,
8888
params[:reason],
8989
params[:comment],
@@ -149,7 +149,7 @@ def allowed_user_params
149149
end
150150

151151
def roles_for_user(allowed_user)
152-
Kaui::UserRole.find_roles_by_username(allowed_user.kb_username, options_for_klient).map(&:presence).compact
152+
Kaui::UserRole.find_roles_by_username(allowed_user.kb_username, options_for_klient).filter_map(&:presence)
153153
rescue StandardError
154154
[]
155155
end

app/controllers/kaui/admin_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def index
2323
def set_clock
2424
if params[:commit] == 'Submit'
2525
date = Date.parse(params[:new_date]).strftime('%Y-%m-%d')
26-
msg = I18n.translate('flashes.notices.clock_updated_successfully', new_date: date)
26+
msg = I18n.t('flashes.notices.clock_updated_successfully', new_date: date)
2727
else
2828
date = nil
29-
msg = I18n.translate('flashes.notices.clock_reset_successfully')
29+
msg = I18n.t('flashes.notices.clock_reset_successfully')
3030
end
3131
begin
3232
Kaui::Admin.set_clock(date, nil, options_for_klient)

0 commit comments

Comments
 (0)