Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ group :development do
end

group :development, :test do
gem 'rubocop', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
gem 'rubocop-thread_safety', require: false
gem 'rubocop', '~> 1.89.0', require: false
gem 'rubocop-performance', '~> 1.26.1', require: false
gem 'rubocop-rails', '~> 2.36.0', require: false
gem 'rubocop-rspec', '~> 3.10.2', require: false
gem 'rubocop-thread_safety', '~> 0.7.3', require: false
end

# gem 'killbill-assets-ui', github: 'killbill/killbill-assets-ui', ref: 'main'
Expand Down
18 changes: 4 additions & 14 deletions app/controllers/kaui/bundles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Kaui
class BundlesController < Kaui::EngineController
# rubocop:disable Lint/HashCompareByIdentity
def index
cached_options_for_klient = options_for_klient
@search_query = params[:q].presence
Expand All @@ -12,27 +11,19 @@ def index

fetch_bundle_tags = promise do
all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', cached_options_for_klient)
all_bundle_tags.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
all_bundle_tags.group_by(&:object_id)
end
fetch_subscription_tags = promise do
all_subscription_tags = @account.all_tags(:SUBSCRIPTION, false, 'NONE', cached_options_for_klient)
all_subscription_tags.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
all_subscription_tags.group_by(&:object_id)
end
fetch_bundle_fields = promise do
all_bundle_fields = @account.all_custom_fields(:BUNDLE, 'NONE', cached_options_for_klient)
all_bundle_fields.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
all_bundle_fields.group_by(&:object_id)
end
fetch_subscription_fields = promise do
all_subscription_fields = @account.all_custom_fields(:SUBSCRIPTION, 'NONE', cached_options_for_klient)
all_subscription_fields.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
all_subscription_fields.group_by(&:object_id)
end
fetch_available_tags = promise { Kaui::TagDefinition.all_for_bundle(cached_options_for_klient) }
fetch_available_subscription_tags = promise { Kaui::TagDefinition.all_for_subscription(cached_options_for_klient) }
Expand Down Expand Up @@ -74,7 +65,6 @@ def index
end
end
end
# rubocop:enable Lint/HashCompareByIdentity

def transfer
@bundle_id = params.require(:id)
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/kaui/custom_fields_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,39 @@ def _check_object_exist(uuid, object_type)
test_uuid = nil
msg = nil
case param_object_type
when 'INVOICE_ITEM'
when 'INVOICE_ITEM'
begin
test_uuid = Kaui::Invoice.find_by_invoice_item_id(param_uuid, false, 'NONE', options_for_klient)
rescue StandardError
# Ignore
ensure
msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_invoice_item_db') } if test_uuid.present?
end
when 'ACCOUNT'
when 'ACCOUNT'
begin
test_uuid = Kaui::Account.find_by_id_or_key(param_uuid, false, false, options_for_klient)
rescue StandardError
# Ignore
ensure
msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_account_db') } if test_uuid.present? && (test_uuid.account_id == param_uuid)
end
when 'BUNDLE'
when 'BUNDLE'
begin
test_uuid = Kaui::Bundle.find_by_id_or_key(param_uuid, options_for_klient)
rescue StandardError
# Ignore
ensure
msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_bundle_db') } if test_uuid.present? && (test_uuid.bundle_id == param_uuid)
end
when 'SUBSCRIPTION'
when 'SUBSCRIPTION'
begin
test_uuid = Kaui::Subscription.find_by_id(param_uuid, 'NONE', options_for_klient)
rescue StandardError
# Ignore
ensure
msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_subscription_db') } if test_uuid.present? && (test_uuid.subscription_id == param_uuid)
end
when 'INVOICE'
when 'INVOICE'
begin
cached_options_for_klient = options_for_klient
test_uuid = Kaui::Invoice.find_by_id(param_uuid, false, 'FULL', cached_options_for_klient)
Expand All @@ -178,7 +178,7 @@ def _check_object_exist(uuid, object_type)
ensure
msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_invoice_db') } if test_uuid.present? && (test_uuid.invoice_id == param_uuid)
end
when 'PAYMENT'
when 'PAYMENT'
begin
test_uuid = Kaui::InvoicePayment.find_by_id(param_uuid, false, true, options_for_klient)
rescue StandardError
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/engine_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Kaui::EngineController < ApplicationController

before_action :authenticate_user!, :check_for_redirect_to_tenant_screen, :populate_account_details

layout :get_layout
layout :current_layout

# Common options for the Kill Bill client
def options_for_klient(options = {})
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/kaui/engine_controller_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ module EngineControllerUtil

protected

# rubocop:disable Lint/UselessAssignment, Naming/AccessorMethodName
def get_layout
layout ||= Kaui.config[:layout]
def current_layout
Kaui.config[:layout]
end
# rubocop:enable Lint/UselessAssignment, Naming/AccessorMethodName

# Remove this when we support balance search alongside the other search
def handle_balance_search(query_string)
Expand Down
18 changes: 4 additions & 14 deletions app/controllers/kaui/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def pagination
paginate searcher, data_extractor, formatter
end

