diff --git a/app/controllers/admin/bounced_mail_addresses_controller.rb b/app/controllers/admin/bounced_mail_addresses_controller.rb index 551413e2c..da9421450 100644 --- a/app/controllers/admin/bounced_mail_addresses_controller.rb +++ b/app/controllers/admin/bounced_mail_addresses_controller.rb @@ -1,47 +1,16 @@ module Admin class BouncedMailAddressesController < BaseController - before_action :set_bounced_mail_address, only: %i[show edit update destroy] + before_action :set_bounced_mail_address, only: %i[show destroy] load_and_authorize_resource # 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 diff --git a/app/models/bounced_mail_address.rb b/app/models/bounced_mail_address.rb index 6609829da..78f37c374 100644 --- a/app/models/bounced_mail_address.rb +++ b/app/models/bounced_mail_address.rb @@ -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 diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index a327419fd..5853bd3e6 100644 --- a/app/views/admin/base/_menu.haml +++ b/app/views/admin/base/_menu.haml @@ -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' diff --git a/app/views/admin/bounced_mail_addresses/_form.html.erb b/app/views/admin/bounced_mail_addresses/_form.html.erb deleted file mode 100644 index 7a384bd3f..000000000 --- a/app/views/admin/bounced_mail_addresses/_form.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<%= form_for([:admin, @bounced_mail_address], html: { class: 'form-horizontal' }) do |form| %> - <% if @bounced_mail_address.errors.any? %> -
-

<%= pluralize(bounced_mail_address.errors.count, "error") %> prohibited this bounced_mail_address from being saved:

- - -
- <% end %> - -
- <%= form.label :email %> - <%= form.text_field :email %> -
- -
- <%= form.label :bounce_reason %> - <%= form.text_field :bounce_reason %> -
- -
- <%= form.label :incidents %> - <%= form.number_field :incidents %> -
- -
- <%= form.label :response_json %> - <%= form.text_field :response_json %> -
- -
- <%= form.submit %> -
-<% end %> diff --git a/app/views/admin/bounced_mail_addresses/edit.html.erb b/app/views/admin/bounced_mail_addresses/edit.html.erb deleted file mode 100644 index a3dfe2d84..000000000 --- a/app/views/admin/bounced_mail_addresses/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing Bounced Mail Address

- -<%= render 'form', bounced_mail_address: @bounced_mail_address %> - -<%= link_to 'Show', admin_bounced_mail_address_path(@bounced_mail_address)%> | -<%= link_to 'Back', admin_bounced_mail_addresses_path %> diff --git a/app/views/admin/bounced_mail_addresses/new.html.erb b/app/views/admin/bounced_mail_addresses/new.html.erb deleted file mode 100644 index 010ac79dc..000000000 --- a/app/views/admin/bounced_mail_addresses/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New Bounced Mail Address

- -<%= render 'form', bounced_mail_address: @bounced_mail_address %> - -<%= link_to 'Back', admin_bounced_mail_addresses_path %> diff --git a/app/views/admin/bounced_mail_addresses/show.html.erb b/app/views/admin/bounced_mail_addresses/show.html.erb index 1f48ad5cf..752bd7b0a 100644 --- a/app/views/admin/bounced_mail_addresses/show.html.erb +++ b/app/views/admin/bounced_mail_addresses/show.html.erb @@ -16,9 +16,13 @@

- Response json: - <%= @bounced_mail_address.response_json %> + Bounced recipient JSON: +

<%= JSON.pretty_generate(@bounced_mail_address.recipient_json) %>
+

+ +

+ Bounce payload: +

<%= JSON.pretty_generate(@bounced_mail_address.response_json) %>

-<%= link_to 'Edit', edit_admin_bounced_mail_address_path(@bounced_mail_address) %> | <%= link_to 'Back', admin_bounced_mail_addresses_path %> diff --git a/config/locales/admin/menu.en.yml b/config/locales/admin/menu.en.yml index 617341c6a..cb1060e6f 100644 --- a/config/locales/admin/menu.en.yml +++ b/config/locales/admin/menu.en.yml @@ -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 diff --git a/db/migrate/20200917104213_add_recipient_json_to_bounced_mail_address.rb b/db/migrate/20200917104213_add_recipient_json_to_bounced_mail_address.rb new file mode 100644 index 000000000..bad3d846e --- /dev/null +++ b/db/migrate/20200917104213_add_recipient_json_to_bounced_mail_address.rb @@ -0,0 +1,5 @@ +class AddRecipientJsonToBouncedMailAddress < ActiveRecord::Migration[6.0] + def change + add_column :bounced_mail_addresses, :recipient_json, :jsonb, null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 3ec055386..23669c665 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -486,7 +486,8 @@ CREATE TABLE public.bounced_mail_addresses ( incidents integer DEFAULT 1 NOT NULL, response_json jsonb, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + updated_at timestamp(6) without time zone NOT NULL, + recipient_json jsonb NOT NULL ); @@ -4956,6 +4957,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200908131554'), ('20200910085157'), ('20200910102028'), -('20200916125326'); +('20200916125326'), +('20200917104213');