Skip to content

Commit

Permalink
Added poi downloader service
Browse files Browse the repository at this point in the history
  • Loading branch information
tsoganov committed Oct 15, 2024
1 parent f14919f commit 43b05c0
Show file tree
Hide file tree
Showing 18 changed files with 1,699 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def handle_error_response(res, dialog: false)
msg = res.body[:message]

case res.body[:code]
when 2202, 503, 401
when 2202, 401
respond_with_log_out(msg)
when 2000..2500
respond(msg, dialog: dialog)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def verify
redirect_to contact_path(contact_code: @response.contact[:code])
end

def download_poi
conn = ApiConnector::Contacts::PoiDownloader.new(**auth_info)
result = conn.call_action(id: params[:contact_code])
handle_response(result); return if performed?

send_data(@response, type: 'application/pdf',
disposition: 'attachment',
filename: @message.match(/filename=(\"?)(.+)\1/)[2])
end

private

def contact_params
Expand Down
18 changes: 18 additions & 0 deletions app/services/api_connector/contacts/poi_downloader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class ApiConnector
module Contacts
class PoiDownloader < ApiConnector
ACTION = 'download_poi'
ENDPOINT = {
method: 'get',
endpoint: '/contacts/download_poi',
}.freeze

def download_poi(params = {})
request(url: url_with_id(params[:id]),
method: method)
end
end
end
end
7 changes: 4 additions & 3 deletions app/views/contacts/partials/_general.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
<th><%= t('contacts.show.verification') %></th>
<td>
<% if @contact[:verified_at].present? %>
Verified on <%= l(@contact[:verified_at].to_datetime, format: :long) %>
<%= t('contacts.show.verified_on') %> <%= l(@contact[:verified_at].to_datetime, format: :long) %>
<%= icon_link_to 'fas fa-file-pdf', download_poi_contact_path(contact_code: @contact[:code]), class: 'simple_tooltip', data: { 'tippy-content': t('contacts.show.download_poi') } %>
<% elsif @contact[:ident_request_sent_at].present? %>
Identification requested on <%= l(@contact[:ident_request_sent_at].to_datetime, format: :long) %>
<%= t('contacts.show.ident_requested_on') %> <%= l(@contact[:ident_request_sent_at].to_datetime, format: :long) %>
<% else %>
Unverified
<%= t('contacts.show.unverified') %>
<% end %>
</td>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,14 @@ en:
requested_at: "Requested at"
verified_at: "Verified at"
verify_confirm_html: "Are you sure you want to send identification request to contact <span>%{code}</span>?"
verified_on: "Verified on"
ident_requested_on: "Identification requested on"
unverified: "Unverified"
contact_types:
registrant: "Registrant"
tech: "Technical contact"
admin: "Admin contact"
download_poi: "Download Proof of Identity"

delete:
title: "Delete contact"
Expand Down
4 changes: 4 additions & 0 deletions config/locales/et.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,14 @@ et:
requested_at: "Taotletud"
verified_at: "Verifitseeritud"
verify_confirm_html: "Kas olete kindel, et soovite saata kontaktile <span>%{code}</span> tuvastamistaotlust?"
verified_on: "Verifitseeritud"
ident_requested_on: "Identifitseerimine taotletud"
unverified: "Verifitseerimata"
contact_types:
registrant: "Registreerija"
tech: "Tehniline kontakt"
admin: "Admin kontakt"
download_poi: "Laadi alla isikutõend"

delete:
title: "Kustuta kontakt"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
get 'contact/delete', to: 'contacts#delete', as: :delete_contact
delete 'contacts/destroy', to: 'contacts#destroy', as: :destroy_contact
post 'contact/verify', to: 'contacts#verify', as: :verify_contact
get 'contact/download_poi', to: 'contacts#download_poi', as: :download_poi_contact
resources :contacts, except: %i[destroy update show edit]

get 'invoices/:id/download', to: 'invoices#download', as: :download_invoice
Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/contacts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
params: {
contact_code: '1111111:5A0D95F4'
}
},
{
method: :download_poi,
http_method: :get,
params: {
contact_code: '1111111:5A0D95F4'
}
}
]

Expand Down
1 change: 0 additions & 1 deletion spec/features/viewing_domains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
scenario 'with wrong response content type' do
VCR.use_cassette 'controllers/domains_controller/index-content-type-fail', record: :once do
visit domains_path
expect(page).to have_current_path(login_path)
expect(page).to have_content('Unsupported content type')
end
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43b05c0

Please sign in to comment.