Updated

app/controllers/accounts/apps / chatwoots_controller.rb

B
47 lines of codes
7 methods
11.7 complexity/method
14 churn
82.23 complexity
0 duplications
class Accounts::Apps::ChatwootsController < InternalController
  1. Accounts::Apps::ChatwootsController assumes too much for instance variable '@chatwoot'
  2. Accounts::Apps::ChatwootsController has no descriptive comment
before_action :set_chatwoot, only: %i[edit update destroy] def new if current_user.account.apps_chatwoots.blank?
  1. Accounts::Apps::ChatwootsController#new calls 'current_user.account' 4 times Locations: 0 1 2
  2. Accounts::Apps::ChatwootsController#new calls 'current_user.account.apps_chatwoots' 3 times Locations: 0 1 2
@chatwoot = current_user.account.apps_chatwoots.new
  1. Accounts::Apps::ChatwootsController#new calls 'current_user.account' 4 times Locations: 0 1 2
  2. Accounts::Apps::ChatwootsController#new calls 'current_user.account.apps_chatwoots' 3 times Locations: 0 1 2
else redirect_to edit_account_apps_chatwoot_path(current_user.account, current_user.account.apps_chatwoots.first)
  1. Accounts::Apps::ChatwootsController#new calls 'current_user.account' 4 times Locations: 0 1 2
  2. Accounts::Apps::ChatwootsController#new calls 'current_user.account.apps_chatwoots' 3 times Locations: 0 1 2
end end def edit; end def create result = Accounts::Apps::Chatwoots::Create.call(current_user.account, chatwoot_params)
  1. Accounts::Apps::ChatwootsController#create calls 'current_user.account' 2 times Locations: 0 1
@chatwoot = result[result.keys.first] if result.key?(:ok) redirect_to edit_account_apps_chatwoot_path(current_user.account, @chatwoot),
  1. Accounts::Apps::ChatwootsController#create calls 'current_user.account' 2 times Locations: 0 1
notice: t('flash_messages.created', model: Apps::Chatwoot.model_name.human) else render :new end end def destroy result = Accounts::Apps::Chatwoots::Delete.call(current_user.account, @chatwoot)
  1. Accounts::Apps::ChatwootsController#destroy calls 'current_user.account' 2 times Locations: 0 1
if result.key?(:ok) redirect_to account_settings_path(current_user.account),
  1. Accounts::Apps::ChatwootsController#destroy calls 'current_user.account' 2 times Locations: 0 1
notice: t('flash_messages.deleted', model: Apps::Chatwoot.model_name.human) end end def update @chatwoot.update(chatwoot_params) redirect_to edit_account_apps_chatwoot_path(current_user.account, current_user.account.apps_chatwoots.first)
  1. Accounts::Apps::ChatwootsController#update calls 'current_user.account' 2 times
end private def set_chatwoot @chatwoot = current_user.account.apps_chatwoots.first end def chatwoot_params params.require(:apps_chatwoot).permit(:chatwoot_endpoint_url, :chatwoot_account_id, :chatwoot_user_token, :active) end end