From ca317ace45b8464960706702c01e3272aeead77d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 15 May 2019 15:17:43 +0300 Subject: [PATCH 1/6] Add registrar IBAN --- .../admin/registrars_controller.rb | 1 + .../admin/registrars/form/_billing.html.erb | 9 +++++++++ .../admin/registrars/show/_billing.html.erb | 3 +++ config/locales/en.yml | 1 + .../20190515113153_add_registrars_iban.rb | 5 +++++ db/structure.sql | 7 +++++-- test/fixtures/registrars.yml | 1 + .../integration/admin_area/registrars_test.rb | 20 +++++++++++++++++++ 8 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20190515113153_add_registrars_iban.rb create mode 100644 test/integration/admin_area/registrars_test.rb diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 1e9df288b..17a618273 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -73,6 +73,7 @@ module Admin :vat_rate, :accounting_customer_code, :billing_email, + :iban, :language) end diff --git a/app/views/admin/registrars/form/_billing.html.erb b/app/views/admin/registrars/form/_billing.html.erb index e9f9b5c88..fa1583ca8 100644 --- a/app/views/admin/registrars/form/_billing.html.erb +++ b/app/views/admin/registrars/form/_billing.html.erb @@ -67,6 +67,15 @@ <% end %> + +
+
+ <%= f.label :iban %> +
+
+ <%= f.text_field :iban, class: 'form-control' %> +
+
diff --git a/app/views/admin/registrars/show/_billing.html.erb b/app/views/admin/registrars/show/_billing.html.erb index 7ed9826ad..da79b9074 100644 --- a/app/views/admin/registrars/show/_billing.html.erb +++ b/app/views/admin/registrars/show/_billing.html.erb @@ -19,6 +19,9 @@
<%= Registrar.human_attribute_name :reference_no %>
<%= registrar.reference_no %>
+ +
<%= Registrar.human_attribute_name :iban %>
+
<%= registrar.iban %>
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 066f569e1..4bb40ed5d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -692,3 +692,4 @@ en: ipv4: IPv4 ipv6: IPv6 reference_no: Reference number + iban: IBAN diff --git a/db/migrate/20190515113153_add_registrars_iban.rb b/db/migrate/20190515113153_add_registrars_iban.rb new file mode 100644 index 000000000..2f1e7b50f --- /dev/null +++ b/db/migrate/20190515113153_add_registrars_iban.rb @@ -0,0 +1,5 @@ +class AddRegistrarsIban < ActiveRecord::Migration + def change + add_column :registrars, :iban, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index bec0a6f55..73841bc84 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2200,7 +2200,8 @@ CREATE TABLE public.registrars ( reference_no character varying NOT NULL, test_registrar boolean DEFAULT false, language character varying NOT NULL, - vat_rate numeric(4,3) + vat_rate numeric(4,3), + iban character varying ); @@ -3987,7 +3988,7 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ -- --- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_versions_on_item_type_and_item_id ON public.versions USING btree (item_type, item_id); @@ -4966,5 +4967,7 @@ INSERT INTO schema_migrations (version) VALUES ('20190510090240'); INSERT INTO schema_migrations (version) VALUES ('20190510102549'); +INSERT INTO schema_migrations (version) VALUES ('20190515113153'); + INSERT INTO schema_migrations (version) VALUES ('20190520093231'); diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index 2f5ed74cf..b0ae6d280 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -11,6 +11,7 @@ bestnames: billing_email: billing@bestnames.test website: https://bestnames.test reference_no: 13 + iban: GB33BUKB20201555555555 goodnames: name: Good Names diff --git a/test/integration/admin_area/registrars_test.rb b/test/integration/admin_area/registrars_test.rb new file mode 100644 index 000000000..009e7c6d6 --- /dev/null +++ b/test/integration/admin_area/registrars_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + + setup do + @registrar = registrars(:bestnames) + sign_in users(:admin) + end + + def test_updates_registrar_optional_attributes + new_iban = 'GB94BARC10201530093459' + assert_not_equal new_iban, @registrar.iban + + patch admin_registrar_path(@registrar), registrar: { iban: new_iban } + @registrar.reload + + assert_equal new_iban, @registrar.iban + end +end \ No newline at end of file From da191e14e63920502960f27010b9b405ee06a0c5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 20 May 2019 13:25:26 +0300 Subject: [PATCH 2/6] Validate iban --- app/controllers/admin/registrars_controller.rb | 5 +++++ app/models/iban.rb | 5 +++++ app/views/admin/registrars/form/_billing.html.erb | 2 +- test/models/iban_test.rb | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/models/iban.rb create mode 100644 test/models/iban_test.rb diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 17a618273..b925a8156 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -3,6 +3,7 @@ module Admin load_and_authorize_resource before_action :set_registrar, only: [:show, :edit, :update, :destroy] helper_method :registry_vat_rate + helper_method :iban_max_length def index @q = Registrar.joins(:accounts).ordered.search(params[:q]) @@ -80,5 +81,9 @@ module Admin def registry_vat_rate Registry.current.vat_rate end + + def iban_max_length + Iban.max_length + end end end diff --git a/app/models/iban.rb b/app/models/iban.rb new file mode 100644 index 000000000..260aca827 --- /dev/null +++ b/app/models/iban.rb @@ -0,0 +1,5 @@ +class Iban + def self.max_length + 34 + end +end \ No newline at end of file diff --git a/app/views/admin/registrars/form/_billing.html.erb b/app/views/admin/registrars/form/_billing.html.erb index fa1583ca8..8d1375f64 100644 --- a/app/views/admin/registrars/form/_billing.html.erb +++ b/app/views/admin/registrars/form/_billing.html.erb @@ -73,7 +73,7 @@ <%= f.label :iban %>
- <%= f.text_field :iban, class: 'form-control' %> + <%= f.text_field :iban, maxlength: iban_max_length, class: 'form-control' %>
diff --git a/test/models/iban_test.rb b/test/models/iban_test.rb new file mode 100644 index 000000000..8455c4e86 --- /dev/null +++ b/test/models/iban_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class IbanTest < ActiveSupport::TestCase + def test_returns_max_length + assert_equal 34, Iban.max_length + end +end \ No newline at end of file From 5c99a6dead4682b846888e4f801dc717d32d89b8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 30 May 2019 14:26:21 +0300 Subject: [PATCH 3/6] Fix SQL schema --- db/structure.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/structure.sql b/db/structure.sql index 73841bc84..6fd2efa2e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3988,7 +3988,7 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ -- --- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_versions_on_item_type_and_item_id ON public.versions USING btree (item_type, item_id); From 633aebdb80a6087b884caabc4707a079df5749a6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 30 May 2019 15:04:28 +0300 Subject: [PATCH 4/6] Add form field hint --- app/views/admin/registrars/form/_billing.html.erb | 1 + config/locales/admin/registrars.en.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/views/admin/registrars/form/_billing.html.erb b/app/views/admin/registrars/form/_billing.html.erb index 8d1375f64..91086918b 100644 --- a/app/views/admin/registrars/form/_billing.html.erb +++ b/app/views/admin/registrars/form/_billing.html.erb @@ -74,6 +74,7 @@
<%= f.text_field :iban, maxlength: iban_max_length, class: 'form-control' %> + <%= t '.iban_hint' %>
diff --git a/config/locales/admin/registrars.en.yml b/config/locales/admin/registrars.en.yml index 7256fabb2..88e95843e 100644 --- a/config/locales/admin/registrars.en.yml +++ b/config/locales/admin/registrars.en.yml @@ -63,6 +63,7 @@ en: registry's rate of %{registry_vat_rate} will be applied in this case. no_reference_number_hint: Reference number will be generated automatically disabled_reference_number_hint: Reference number cannot be changed + iban_hint: Used for e-invoices preferences: header: Preferences \ No newline at end of file From 02c37a1c3197e5e28d31ff81edd1f82e2738a6c4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 30 May 2019 15:28:54 +0300 Subject: [PATCH 5/6] Let registrars change IBAN --- app/controllers/registrar/account_controller.rb | 2 +- app/views/registrar/account/_details.html.erb | 3 +++ app/views/registrar/account/_form.html.erb | 10 ++++++++++ app/views/registrar/account/show.html.erb | 4 ++-- test/system/registrar_area/account_test.rb | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/controllers/registrar/account_controller.rb b/app/controllers/registrar/account_controller.rb index 1bcf9e468..9252098b8 100644 --- a/app/controllers/registrar/account_controller.rb +++ b/app/controllers/registrar/account_controller.rb @@ -18,7 +18,7 @@ class Registrar private def registrar_params - params.require(:registrar).permit(:billing_email) + params.require(:registrar).permit(:billing_email, :iban) end end end \ No newline at end of file diff --git a/app/views/registrar/account/_details.html.erb b/app/views/registrar/account/_details.html.erb index 9e35da899..185b046c8 100644 --- a/app/views/registrar/account/_details.html.erb +++ b/app/views/registrar/account/_details.html.erb @@ -7,6 +7,9 @@
<%= Registrar.human_attribute_name :billing_email %>
<%= registrar.billing_email %>
+ +
<%= Registrar.human_attribute_name :iban %>
+
<%= registrar.iban %>
diff --git a/app/views/registrar/account/_form.html.erb b/app/views/registrar/account/_form.html.erb index c2bb6aa82..7a7e4491b 100644 --- a/app/views/registrar/account/_form.html.erb +++ b/app/views/registrar/account/_form.html.erb @@ -11,6 +11,16 @@ +
+
+ <%= f.label :iban %> +
+ +
+ <%= f.text_field :iban, class: 'form-control' %> +
+
+
diff --git a/app/views/registrar/account/show.html.erb b/app/views/registrar/account/show.html.erb index 53218d1f7..46813fa96 100644 --- a/app/views/registrar/account/show.html.erb +++ b/app/views/registrar/account/show.html.erb @@ -3,13 +3,13 @@
-
+
<%= render 'details', registrar: current_registrar_user.registrar %>
-
+
<%= render 'linked_users', linked_users: current_registrar_user.linked_users %>
\ No newline at end of file diff --git a/test/system/registrar_area/account_test.rb b/test/system/registrar_area/account_test.rb index 438de2629..81db3ed4b 100644 --- a/test/system/registrar_area/account_test.rb +++ b/test/system/registrar_area/account_test.rb @@ -8,15 +8,19 @@ class RegistrarAccountTest < ApplicationSystemTestCase def test_updates_account new_billing_email = 'new@registrar.test' + new_iban = 'GB77BARC20201530093459' assert_not_equal new_billing_email, @registrar.billing_email + assert_not_equal new_iban, @registrar.iban visit registrar_account_path click_on 'Edit' fill_in 'Billing email', with: new_billing_email + fill_in 'IBAN', with: new_iban click_on 'Save changes' assert_text 'Your account has been updated' assert_text new_billing_email + assert_text new_iban end end \ No newline at end of file From 8c0d6544752a2a2471f84da4644b3c57658ec653 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 30 May 2019 16:00:36 +0300 Subject: [PATCH 6/6] Improve UI --- app/controllers/registrar/account_controller.rb | 5 +++++ app/views/registrar/account/_form.html.erb | 3 ++- config/locales/registrar/account.en.yml | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/registrar/account_controller.rb b/app/controllers/registrar/account_controller.rb index 9252098b8..0bb40ae3c 100644 --- a/app/controllers/registrar/account_controller.rb +++ b/app/controllers/registrar/account_controller.rb @@ -1,6 +1,7 @@ class Registrar class AccountController < BaseController skip_authorization_check + helper_method :iban_max_length def show; end @@ -20,5 +21,9 @@ class Registrar def registrar_params params.require(:registrar).permit(:billing_email, :iban) end + + def iban_max_length + Iban.max_length + end end end \ No newline at end of file diff --git a/app/views/registrar/account/_form.html.erb b/app/views/registrar/account/_form.html.erb index 7a7e4491b..ab1fb0294 100644 --- a/app/views/registrar/account/_form.html.erb +++ b/app/views/registrar/account/_form.html.erb @@ -17,7 +17,8 @@
- <%= f.text_field :iban, class: 'form-control' %> + <%= f.text_field :iban, maxlength: iban_max_length, class: 'form-control' %> + <%= t '.iban_hint' %>
diff --git a/config/locales/registrar/account.en.yml b/config/locales/registrar/account.en.yml index 94d4783d5..a4f3f8f2a 100644 --- a/config/locales/registrar/account.en.yml +++ b/config/locales/registrar/account.en.yml @@ -8,6 +8,7 @@ en: header: Edit your account form: + iban_hint: Required for sending e-invoices to the bank submit_btn: Save changes update: