Skip to content

Commit

Permalink
Issue 342 remove kenui dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tungleduyxyz committed Feb 17, 2025
1 parent 6fcf39f commit 66ae68b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ group :development do
end
end

# gem 'kenui', :path => '../killbill-email-notifications-ui'
# gem 'kenui', git: 'https://github.com/killbill/killbill-email-notifications-ui.git', branch: 'master'
gem 'kenui'

# gem 'killbill-assets-ui', github: 'killbill/killbill-assets-ui', ref: 'main'
# gem 'killbill-assets-ui', path: '../killbill-assets-ui'
gem 'killbill-assets-ui'
Expand Down
35 changes: 11 additions & 24 deletions app/controllers/kaui/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@ def show
fetch_account_emails = promise { Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', cached_options_for_klient) }
fetch_payments = promise { @account.payments(cached_options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) } }
fetch_payment_methods = promise { Kaui::PaymentMethod.find_all_by_account_id(@account.account_id, false, cached_options_for_klient) }

# is email notification plugin available
is_email_notifications_plugin_available = Kenui::EmailNotificationService.email_notification_plugin_available?(cached_options_for_klient).first
is_email_notifications_plugin_available = Dependencies::Kenui::EmailNotification.email_notification_plugin_available?(cached_options_for_klient).first
fetch_email_notification_configuration = if is_email_notifications_plugin_available
promise do
Kenui::EmailNotificationService.get_configuration_per_account(params.require(:account_id), cached_options_for_klient)
Dependencies::Kenui::EmailNotification.get_configuration_per_account(params.require(:account_id), cached_options_for_klient)
end.then do |configuration|
if configuration.first.is_a?(FalseClass)
Rails.logger.warn(configuration[1])
Expand Down Expand Up @@ -175,7 +173,7 @@ def show
@available_tags = wait(fetch_available_tags)
@children = wait(fetch_children)
@account_parent = @account.parent_account_id.nil? ? nil : wait(fetch_parent)
@email_notification_configuration = wait(fetch_email_notification_configuration) if is_email_notifications_plugin_available
@email_notification_configuration = is_email_notifications_plugin_available ? wait(fetch_email_notification_configuration) : []

@last_transaction_by_payment_method_id = {}
wait(fetch_payments).each do |payment|
Expand Down Expand Up @@ -345,15 +343,15 @@ def set_email_notifications_configuration
event_types = configuration[:event_types]
cached_options_for_klient = options_for_klient

is_success, message = email_notification_plugin_available?(cached_options_for_klient)
is_success, message = Dependencies::Kenui::EmailNotification.email_notification_plugin_available?(cached_options_for_klient)

if is_success
is_success, message = Kenui::EmailNotificationService.set_configuration_per_account(account_id,
event_types,
current_user.kb_username,
params[:reason],
params[:comment],
cached_options_for_klient)
is_success, message = Dependencies::Kenui::EmailNotification.set_configuration_per_account(account_id,
event_types,
current_user.kb_username,
params[:reason],
params[:comment],
cached_options_for_klient)
end
if is_success
flash[:notice] = message
Expand All @@ -365,24 +363,13 @@ def set_email_notifications_configuration

def events_to_consider
json_response do
{ data: Kenui::EmailNotificationService.get_events_to_consider(options_for_klient) }
{ data: Dependencies::Kenui::EmailNotification.get_events_to_consider(options_for_klient) }
end
end

def export_account
data = KillBillClient::Model::Export.find_by_account_id(params[:account_id], current_user.kb_username, options_for_klient)
send_data data, filename: "account#{params[:account_id]}.txt", type: :txt
end

private

def email_notification_plugin_available?(options_for_klient)
error_message = 'Email notification plugin is not installed'

is_available = Kenui::EmailNotificationService.email_notification_plugin_available?(options_for_klient).first
[is_available, is_available ? nil : error_message]
rescue StandardError
[false, error_message]
end
end
end
40 changes: 40 additions & 0 deletions app/services/dependencies/kenui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

module Dependencies
module Kenui
class EmailNotification
ERROR_MESSAGE = I18n.translate('errors.messages.email_notification_plugin_not_available')
class << self
def email_notification_plugin_available?(options_for_klient)
is_available = ::Kenui::EmailNotificationService.email_notification_plugin_available?(options_for_klient)
[is_available, is_available ? nil : ERROR_MESSAGE]
rescue StandardError
[false, ERROR_MESSAGE]
end

def set_configuration_per_account(account_id, event_types, kb_username, reason, comment, options_for_klient)
::Kenui::EmailNotificationService.set_configuration_per_account(account_id,
event_types,
kb_username,
reason,
comment,
options_for_klient)
rescue StandardError
[false, ERROR_MESSAGE]
end

def get_events_to_consider(options_for_klient)
::Kenui::EmailNotificationService.get_events_to_consider(options_for_klient)
rescue StandardError
{}
end

def get_configuration_per_account(account_id, options_for_klient)
::Kenui::EmailNotificationService.get_configuration_per_account(account_id, options_for_klient)
rescue StandardError
[]
end
end
end
end
end
1 change: 0 additions & 1 deletion kaui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Gem::Specification.new do |s|
s.add_dependency 'jquery-ui-rails'
s.add_dependency 'js-routes'
s.add_dependency 'jwt'
s.add_dependency 'kenui'
s.add_dependency 'killbill-assets-ui'
s.add_dependency 'killbill-client'
s.add_dependency 'money-rails'
Expand Down
1 change: 0 additions & 1 deletion lib/kaui/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require 'json'
require 'money-rails'
require 'killbill_client'
require 'kenui'
require 'devise'
require 'cancan'
require 'country_select'
Expand Down

0 comments on commit 66ae68b

Please sign in to comment.