Merge pull request #1687 from internetee/log-bounced-emails

Gather data about bounced emails via API
This commit is contained in:
Timo Võhmar 2020-12-17 18:30:47 +02:00 committed by GitHub
commit 903f14d0ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 463 additions and 6 deletions

View 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

View file

@ -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' }

View 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

View file

@ -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)