From d5d1be9be5fa1cd36854ba97553be04691563f18 Mon Sep 17 00:00:00 2001 From: Matthias Viehweger Date: Mon, 6 May 2024 16:06:32 +0200 Subject: [PATCH 1/3] Conform to linter and styleguide --- .../event/participations_controller.rb | 2 +- .../export/tabular/abo_addresses/list.rb | 2 +- spec/domain/import/person_importer_spec.rb | 38 ++++++++++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/controllers/insieme/event/participations_controller.rb b/app/controllers/insieme/event/participations_controller.rb index 3581579f..e8991b11 100644 --- a/app/controllers/insieme/event/participations_controller.rb +++ b/app/controllers/insieme/event/participations_controller.rb @@ -9,7 +9,7 @@ module Insieme module Event::ParticipationsController def self.prepended(base) base.permitted_attrs += [:disability, :multiple_disability, :wheel_chair, - person_attributes: additional_person_attributes] + { person_attributes: additional_person_attributes }] end private diff --git a/app/domain/export/tabular/abo_addresses/list.rb b/app/domain/export/tabular/abo_addresses/list.rb index 0fa52615..b19eff60 100644 --- a/app/domain/export/tabular/abo_addresses/list.rb +++ b/app/domain/export/tabular/abo_addresses/list.rb @@ -9,7 +9,7 @@ module Export::Tabular::AboAddresses class List < Export::Tabular::Base - self.model_class = Person + self.model_class = ::Person def attribute_labels { number: 'Kd.Nr.', diff --git a/spec/domain/import/person_importer_spec.rb b/spec/domain/import/person_importer_spec.rb index 0028263f..716bf39b 100644 --- a/spec/domain/import/person_importer_spec.rb +++ b/spec/domain/import/person_importer_spec.rb @@ -47,7 +47,13 @@ end it 'keeps number of matching person' do - existing = Fabricate(:person, { first_name: 'John', last_name: 'Lennon', town: 'Liverpool', number: 2, manual_number: true }) + existing = Fabricate( :person, + first_name: 'John', + last_name: 'Lennon', + town: 'Liverpool', + number: 2, + manual_number: true + ) expect(person).to eq existing expect(person.number).to eq 2 @@ -87,7 +93,11 @@ let(:number) { Person::AUTOMATIC_NUMBER_RANGE.first } it 'uses person with same automatic number from db' do - existing = Fabricate(:person, { first_name: 'Hans', last_name: 'Lehmann', town: 'Liverpool' }) + existing = Fabricate(:person, + first_name: 'Hans', + last_name: 'Lehmann', + town: 'Liverpool' + ) expect(existing.number).to eq number expect(person).to eq existing @@ -111,7 +121,13 @@ context 'manual' do it 'uses person with same manual number from db' do - existing = Fabricate(:person, { first_name: 'Hans', last_name: 'Lehmann', town: 'Liverpool', number: number, manual_number: true }) + existing = Fabricate(:person, + first_name: 'Hans', + last_name: 'Lehmann', + town: 'Liverpool', + number: number, + manual_number: true + ) expect(person).to eq existing expect(person.number).to eq number @@ -124,7 +140,13 @@ end it 'fails if person with other number matches' do - existing = Fabricate(:person, { first_name: 'John', last_name: 'Lennon', town: 'Manchester', number: 456, manual_number: true }) + existing = Fabricate(:person, + first_name: 'John', + last_name: 'Lennon', + town: 'Manchester', + number: 456, + manual_number: true + ) expect(person).to eq existing expect(import_person.person.errors).not_to be_empty @@ -149,7 +171,13 @@ let(:number) { '' } it 'keeps number of matching person' do - existing = Fabricate(:person, { first_name: 'John', last_name: 'Lennon', town: 'Liverpool', number: 2, manual_number: true }) + existing = Fabricate(:person, + first_name: 'John', + last_name: 'Lennon', + town: 'Liverpool', + number: 2, + manual_number: true + ) expect(person).to eq existing expect(person.number).to eq 2 From 3e22f69995fbe8d4cc213031b7786b75b81fb4e4 Mon Sep 17 00:00:00 2001 From: Matthias Viehweger Date: Mon, 6 May 2024 16:08:01 +0200 Subject: [PATCH 2/3] Adapt to changed columns --- .../event/participations_controller.rb | 7 +++--- app/domain/abo_addresses/query.rb | 22 ++++++++++++++++--- .../export/tabular/abo_addresses/list.rb | 16 +++++++++++--- app/models/insieme/person.rb | 4 ++-- db/seeds/development/0_groups.rb | 14 +++++++----- .../event/participations_controller_spec.rb | 6 ++--- spec/domain/export/csv/people_spec.rb | 6 ++--- spec/domain/export/pdf/labels_spec.rb | 5 +++-- .../export/tabular/abo_addresses/list_spec.rb | 6 +++-- spec/domain/import/person_importer_spec.rb | 12 +++++----- spec/fabricators/person_fabricator.rb | 5 +++-- spec/fixtures/people.yml | 11 ++++++---- spec/models/person/address_normalizer_spec.rb | 5 +++-- spec/models/person_spec.rb | 10 ++++----- spec/spec_helper.rb | 5 ++++- 15 files changed, 89 insertions(+), 45 deletions(-) diff --git a/app/controllers/insieme/event/participations_controller.rb b/app/controllers/insieme/event/participations_controller.rb index e8991b11..4938fe7b 100644 --- a/app/controllers/insieme/event/participations_controller.rb +++ b/app/controllers/insieme/event/participations_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2012-2020, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -32,8 +32,9 @@ def permitted_attrs def self.additional_person_attributes person_attributes = [:id, :canton, :birthday, :ahv_number, - :address, :zip_code, :town, :country, - :newly_registered] + :address, + :address_care_of, :street, :housenumber, :postbox, + :zip_code, :town, :country, :newly_registered] Person::ADDRESS_TYPES.grep(/course/).each do |prefix| person_attributes << :"#{prefix}_same_as_main" diff --git a/app/domain/abo_addresses/query.rb b/app/domain/abo_addresses/query.rb index 16e6e742..21f5b298 100644 --- a/app/domain/abo_addresses/query.rb +++ b/app/domain/abo_addresses/query.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2014 insieme Schweiz. This file is part of +# Copyright (c) 2014-2024, insieme Schweiz. This file is part of # hitobito and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -18,8 +18,24 @@ class Query Group::Passivmitglieder::PassivmitgliedMitAbo] # must match with attrs exported in csv - REQUIRED_ATTRS = [:id, :first_name, :last_name, :company_name, :address, - :zip_code, :town, :country, :number] + REQUIRED_ATTRS = [ + :id, + :first_name, + :last_name, + :company_name, + :zip_code, + :town, + :country, + :number + ] + if FeatureGate.enabled?('structured_addresses') + REQUIRED_ATTRS << :address_care_of + REQUIRED_ATTRS << :street + REQUIRED_ATTRS << :housenumber + REQUIRED_ATTRS << :postbox + else + REQUIRED_ATTRS << :address + end attr_reader :swiss, :language diff --git a/app/domain/export/tabular/abo_addresses/list.rb b/app/domain/export/tabular/abo_addresses/list.rb index b19eff60..5a3c8f12 100644 --- a/app/domain/export/tabular/abo_addresses/list.rb +++ b/app/domain/export/tabular/abo_addresses/list.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2014 Insieme Schweiz. This file is part of +# Copyright (c) 2014-2024, Insieme Schweiz. This file is part of # hitobito and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -54,8 +54,18 @@ def country private - def address_line(line) - line = entry.address.to_s.split($INPUT_RECORD_SEPARATOR)[line] + def address_line(line_index) + lines = if FeatureGate.enabled?('structured_addresses') + [ + entry.address_care_of, + entry.address, + entry.postbox + ].compact + else + entry.address.to_s.split($INPUT_RECORD_SEPARATOR) + end + + line = lines[line_index] line ? line.strip : nil end end diff --git a/app/models/insieme/person.rb b/app/models/insieme/person.rb index 4376eb37..f823cde0 100644 --- a/app/models/insieme/person.rb +++ b/app/models/insieme/person.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2012-2020, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -50,7 +50,7 @@ module Insieme::Person validate :assert_address_types_zip_is_valid_swiss_post_code validate :assert_full_name_or_company_name - validates :address, presence: true, unless: :newly_registered + validates :street, presence: true, unless: :newly_registered validates :zip_code, presence: true, unless: :newly_registered validates :town, presence: true, unless: :newly_registered validates :country, presence: true, unless: :newly_registered diff --git a/db/seeds/development/0_groups.rb b/db/seeds/development/0_groups.rb index fe12727f..08a3b8ae 100644 --- a/db/seeds/development/0_groups.rb +++ b/db/seeds/development/0_groups.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# Copyright (c) 2012-2014, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -42,7 +42,8 @@ def seed_group(group, *attrs) be, fr = seed_group(Group::Regionalverein, {name: 'Kanton Bern', short_name: 'BE', - address: 'Seilerstr. 27', + street: 'Seilerstr.', + housenumber: '27', zip_code: 3011, town: 'Bern', country: 'Schweiz', @@ -51,7 +52,8 @@ def seed_group(group, *attrs) {name: 'Freiburg', short_name: 'FR', - address: 'Route de Moncor 14', + street: 'Route de Moncor', + housenumber: '14', zip_code: 1701, town: 'Fribourg', country: 'Schweiz', @@ -62,7 +64,8 @@ def seed_group(group, *attrs) {name: 'Biel-Seeland', short_name: 'BNC', - address: 'Unterer Quai 42', + street: 'Unterer Quai', + housenumber: '42', zip_code: 2500, town: 'Biel/Bienne', country: 'Schweiz', @@ -71,7 +74,8 @@ def seed_group(group, *attrs) {name: 'Region Bern', short_name: 'RBE', - address: 'Effingerstrasse 123', + street: 'Effingerstrasse', + housenumber: '123', zip_code: 3000, town: 'Bern', country: 'Schweiz', diff --git a/spec/controllers/event/participations_controller_spec.rb b/spec/controllers/event/participations_controller_spec.rb index 097f7813..4f47f42f 100644 --- a/spec/controllers/event/participations_controller_spec.rb +++ b/spec/controllers/event/participations_controller_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# Copyright (c) 2012-2014, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -23,7 +23,7 @@ birthday: '2014-09-22', zip_code: '1234', town: 'dummy', - address: 'dummy', + street: 'dummy', country: 'DE', ahv_number: '123', correspondence_course_same_as_main: false, @@ -64,7 +64,7 @@ end %w(town - address + street correspondence_course_salutation correspondence_course_first_name diff --git a/spec/domain/export/csv/people_spec.rb b/spec/domain/export/csv/people_spec.rb index 2fe9dd6d..6f5ed245 100644 --- a/spec/domain/export/csv/people_spec.rb +++ b/spec/domain/export/csv/people_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# Copyright (c) 2012-2014, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -61,8 +61,8 @@ before do Fabricate(Group::Aktivmitglieder::Aktivmitglied.sti_name.to_sym, group: groups(:aktiv), - person: Fabricate(:person, number: '123', first_name: 'John', - last_name: 'Lennon', address: 'Bank Street 105', + person: Fabricate(:person, number: '123', first_name: 'John', last_name: 'Lennon', + street: 'Bank Street', housenumber: '105', zip_code: 1234, town: 'New York', additional_information: 'English musician')) diff --git a/spec/domain/export/pdf/labels_spec.rb b/spec/domain/export/pdf/labels_spec.rb index eade6f3c..a9bb70bc 100644 --- a/spec/domain/export/pdf/labels_spec.rb +++ b/spec/domain/export/pdf/labels_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2014-2021, Insieme Schweiz. This file is part of +# Copyright (c) 2014-2024, Insieme Schweiz. This file is part of # hitobito and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -21,7 +21,8 @@ def to_name(contactable) before do person.update!( - address: 'My Street', + street: 'My Street', + housenumber: nil, town: 'Bern', zip_code: '3007', correspondence_course_same_as_main: false, diff --git a/spec/domain/export/tabular/abo_addresses/list_spec.rb b/spec/domain/export/tabular/abo_addresses/list_spec.rb index 70f57d6f..bf0cb3aa 100644 --- a/spec/domain/export/tabular/abo_addresses/list_spec.rb +++ b/spec/domain/export/tabular/abo_addresses/list_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# Copyright (c) 2014, insieme Schweiz. This file is part of +# Copyright (c) 2014-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -34,7 +34,9 @@ people(:regio_aktiv).update!(first_name: 'Hans', last_name: 'Muster', company_name: 'Firma', - address: "Eigerplatz 4\nPostfach 123", + street: "Eigerplatz", + housenumber: "4", + postbox: "Postfach 123", zip_code: 3000, town: 'Bern', country: 'CH', diff --git a/spec/domain/import/person_importer_spec.rb b/spec/domain/import/person_importer_spec.rb index 716bf39b..469ea63a 100644 --- a/spec/domain/import/person_importer_spec.rb +++ b/spec/domain/import/person_importer_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# Copyright (c) 2014, insime Schweiz. This file is part of +# Copyright (c) 2014-2024, insime Schweiz. This file is part of # hitobito and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -17,8 +17,8 @@ let(:data) { parser.map_data(mapping) } let(:user) { people(:regio_leader) } let(:foreign_group) { groups(:chaeib) } - let(:header) { "Vorname,Nachname,Geburtsdatum,Nummer,Stadt,Adresse,PLZ,Land,Korrespondenzsprache,Sprache" } - let(:row) { "John,Lennon,9.10.1940,#{number},Liverpool,Teststrasse 23,3007,CH,de,de" } + let(:header) { "Vorname,Nachname,Geburtsdatum,Nummer,Stadt,Strasse,Hausnummer,PLZ,Land,Korrespondenzsprache,Sprache" } + let(:row) { "John,Lennon,9.10.1940,#{number},Liverpool,Teststrasse,23,3007,CH,de,de" } let(:number) { 123 } let(:importer) do @@ -38,7 +38,8 @@ Nachname: 'last_name', Geburtsdatum: 'birthday', Stadt: 'town', - Adresse: 'address', + Strasse: 'street', + Hausnummer: 'housenumber', PLZ: 'zip_code', Land: 'country', Korrespondenzsprache: 'correspondence_language', @@ -81,7 +82,8 @@ Geburtsdatum: 'birthday', Nummer: 'number', Stadt: 'town', - Adresse: 'address', + Strasse: 'street', + Hausnummer: 'housenumber', PLZ: 'zip_code', Land: 'country', Korrespondenzsprache: 'correspondence_language', diff --git a/spec/fabricators/person_fabricator.rb b/spec/fabricators/person_fabricator.rb index 4d59f6c9..bda6c555 100644 --- a/spec/fabricators/person_fabricator.rb +++ b/spec/fabricators/person_fabricator.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -# Copyright (c) 2020, Insieme Schweiz. This file is part of +# Copyright (c) 2020-2024, Insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -13,7 +13,8 @@ company false - address 'Teststrasse 23' + street 'Teststrasse' + housenumber '23' zip_code '3007' town 'Bern' country 'CH' diff --git a/spec/fixtures/people.yml b/spec/fixtures/people.yml index 2304e6f1..3952dee0 100644 --- a/spec/fixtures/people.yml +++ b/spec/fixtures/people.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2014, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -9,7 +9,8 @@ top_leader: email: top.leader@insieme.example.com contact_data_visible: true primary_group: dachverein - address: Teststrasse 23 + street: Teststrasse + housenumber: 23 zip_code: 3007 town: Bern country: CH @@ -22,7 +23,8 @@ regio_leader: email: regio.leader@insieme.example.com contact_data_visible: true primary_group: be - address: Teststrasse 23 + street: Teststrasse + housenumber: 23 zip_code: 3007 town: Bern country: CH @@ -34,7 +36,8 @@ regio_aktiv: last_name: Person email: child1@insieme.example.com primary_group: aktiv - address: Teststrasse 23 + street: Teststrasse + housenumber: 23 zip_code: 3007 town: Bern country: CH diff --git a/spec/models/person/address_normalizer_spec.rb b/spec/models/person/address_normalizer_spec.rb index 95770f1f..f844abe5 100644 --- a/spec/models/person/address_normalizer_spec.rb +++ b/spec/models/person/address_normalizer_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# Copyright (c) 2012-2014, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -10,7 +10,8 @@ describe Person::AddressNormalizer do let(:attrs) { { first_name: 'Puzzle', last_name: 'ITC', - address: 'Eigerplatz 4', + street: 'Eigerplatz', + housenumber: '4', zip_code: '3007', town: 'Bern', country: 'CH', diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 27a79fd1..9e888222 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2012-2020, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. @@ -194,8 +194,8 @@ def create(attrs = {}) Fabricate(:person, attrs.merge(first_name: 'John', last_name: 'Lennon', - address: 'Pennylane', zip_code: '9933', - town: 'Liverpool', country: 'US')) + street: 'Pennylane', housenumber: nil, + zip_code: '9933', town: 'Liverpool', country: 'US')) end end @@ -311,8 +311,8 @@ def new_person(attrs) expect { nicknamed_person.last_name = nil }.to change { nicknamed_person.valid? }.from(true).to(false) end - it 'has an address' do - expect { named_person.address = nil }.to change { named_person.valid? }.from(true).to(false) + it 'has a street' do + expect { named_person.street = nil }.to change { named_person.valid? }.from(true).to(false) end it 'has a zip_code' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4b46cfbd..782cea2c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,13 @@ # encoding: utf-8 -# Copyright (c) 2012-2014, insieme Schweiz. This file is part of +# Copyright (c) 2012-2024, insieme Schweiz. This file is part of # hitobito_insieme and licensed under the Affero General Public License version 3 # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_insieme. +ENV['RAILS_STRUCTURED_ADDRESSES'] = '1' +ENV['RAILS_ADDRESS_MIGRATION'] = '0' + load File.expand_path('../../app_root.rb', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) From c6ce256d5188d4d3432d7264d9d955a069173cf4 Mon Sep 17 00:00:00 2001 From: Matthias Viehweger Date: Mon, 6 May 2024 16:08:40 +0200 Subject: [PATCH 3/3] Shorten the label-columns to not blow the row-limit again --- db/migrate/20221124094837_add_address_labels_to_people.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20221124094837_add_address_labels_to_people.rb b/db/migrate/20221124094837_add_address_labels_to_people.rb index 07484601..2775475a 100644 --- a/db/migrate/20221124094837_add_address_labels_to_people.rb +++ b/db/migrate/20221124094837_add_address_labels_to_people.rb @@ -12,7 +12,7 @@ class AddAddressLabelsToPeople < ActiveRecord::Migration[6.1] billing_course).freeze def change ADDRESS_TYPES.each do |concern| - add_column :people, "#{concern}_label", :string + add_column :people, "#{concern}_label", :string, limit: 20 # was 255, the varchar-default end end end