Skip to content

Commit

Permalink
Add full request JSON to bounced mail, remove unused views
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Sep 17, 2020
1 parent 6af37a7 commit af6fcbe
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 420 deletions.
33 changes: 1 addition & 32 deletions app/controllers/admin/bounced_mail_addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,12 @@ class BouncedMailAddressesController < BaseController

# GET /bounced_mail_addresses
def index
@bounced_mail_addresses = BouncedMailAddress.all
@bounced_mail_addresses = BouncedMailAddress.all.order(created_at: :desc)
end

# GET /bounced_mail_addresses/1
def show; end

# GET /bounced_mail_addresses/new
def new
@bounced_mail_address = BouncedMailAddress.new
end

# GET /bounced_mail_addresses/1/edit
def edit; end

# POST /bounced_mail_addresses
def create
@bounced_mail_address = BouncedMailAddress.new(bounced_mail_address_params)

if @bounced_mail_address.save
redirect_to(
admin_bounced_mail_addresses_url,
notice: 'Bounced mail address was successfully created.'
)
else
render(:new)
end
end

# PATCH/PUT /bounced_mail_addresses/1
def update
if @bounced_mail_address.update(bounced_mail_address_params)
redirect_to(@bounced_mail_address, notice: 'Bounced mail address was successfully updated.')
else
render(:edit)
end
end

# DELETE /bounced_mail_addresses/1
def destroy
@bounced_mail_address.destroy
Expand Down
15 changes: 11 additions & 4 deletions app/models/bounced_mail_address.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
class BouncedMailAddress < ApplicationRecord
validates :email, presence: true
validates :bounce_reason, presence: true
before_validation :assign_bounce_reason

def assign_bounce_reason
self.bounce_reason = "#{action} (#{status} #{diagnostic})"
end

def diagnostic
response_json['diagnosticCode']
recipient_json['diagnosticCode']
end

def action
response_json['action']
recipient_json['action']
end

def status
response_json['status']
recipient_json['status']
end

def self.record(json)
bounced_records = json['bounce']['bouncedRecipients']
bounced_records.each do |record|
bounce_record = BouncedMailAddress.new(email: record['emailAddress'], response_json: record)
bounce_record = BouncedMailAddress.new(email: record['emailAddress'], recipient_json: record,
response_json: json)

bounce_record.save
end
end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/base/_menu.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
%li= link_to t('.blocked_domains'), admin_blocked_domains_path
%li= link_to t('.reserved_domains'), admin_reserved_domains_path
%li= link_to t('.disputed_domains'), admin_disputes_path
%li= link_to t('.bounced_email_addresses'), admin_bounced_mail_addresses_path
%li= link_to t('.epp_log'), admin_epp_logs_path(created_after: 'today')
%li= link_to t('.repp_log'), admin_repp_logs_path(created_after: 'today')
%li= link_to t('.que'), '/admin/que'
Expand Down
37 changes: 0 additions & 37 deletions app/views/admin/bounced_mail_addresses/_form.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/admin/bounced_mail_addresses/edit.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/admin/bounced_mail_addresses/new.html.erb

This file was deleted.

10 changes: 7 additions & 3 deletions app/views/admin/bounced_mail_addresses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
</p>

<p>
<strong>Response json:</strong>
<%= @bounced_mail_address.response_json %>
<strong>Bounced recipient JSON:</strong>
<pre><%= JSON.pretty_generate(@bounced_mail_address.recipient_json) %></pre>
</p>

<p>
<strong>Bounce payload:</strong>
<pre><%= JSON.pretty_generate(@bounced_mail_address.response_json) %></pre>
</p>

<%= link_to 'Edit', edit_admin_bounced_mail_address_path(@bounced_mail_address) %> |
<%= link_to 'Back', admin_bounced_mail_addresses_path %>
1 change: 1 addition & 0 deletions config/locales/admin/menu.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ en:
blocked_domains: Blocked domains
reserved_domains: Reserved domains
disputed_domains: Disputed domains
bounced_email_addresses: Bounced emails
epp_log: EPP log
repp_log: REPP log
que: Que
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRecipientJsonToBouncedMailAddress < ActiveRecord::Migration[6.0]
def change
add_column :bounced_mail_addresses, :recipient_json, :jsonb, null: false
end
end
Loading

0 comments on commit af6fcbe

Please sign in to comment.