diff --git a/app/controllers/admin/certificates_controller.rb b/app/controllers/admin/certificates_controller.rb index 3f1113b0f..56e30f26a 100644 --- a/app/controllers/admin/certificates_controller.rb +++ b/app/controllers/admin/certificates_controller.rb @@ -41,7 +41,7 @@ module Admin def sign if @certificate.sign!(password: certificate_params[:password]) flash[:notice] = I18n.t('record_updated') - notify_api_user + notify_registrar redirect_to [:admin, @api_user, @certificate] else flash.now[:alert] = I18n.t('failed_to_update_record') @@ -88,10 +88,10 @@ module Admin end end - def notify_api_user - api_user_email = @api_user.registrar.email + def notify_registrar + email = @api_user.registrar.email - CertificateMailer.signed(email: api_user_email, api_user: @api_user, + CertificateMailer.signed(email: email, api_user: @api_user, crt: OpenSSL::X509::Certificate.new(@certificate.crt)) .deliver_now end diff --git a/app/controllers/admin/white_ips_controller.rb b/app/controllers/admin/white_ips_controller.rb index a621a8386..13867606e 100644 --- a/app/controllers/admin/white_ips_controller.rb +++ b/app/controllers/admin/white_ips_controller.rb @@ -36,7 +36,11 @@ module Admin end def update + previously_committed = @white_ip.committed + if @white_ip.update(white_ip_params) + notify_registrar if !previously_committed && @white_ip.committed + flash[:notice] = I18n.t('record_updated') redirect_to [:admin, @registrar, @white_ip] else @@ -52,7 +56,14 @@ module Admin end def white_ip_params - params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, { interfaces: [] }) + params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, :committed, { interfaces: [] }) + end + + def notify_registrar + email = @white_ip.registrar.email + + WhiteIpMailer.committed(email: email, ip: @white_ip) + .deliver_now end end end diff --git a/app/controllers/repp/v1/accounts_controller.rb b/app/controllers/repp/v1/accounts_controller.rb index 8aee2d294..2fe716e9c 100644 --- a/app/controllers/repp/v1/accounts_controller.rb +++ b/app/controllers/repp/v1/accounts_controller.rb @@ -174,7 +174,7 @@ module Repp end def serialized_ips(ips) - ips.as_json(only: %i[id ipv4 ipv6 interfaces]) + ips.as_json(only: %i[id ipv4 ipv6 interfaces committed]) end end end diff --git a/app/controllers/repp/v1/white_ips_controller.rb b/app/controllers/repp/v1/white_ips_controller.rb index 4cc5fec04..beb3cde03 100644 --- a/app/controllers/repp/v1/white_ips_controller.rb +++ b/app/controllers/repp/v1/white_ips_controller.rb @@ -31,21 +31,21 @@ module Repp return end - notify_admins if @white_ip.interfaces.include? WhiteIp::API + uncommit_and_notify_admins if api_interface?(@white_ip) render_success(data: { ip: { id: @white_ip.id } }) end api :PUT, '/repp/v1/white_ips/:id' desc 'Update whitelisted IP address' def update - api = @white_ip.interfaces.include? WhiteIp::API + previously_api = api_interface?(@white_ip) unless @white_ip.update(white_ip_params) handle_non_epp_errors(@white_ip) return end - notify_admins if @white_ip.interfaces.include? WhiteIp::API - notify_admins if api && !@white_ip.interfaces.include?(WhiteIp::API) + uncommit_and_notify_admins if api_interface?(@white_ip) + uncommit_and_notify_admins if previously_api && !api_interface?(@white_ip) render_success(data: { ip: { id: @white_ip.id } }) end @@ -58,12 +58,16 @@ module Repp return end - notify_admins(ip: ip, action: 'deleted') if ip.interfaces.include?(WhiteIp::API) + uncommit_and_notify_admins(ip: ip, action: 'deleted') if ip.interfaces.include?(WhiteIp::API) render_success end private + def api_interface?(ip) + ip.interfaces.include? WhiteIp::API + end + def find_white_ip @white_ip = current_user.registrar.white_ips.find(params[:id]) end @@ -72,7 +76,8 @@ module Repp params.require(:white_ip).permit(:address, interfaces: []) end - def notify_admins(ip: @white_ip, action: 'updated') + def uncommit_and_notify_admins(ip: @white_ip, action: 'updated') + @white_ip.update(committed: false) if action == 'updated' admin_users_emails = User.admin.pluck(:email).reject(&:blank?) return if admin_users_emails.empty? diff --git a/app/mailers/white_ip_mailer.rb b/app/mailers/white_ip_mailer.rb index 61914fb9a..8b7984ba8 100644 --- a/app/mailers/white_ip_mailer.rb +++ b/app/mailers/white_ip_mailer.rb @@ -14,4 +14,10 @@ class WhiteIpMailer < ApplicationMailer subject = '[Important] Whitelisted IP Address Removal Notification' mail(to: email, subject: subject) end + + def committed(email:, ip:) + @white_ip = ip + subject = 'Whitelisted IP Address Activation Confirmation' + mail(to: email, subject: subject) + end end diff --git a/app/views/admin/registrars/show/_white_ips.html.erb b/app/views/admin/registrars/show/_white_ips.html.erb index 5de3066c0..df59c8b63 100644 --- a/app/views/admin/registrars/show/_white_ips.html.erb +++ b/app/views/admin/registrars/show/_white_ips.html.erb @@ -9,6 +9,7 @@ <%= WhiteIp.human_attribute_name :ipv4 %> <%= WhiteIp.human_attribute_name :ipv6 %> <%= WhiteIp.human_attribute_name :interfaces %> + <%= WhiteIp.human_attribute_name :committed %> @@ -26,6 +27,7 @@ <% end %> <%= white_ip.interfaces.join(', ').upcase %> + <%= white_ip.committed %> <% end %> diff --git a/app/views/admin/white_ips/_form.haml b/app/views/admin/white_ips/_form.haml index 7a0371697..2236c09ad 100644 --- a/app/views/admin/white_ips/_form.haml +++ b/app/views/admin/white_ips/_form.haml @@ -26,7 +26,13 @@ .col-md-7 = f.check_box :interfaces, { multiple: true }, x, nil = hidden_field_tag "white_ip[interfaces][]", nil + .form-group + .col-md-4.control-label + = f.label :committed + .col-md-7 + = f.check_box :committed + %hr .row .col-md-8.text-right - = button_tag(t(:save), class: 'btn btn-primary') + = button_tag(t(:save), class: 'btn btn-primary') \ No newline at end of file diff --git a/app/views/admin/white_ips/show.haml b/app/views/admin/white_ips/show.haml index 2ec354aa4..d3df82e93 100644 --- a/app/views/admin/white_ips/show.haml +++ b/app/views/admin/white_ips/show.haml @@ -22,3 +22,6 @@ %dt= WhiteIp.human_attribute_name :interfaces %dd= @white_ip.interfaces.join(', ').upcase + + %dt= WhiteIp.human_attribute_name :committed + %dd= @white_ip.committed diff --git a/app/views/mailers/white_ip_mailer/committed.html.erb b/app/views/mailers/white_ip_mailer/committed.html.erb new file mode 100644 index 000000000..df782f79f --- /dev/null +++ b/app/views/mailers/white_ip_mailer/committed.html.erb @@ -0,0 +1,43 @@ +Tere, +