# rubocop:disable Lint/HashCompareByIdentity
def show
# Go to the database once
cached_options_for_klient = options_for_klient
Expand Down Expand Up @@ -116,24 +115,18 @@ def show
fetch_invoice_fields = promise { @invoice.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
fetch_payment_fields = promise do
all_payment_fields = @account.all_custom_fields(:PAYMENT, 'NONE', cached_options_for_klient)
all_payment_fields.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
all_payment_fields.group_by(&:object_id)
end

fetch_available_invoice_item_tags = promise { Kaui::TagDefinition.all_for_invoice_item(cached_options_for_klient) }
fetch_tags_per_invoice_item = promise do
tags_per_invoice_item = @account.all_tags(:INVOICE_ITEM, false, 'NONE', cached_options_for_klient)
tags_per_invoice_item.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
tags_per_invoice_item.group_by(&:object_id)
end

fetch_custom_fields_per_invoice_item = promise do
custom_fields_per_invoice_item = @account.all_custom_fields(:INVOICE_ITEM, 'NONE', cached_options_for_klient)
custom_fields_per_invoice_item.each_with_object({}) do |entry, hsh|
(hsh[entry.object_id] ||= []) << entry
end
custom_fields_per_invoice_item.group_by(&:object_id)
end

fetch_invoice_tags = promise { @invoice.tags(false, 'NONE', cached_options_for_klient).sort }
Expand All @@ -150,7 +143,6 @@ def show
@available_invoice_tags = wait(fetch_available_invoice_tags)
@available_invoice_tags.reject! { |td| td.name == 'WRITTEN_OFF' } if @invoice.status == 'VOID'
end
# rubocop:enable Lint/HashCompareByIdentity

def void_invoice
cached_options_for_klient = options_for_klient
Expand All @@ -175,9 +167,7 @@ def restful_show_by_number
end

def show_html
# rubocop:disable Rails/OutputSafety -- Invoice HTML from Kill Bill backend is trusted
render html: Kaui::Invoice.as_html(params.require(:id), options_for_klient).html_safe
# rubocop:enable Rails/OutputSafety
render html: Kaui::Invoice.as_html(params.require(:id), options_for_klient).html_safe # rubocop:disable Rails/OutputSafety -- Invoice HTML from Kill Bill backend is trusted
end

def commit_invoice
Expand Down
22 changes: 10 additions & 12 deletions app/controllers/kaui/queues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@

module Kaui
class QueuesController < Kaui::EngineController
# rubocop:disable Lint/SuppressedException,Lint/EnsureReturn
def index
@account_id = params[:account_id]

if params[:max_date].present?
begin
max_date_test = Time.parse(params[:max_date]).iso8601
rescue StandardError
ensure
if max_date_test.nil?
flash[:error] = I18n.t('errors.messages.invalid_max_date')
redirect_to account_queues_path(@account.account_id) and return
end
max_date_test = nil
end
if max_date_test.nil?
flash[:error] = I18n.t('errors.messages.invalid_max_date')
redirect_to account_queues_path(@account.account_id) and return
end
end

if params[:min_date].present?
begin
min_date_test = Time.parse(params[:min_date]).iso8601
rescue StandardError
ensure
if min_date_test.nil?
flash[:error] = I18n.t('errors.messages.invalid_min_date')
redirect_to account_queues_path(@account.account_id) and return
end
min_date_test = nil
end
if min_date_test.nil?
flash[:error] = I18n.t('errors.messages.invalid_min_date')
redirect_to account_queues_path(@account.account_id) and return
end
end

Expand All @@ -47,6 +46,5 @@ def index

params.permit!
end
# rubocop:enable Lint/SuppressedException,Lint/EnsureReturn
end
end
6 changes: 1 addition & 5 deletions app/controllers/kaui/refunds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def new
@refund = KillBillClient::Model::InvoiceItem.new(invoice_id: @invoice.invoice_id)
end

# rubocop:disable Lint/FloatComparison
def create
invoice = Kaui::Invoice.find_by_id(params.require(:invoice_id), false, 'NONE', options_for_klient)

Expand All @@ -29,9 +28,7 @@ def create
item = KillBillClient::Model::InvoiceItem.new
item.invoice_item_id = ii[0]
item.description = params.dig(:descriptions, ii[0])
# If we tried to do a partial item adjustment, we pass the value, if not we don't send any value and let the system
# decide what is the maximum amount we can have on that item
item.amount = ii[1].to_f == original_item.amount ? nil : ii[1]
item.amount = ii[1].to_d == original_item.amount.to_d ? nil : ii[1]

items << item
end
Expand All @@ -40,7 +37,6 @@ def create
KillBillClient::Model::InvoicePayment.refund(params.require(:payment_id), params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Refund created'
end
# rubocop:enable Lint/FloatComparison

private

Expand Down
4 changes: 1 addition & 3 deletions app/models/kaui/refund.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

module Kaui
# rubocop:disable Lint/EmptyClass
class Refund
class Refund # rubocop:disable Lint/EmptyClass
end
# rubocop:enable Lint/EmptyClass
end
4 changes: 1 addition & 3 deletions test/functional/kaui/admin_allowed_users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class AdminAllowedUsersControllerTest < Kaui::FunctionalTestHelper
assert response_path.include?('/kaui/home'), "#{response_path} is expected to contain '/kaui/home'"
end

# rubocop:disable Naming/VariableNumber
test 'should add tenant' do
allowed_user = { kb_username: SecureRandom.uuid.to_s, description: SecureRandom.uuid.to_s }

Expand All @@ -151,13 +150,12 @@ class AdminAllowedUsersControllerTest < Kaui::FunctionalTestHelper

allowed_user[:id] = au.id

put :add_tenant, params: { allowed_user:, tenant_1: nil }
put :add_tenant, params: { allowed_user:, tenant_1: nil } # rubocop:disable Naming/VariableNumber
assert_equal 'Successfully set tenants for user', flash[:notice]
assert_response :redirect
# validate redirect path
assert response_path.include?(expected_response_path(au.id)), "#{response_path} is expected to contain #{expected_response_path(au.id)}"
end
# rubocop:enable Naming/VariableNumber

test 'should detect if a user is managed externally' do
allowed_user = { kb_username: SecureRandom.uuid.to_s, description: SecureRandom.uuid.to_s }
Expand Down
12 changes: 3 additions & 9 deletions test/killbill_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,15 @@ def create_bundle(account = nil, tenant = nil, username = USERNAME, password = P
end

# Return a new test payment method
# rubocop:disable Style/OptionalBooleanParameter
def create_payment_method(set_default = false, account = nil, tenant = nil, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil)
def create_payment_method(set_default = false, account = nil, tenant = nil, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) # rubocop:disable Style/OptionalBooleanParameter
account = create_account(tenant, username, password, user, reason, comment) if account.nil?

payment_method = Kaui::PaymentMethod.new(account_id: account.account_id, plugin_name: '__EXTERNAL_PAYMENT__', is_default: set_default)
payment_method.create(true, user, reason, comment, build_options(tenant, username, password))
end
# rubocop:enable Style/OptionalBooleanParameter

# Return the created external charge
# rubocop:disable Style/OptionalBooleanParameter
def create_charge(account = nil, tenant = nil, auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil)
def create_charge(account = nil, tenant = nil, auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) # rubocop:disable Style/OptionalBooleanParameter
tenant = create_tenant(user, reason, comment) if tenant.nil?
account = create_account(tenant, username, password, user, reason, comment) if account.nil?

Expand All @@ -155,11 +152,9 @@ def create_charge(account = nil, tenant = nil, auto_commit = false, username = U
rescue StandardError
nil
end
# rubocop:enable Style/OptionalBooleanParameter

# Return the created credit
# rubocop:disable Style/OptionalBooleanParameter
def create_cba(invoice_id = nil, account = nil, tenant = nil, _auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil)
def create_cba(invoice_id = nil, account = nil, tenant = nil, _auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) # rubocop:disable Style/OptionalBooleanParameter
tenant = create_tenant(user, reason, comment) if tenant.nil?
account = create_account(tenant, username, password, user, reason, comment) if account.nil?

Expand All @@ -169,7 +164,6 @@ def create_cba(invoice_id = nil, account = nil, tenant = nil, _auto_commit = fal
invoice = KillBillClient::Model::Invoice.find_by_id(credit.invoice_id, false, 'NONE', build_options(tenant, username, password))
invoice.items.find { |ii| ii.amount == -credit.amount }
end
# rubocop:enable Style/OptionalBooleanParameter

def commit_invoice(invoice_id, tenant, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil)
invoice = KillBillClient::Model::Invoice.find_by_id(invoice_id, false, 'NONE', build_options(tenant, username, password))
Expand Down
8 changes: 3 additions & 5 deletions test/unit/kaui/account_email_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

module Kaui
class AccountEmailTest < ActiveSupport::TestCase
# rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
test 'can compare emails' do
email1 = Kaui::AccountEmail.new(account_id: SecureRandom.uuid, email: 'abc@bar.com')
email2 = Kaui::AccountEmail.new(account_id: SecureRandom.uuid, email: 'bcd@bar.com')
email3 = Kaui::AccountEmail.new(account_id: SecureRandom.uuid, email: nil)

assert_equal(-1, email1 <=> email2)
assert_equal 1, email2 <=> email1
assert_equal 0, email1 <=> email1
assert_equal 0, email2 <=> email2
assert_equal 0, email3 <=> email3
assert_equal 0, email1 <=> email1.dup
assert_equal 0, email2 <=> email2.dup
assert_equal 0, email3 <=> email3.dup
assert_equal 1, email1 <=> email3
assert_equal(-1, email3 <=> email1)
assert_equal(-1, email1 <=> nil)
end
# rubocop:enable Lint/BinaryOperatorWithIdenticalOperands
end
end
Loading