Sha256: 088982ec31014ec9c411270c532b7cec3c7720c8102a0e128a46c71c96beb785

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Kaui
  class AccountEmailsController < Kaui::EngineController
    def new
      @account_email = Kaui::AccountEmail.new(account_id: params.require(:account_id),
                                              email: params[:email])
    end

    def create
      @account_email = Kaui::AccountEmail.new(account_email_params.merge(account_id: params.require(:account_id)))

      begin
        @account_email.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
        redirect_to kaui_engine.account_path(@account_email.account_id), notice: 'Account email was successfully added'
      rescue StandardError => e
        flash.now[:error] = "Error while adding the email: #{as_string(e)}"
        render action: :new
      end
    end

    def destroy
      account_email = Kaui::AccountEmail.new(account_id: params.require(:account_id),
                                             email: params.require(:id))

      account_email.destroy(current_user.kb_username, params[:reason], params[:comment], options_for_klient)

      redirect_to kaui_engine.account_path(account_email.account_id), notice: 'Account email was successfully deleted'
    end

    private

    def account_email_params
      account_email = params.require(:account_email)
      account_email.require(:email)
      account_email
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kaui-3.0.5 app/controllers/kaui/account_emails_controller.rb
kaui-3.0.4 app/controllers/kaui/account_emails_controller.rb
kaui-3.0.2 app/controllers/kaui/account_emails_controller.rb
kaui-2.2.1 app/controllers/kaui/account_emails_controller.rb
kaui-3.0.1 app/controllers/kaui/account_emails_controller.rb