+

+Anname teada, et Teie konto juurde kuuluv lubatud IP-aadress on edukalt aktiveeritud. +

+

IP-aadressi andmed:

+ +

+Kõik päringud, mis algavad IP-aadressist <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>, saavad meie süsteemis piiranguteta juurdepääsu. +Palun veenduge, et hoiaksite selle IP-aadressi turvalisust ja konfidentsiaalsust, et vältida volitamata juurdepääsu. +

+Kui Teil on küsimusi seoses Teie lubatud IP-aadressi aktiveerimisega, võtke meiega ühendust. +

+

+Parimate soovidega, +

+<%= render 'mailers/shared/signatures/signature.et.html' %> +
+

+ +Hi, +

+

+We would like to inform you that the whitelisted IP address associated with your account has been successfully activated. +

+

IP address Details:

+ +

+All requests originating from the IP address <%= @white_ip.ipv4.presence || @white_ip.ipv6 %> will now have unrestricted access to our system. +Please ensure the security and confidentiality of this IP address to prevent unauthorized access. +

+If you have any questions regarding the activation of your whitelisted IP address, please contact us. +

+

+Best regards, +

+<%= render 'mailers/shared/signatures/signature.en.html' %> \ No newline at end of file diff --git a/app/views/mailers/white_ip_mailer/committed.text.erb b/app/views/mailers/white_ip_mailer/committed.text.erb new file mode 100644 index 000000000..fb38714df --- /dev/null +++ b/app/views/mailers/white_ip_mailer/committed.text.erb @@ -0,0 +1,32 @@ +Tere, + +Anname teada, et Teie konto juurde kuuluv lubatud IP-aadress on edukalt aktiveeritud. + +IP-aadressi andmed: +- IP-aadress: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %> +- Liidesed: <%= @white_ip.interfaces.join(', ') %> + +Kõik päringud, mis algavad IP-aadressist <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>, saavad meie süsteemis piiranguteta juurdepääsu. +Palun veenduge, et hoiaksite selle IP-aadressi turvalisust ja konfidentsiaalsust, et vältida volitamata juurdepääsu. + +Kui Teil on küsimusi seoses Teie lubatud IP-aadressi aktiveerimisega, võtke meiega ühendust. + +Parimate soovidega, +<%= render 'mailers/shared/signatures/signature.et.html' %> +--- + +Hi, + +We would like to inform you that the whitelisted IP address associated with your account has been successfully activated. + +IP address Details: +- IP address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %> +- Interfaces: <%= @white_ip.interfaces.join(', ') %> + +All requests originating from the IP address <%= @white_ip.ipv4.presence || @white_ip.ipv6 %> will now have unrestricted access to our system. +Please ensure the security and confidentiality of this IP address to prevent unauthorized access. + +If you have any questions regarding the activation of your whitelisted IP address, please contact us. + +Best regards, +<%= render 'mailers/shared/signatures/signature.en.html' %> \ No newline at end of file diff --git a/db/migrate/20230707084741_add_committed_to_white_ips.rb b/db/migrate/20230707084741_add_committed_to_white_ips.rb new file mode 100644 index 000000000..751bcc14c --- /dev/null +++ b/db/migrate/20230707084741_add_committed_to_white_ips.rb @@ -0,0 +1,5 @@ +class AddCommittedToWhiteIps < ActiveRecord::Migration[6.1] + def change + add_column :white_ips, :committed, :boolean, default: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 44ffd7162..117880656 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2806,7 +2806,8 @@ CREATE TABLE public.white_ips ( created_at timestamp without time zone, updated_at timestamp without time zone, creator_str character varying, - updator_str character varying + updator_str character varying, + committed boolean DEFAULT true ); @@ -5468,6 +5469,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20221207102831'), ('20221214073933'), ('20221214074252'), -('20230531111154'); +('20230531111154'), +('20230707084741');