Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to changed columns #159

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/controllers/insieme/event/participations_controller.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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"
Expand Down
22 changes: 19 additions & 3 deletions app/domain/abo_addresses/query.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand Down
18 changes: 14 additions & 4 deletions app/domain/export/tabular/abo_addresses/list.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.',
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/insieme/person.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20221124094837_add_address_labels_to_people.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions db/seeds/development/0_groups.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/event/participations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -64,7 +64,7 @@
end

%w(town
address
street

correspondence_course_salutation
correspondence_course_first_name
Expand Down
6 changes: 3 additions & 3 deletions spec/domain/export/csv/people_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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'))

Expand Down
5 changes: 3 additions & 2 deletions spec/domain/export/pdf/labels_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions spec/domain/export/tabular/abo_addresses/list_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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',
Expand Down
50 changes: 40 additions & 10 deletions spec/domain/import/person_importer_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -47,7 +48,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
Expand Down Expand Up @@ -75,7 +82,8 @@
Geburtsdatum: 'birthday',
Nummer: 'number',
Stadt: 'town',
Adresse: 'address',
Strasse: 'street',
Hausnummer: 'housenumber',
PLZ: 'zip_code',
Land: 'country',
Korrespondenzsprache: 'correspondence_language',
Expand All @@ -87,7 +95,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
Expand All @@ -111,7 +123,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
Expand All @@ -124,7 +142,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
Expand All @@ -149,7 +173,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
Expand Down
5 changes: 3 additions & 2 deletions spec/fabricators/person_fabricator.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,7 +13,8 @@

company false

address 'Teststrasse 23'
street 'Teststrasse'
housenumber '23'
zip_code '3007'
town 'Bern'
country 'CH'
Expand Down
Loading
Loading