mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Merge pull request #1687 from internetee/log-bounced-emails
Gather data about bounced emails via API
This commit is contained in:
commit
903f14d0ba
18 changed files with 463 additions and 6 deletions
30
app/controllers/admin/bounced_mail_addresses_controller.rb
Normal file
30
app/controllers/admin/bounced_mail_addresses_controller.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Admin
|
||||
class BouncedMailAddressesController < BaseController
|
||||
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.order(created_at: :desc)
|
||||
end
|
||||
|
||||
# GET /bounced_mail_addresses/1
|
||||
def show; end
|
||||
|
||||
# DELETE /bounced_mail_addresses/1
|
||||
def destroy
|
||||
@bounced_mail_address.destroy
|
||||
redirect_to(
|
||||
admin_bounced_mail_addresses_url,
|
||||
notice: 'Bounced mail address was successfully destroyed.'
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_bounced_mail_address
|
||||
@bounced_mail_address = BouncedMailAddress.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,11 @@ module Api
|
|||
head :unauthorized unless ip_allowed
|
||||
end
|
||||
|
||||
def authenticate_shared_key
|
||||
api_key = "Basic #{ENV['api_shared_key']}"
|
||||
head(:unauthorized) unless api_key == request.authorization
|
||||
end
|
||||
|
||||
def not_found_error
|
||||
uuid = params['uuid']
|
||||
json = { error: 'Not Found', uuid: uuid, message: 'Record not found' }
|
||||
|
|
25
app/controllers/api/v1/bounces_controller.rb
Normal file
25
app/controllers/api/v1/bounces_controller.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Api
|
||||
module V1
|
||||
class BouncesController < BaseController
|
||||
before_action :authenticate_shared_key
|
||||
|
||||
# POST api/v1/bounces/
|
||||
def create
|
||||
return head(:bad_request) unless bounce_params[:bounce][:bouncedRecipients].any?
|
||||
|
||||
BouncedMailAddress.record(bounce_params)
|
||||
head(:created)
|
||||
rescue ActionController::ParameterMissing
|
||||
head(:bad_request)
|
||||
end
|
||||
|
||||
def bounce_params
|
||||
params.require(:data).require(:bounce).require(:bouncedRecipients).each do |r|
|
||||
r.require(:emailAddress)
|
||||
end
|
||||
|
||||
params.require(:data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -62,6 +62,7 @@ class Registrar
|
|||
|
||||
def find_user_by_idc_and_allowed(idc)
|
||||
return User.new unless idc
|
||||
|
||||
possible_users = ApiUser.where(identity_code: idc) || User.new
|
||||
possible_users.each do |selected_user|
|
||||
if selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip)
|
||||
|
|
|
@ -109,6 +109,7 @@ class Ability
|
|||
can :destroy, :pending
|
||||
can :create, :zonefile
|
||||
can :access, :settings_menu
|
||||
can :manage, BouncedMailAddress
|
||||
end
|
||||
|
||||
def static_registrant
|
||||
|
|
28
app/models/bounced_mail_address.rb
Normal file
28
app/models/bounced_mail_address.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class BouncedMailAddress < ApplicationRecord
|
||||
validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
|
||||
|
||||
def bounce_reason
|
||||
"#{action} (#{status} #{diagnostic})"
|
||||
end
|
||||
|
||||
def self.record(json)
|
||||
bounced_records = json['bounce']['bouncedRecipients']
|
||||
bounced_records.each do |record|
|
||||
bounce_record = BouncedMailAddress.new(params_from_json(json, record))
|
||||
|
||||
bounce_record.save
|
||||
end
|
||||
end
|
||||
|
||||
def self.params_from_json(json, bounced_record)
|
||||
{
|
||||
email: bounced_record['emailAddress'],
|
||||
message_id: json['mail']['messageId'],
|
||||
bounce_type: json['bounce']['bounceType'],
|
||||
bounce_subtype: json['bounce']['bounceSubType'],
|
||||
action: bounced_record['action'],
|
||||
status: bounced_record['status'],
|
||||
diagnostic: bounced_record['diagnosticCode'],
|
||||
}
|
||||
end
|
||||
end
|
|
@ -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'
|
||||
|
|
36
app/views/admin/bounced_mail_addresses/index.html.erb
Normal file
36
app/views/admin/bounced_mail_addresses/index.html.erb
Normal file
|
@ -0,0 +1,36 @@
|
|||
<h1>Bounced Mail Addresses</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Action</th>
|
||||
<th>Status</th>
|
||||
<th>Diagnostic</th>
|
||||
<th>Tracked</th>
|
||||
<th colspan="2">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @bounced_mail_addresses.each do |mail_addr| %>
|
||||
<tr>
|
||||
<td><%= mail_addr.email %></td>
|
||||
<td><%= mail_addr.action %></td>
|
||||
<td><%= mail_addr.status %></td>
|
||||
<td><%= mail_addr.diagnostic %></td>
|
||||
<td><%= mail_addr.created_at %></td>
|
||||
<td><%= link_to 'Detailed', admin_bounced_mail_address_path(mail_addr) %></td>
|
||||
<td><%= link_to 'Destroy', admin_bounced_mail_address_path(mail_addr), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
27
app/views/admin/bounced_mail_addresses/show.html.erb
Normal file
27
app/views/admin/bounced_mail_addresses/show.html.erb
Normal file
|
@ -0,0 +1,27 @@
|
|||
<p>
|
||||
<strong>Email:</strong>
|
||||
<%= @bounced_mail_address.email %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Bounced message ID:</strong>
|
||||
<%= @bounced_mail_address.message_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Overall bounce type:</strong>
|
||||
<%= @bounced_mail_address.bounce_type %> (<%= @bounced_mail_address.bounce_subtype %> )
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Bounced recipient status:</strong>
|
||||
<%= @bounced_mail_address.action %> (<%= @bounced_mail_address.status %>)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Bounced recipient diagnostic:</strong>
|
||||
<pre><%= @bounced_mail_address.diagnostic %></pre>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Back', admin_bounced_mail_addresses_path %>
|
||||
<%= link_to 'Destroy', admin_bounced_mail_address_path(@bounced_mail_address), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
Loading…
Add table
Add a link
Reference in a new issue