Skip to content

Commit

Permalink
Merge pull request #290 from hitobito/#1919_abo-filter
Browse files Browse the repository at this point in the history
PERSON: Abo-Filter nach Alter und Sprache
  • Loading branch information
carlobeltrame authored Dec 21, 2023
2 parents 55a7d6a + e825a8b commit 7afcef4
Show file tree
Hide file tree
Showing 26 changed files with 124 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/domain/pbs/export/tabular/people/households_full.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Pbs::Export::Tabular::People
class HouseholdsFull < Export::Tabular::People::Households
ADDITIONAL_PERSON_ATTRIBUTES =
%i[correspondence_language prefers_digital_correspondence kantonalverband_id id
%i[language prefers_digital_correspondence kantonalverband_id id
layer_group_id company_name company].freeze

def person_attributes
Expand Down
8 changes: 4 additions & 4 deletions app/domain/pbs/export/tabular/people/participation_nds_row.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2012-2022, Pfadibewegung Schweiz. This file is part of
# Copyright (c) 2012-2023, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs 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_pbs.
Expand All @@ -9,11 +9,11 @@ module Pbs::Export::Tabular::People::ParticipationNdsRow
extend ActiveSupport::Concern

included do
alias_method_chain :first_language, :correspondence_language
alias_method_chain :first_language, :language
end

def first_language_with_correspondence_language
lang = entry.correspondence_language.presence
def first_language_with_language
lang = entry.language.presence
lang ? lang.upcase : 'DE'
end
end
2 changes: 1 addition & 1 deletion app/domain/pbs/export/tabular/people/people_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize_with_kv(list)

def person_attributes_with_title
person_attributes_without_title +
[:title, :salutation, :correspondence_language, :prefers_digital_correspondence,
[:title, :salutation, :language, :prefers_digital_correspondence,
:kantonalverband_id, :id, :layer_group_id]
end
end
Expand Down
1 change: 0 additions & 1 deletion app/domain/pbs/people/minimizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def minimize_person_attrs
:town,
:zip_code,
:title,
:correspondence_language,
:language,
:salutation,
:grade_of_school,
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/pbs/contact_attrs/control_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def initialize_with_required_contact_attrs(form, event)
return if @event.persisted? || @event.event.type != 'Event::Camp'

@event.event.required_contact_attrs += %w(address zip_code town country gender birthday
nationality_j_s ahv_number
correspondence_language)
nationality_j_s ahv_number language)
end

def radio_buttons_with_supercamp_flag(*args)
Expand Down
11 changes: 2 additions & 9 deletions app/helpers/people_pbs_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8
# frozen_string_literal: true

# Copyright (c) 2012-2014, Pfadibewegung Schweiz. This file is part of
# Copyright (c) 2012-2023, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs 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_pbs.
Expand All @@ -11,11 +11,4 @@ def format_person_salutation(person)
person.salutation_value
end

def format_correspondence_language(person)
lang = person.correspondence_language
if lang
Settings.application.languages.to_hash.with_indifferent_access[lang]
end
end

end
2 changes: 1 addition & 1 deletion app/jobs/event/camp_reminder_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def camps_to_remind
def send_reminder(camp)
recipients = fetch_recipients(camp)
recipients.each do |person|
I18n.locale = person.correspondence_language.presence || I18n.default_locale
I18n.locale = person.language
Event::CampMailer.remind(camp, person).deliver_now
end
camp.update_column(:camp_reminder_sent, true) if recipients.present?
Expand Down
2 changes: 1 addition & 1 deletion app/models/pbs/event/participation_contact_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Pbs::Event::ParticipationContactData

included do
Event::ParticipationContactData.contact_attrs << :title << :salutation <<
:correspondence_language << :grade_of_school << :entry_date << :leaving_date
:language << :grade_of_school << :entry_date << :leaving_date

delegate(*Event::ParticipationContactData.contact_attrs, to: :person)
end
Expand Down
8 changes: 1 addition & 7 deletions app/models/pbs/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module Pbs::Person
extend ActiveSupport::Concern

included do
Person::PUBLIC_ATTRS << :title << :salutation << :correspondence_language <<
Person::PUBLIC_ATTRS << :title << :salutation << :language <<
:prefers_digital_correspondence << :kantonalverband_id
Person::ADDRESS_ATTRS << "prefers_digital_correspondence"

Expand All @@ -72,12 +72,6 @@ module Pbs::Person
inclusion: { in: ->(_) { Salutation.available.keys },
allow_blank: true }

validates :correspondence_language,
inclusion: { in: lambda do |_|
Settings.application.languages.to_hash.keys.collect(&:to_s)
end,
allow_blank: true }

validates :entry_date, :leaving_date,
timeliness: { type: :date, allow_blank: true, before: Date.new(9999, 12, 31) }

Expand Down
4 changes: 3 additions & 1 deletion app/serializers/pbs/mailing_list_subscriber_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Pbs::MailingListSubscriberSerializer

included do
schema do
property :correspondence_language, item.correspondence_language
# correspondence_language is deprecated and could be removed in the future
property :correspondence_language, item.language
property :language, item.language
property :kantonalverband_short_name, item.kantonalverband.short_name
end
end
Expand Down
5 changes: 4 additions & 1 deletion app/serializers/pbs/person_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ module Pbs::PersonSerializer

included do
extension(:details) do |_|
map_properties :pbs_number, :salutation_value, :correspondence_language,
map_properties :pbs_number, :salutation_value, :language,
:prefers_digital_correspondence, :grade_of_school, :entry_date, :leaving_date

# correspondence_language is deprecated and could be removed in the future
property :correspondence_language, item.language

if context[:group].present?
property :has_siblings_in_layer, item.siblings_in_context(context[:group]).any?
end
Expand Down
1 change: 0 additions & 1 deletion app/views/csv_imports/_special_fields_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
-# https://github.com/hitobito/hitobito_pbs.
= csv_field_documentation(:salutation, Salutation.available)
= csv_field_documentation(:correspondence_language, Settings.application.languages.to_hash)
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
= f.labeled_input_field :title
- if entry.show_attr?(:salutation)
= f.labeled_collection_select :salutation, Salutation.available, :first, :last, { include_blank: "" }, class: 'form-select form-select-sm'
- if entry.show_attr?(:correspondence_language)
= f.labeled_collection_select(:correspondence_language,
Settings.application.languages.to_hash,
:first,
:last,
{ prompt: true },
class: 'form-select form-select-sm')
- if entry.show_attr?(:grade_of_school)
= f.labeled_input_field :grade_of_school, help_inline: t('people.fields_pbs.non_automatic_field')

Expand Down
3 changes: 1 addition & 2 deletions app/views/people/_details_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
-# or later. See the COPYING file at the top-level directory or at
-# https://github.com/hitobito/hitobito_pbs.
= render_attrs(entry, :pbs_number, :salutation, :correspondence_language,
:grade_of_school)
= render_attrs(entry, :pbs_number, :salutation, :language, :grade_of_school)

%dl.dl-horizontal
- sibling_context = parent.try(:layer_group) || parent
Expand Down
7 changes: 0 additions & 7 deletions app/views/people/_fields_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
= field_set_tag do
= f.labeled_input_field :title
= f.labeled_collection_select :salutation, Salutation.available, :first, :last, { include_blank: "" }, class: 'form-select form-select-sm'
= f.labeled_collection_select(:correspondence_language,
Settings.application.languages.to_hash,
:first,
:last,
{ prompt: true },
class: 'form-select form-select-sm')

= f.labeled_input_field :grade_of_school, help_inline: t('.non_automatic_field')

= field_set_tag do
Expand Down
1 change: 0 additions & 1 deletion config/locales/models.pbs.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,6 @@ de:
entry_date: Eintrittsdatum
leaving_date: Austrittsdatum
j_s_number: J+S Personennummer
correspondence_language: Korrespondenzsprache
has_siblings_in_layer: Geschwister in der Ebene
kv: Kantonalverband
prefers_digital_correspondence: Digitale Korrespondenz bevorzugt
Expand Down
1 change: 0 additions & 1 deletion config/locales/models.pbs.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,6 @@ fr:
entry_date: Membre depuis
leaving_date: Date de départ
j_s_number: N° personnel J+S
correspondence_language: Langue de correspondance
kv: Assocation cantonale
prefers_digital_correspondence: Préfère la correspondance numérique
group:
Expand Down
1 change: 0 additions & 1 deletion config/locales/models.pbs.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,6 @@ it:
entry_date: Data d'entrata
leaving_date: Data d'uscita
j_s_number: Numero personale G+S
correspondence_language: Lingua di corrispondenza
kv: Associazione cantonale
prefers_digital_correspondence: Si preferisce la corrispondenza digitale
group:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs 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_pbs.

class ReplaceCorrespondenceLanguageWithCoreLanguage < ActiveRecord::Migration[6.1]
CANTONS_LANGUAGE = {
# de: [:ag, :ai, :ar, :be, :bl, :bs, :gl, :gr, :lu, :nw, :ow, :sg, :sh, :so, :sz, :tg, :ur, :zg, :zh],
fr: [:fr, :ge, :ju, :ne, :vd, :vs],
it: [:ti]
}.freeze

def up
Person.where.not(correspondence_language: nil).update_all("language = correspondence_language")
Person.where(correspondence_language: nil).find_each do |person|
person.update!(language: infer_person_language(person))
end

remove_column :people, :correspondence_language, :string, limit: 5
end

def down
add_column :people, :correspondence_language, :string, limit: 5
Person.update_all("correspondence_language = language")
end

def infer_person_language(person)
return person.language if person.language.present?
return person.correspondence_language if person.try(:correspondence_language).present?

kv = person.send(:find_kantonalverband)&.becomes(Group::Kantonalverband)
canton = kv&.kantonalverband_cantons&.first&.to_s&.downcase&.to_sym
CANTONS_LANGUAGE.find { |language, cantons| cantons.include?(canton) }&.first || :de
end
end
2 changes: 1 addition & 1 deletion lib/hitobito_pbs/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Wagon < Rails::Engine

### controllers
PeopleController.permitted_attrs += [:salutation, :title, :grade_of_school, :entry_date,
:leaving_date, :j_s_number, :correspondence_language,
:leaving_date, :j_s_number,
:prefers_digital_correspondence]
GroupsController.permitted_attrs += [:hostname]
Event::KindsController.permitted_attrs += [:documents_text, :campy, :can_have_confirmations,
Expand Down
6 changes: 3 additions & 3 deletions spec/domain/export/tabular/people/households_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
context 'header' do
it 'includes name, address attributes and layer group columns' do
expect(exporter.attributes).to eq [:salutation, :name, :address, :zip_code, :town,
:country, :layer_group, :correspondence_language,
:country, :layer_group, :language,
:prefers_digital_correspondence, :kantonalverband_id,
:id, :layer_group_id, :company_name, :company]
end
Expand All @@ -35,7 +35,7 @@
nil,
nil,
"Pfadibewegung Schweiz",
nil,
"de",
"nein",
"CH",
337180612,
Expand Down Expand Up @@ -68,7 +68,7 @@
nil,
nil,
"Pfadibewegung Schweiz",
nil,
"de",
"ja",
"CH",
337180612,
Expand Down
11 changes: 3 additions & 8 deletions spec/domain/export/tabular/people/participation_nds_row_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2012-2022, Pfadibewegung Schweiz. This file is part of
# Copyright (c) 2012-2023, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs 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_pbs.
Expand All @@ -13,13 +13,8 @@

let(:row) { described_class.new(participation) }

context 'with correspondence language' do
let(:person) { Fabricate(:person, correspondence_language: 'it') }
context 'with language' do
let(:person) { Fabricate(:person, language: 'it') }
it { expect(row.fetch(:first_language)).to eq 'IT' }
end

context 'without correspondence language' do
let(:person) { Fabricate(:person, correspondence_language: nil) }
it { expect(row.fetch(:first_language)).to eq 'DE' }
end
end
2 changes: 1 addition & 1 deletion spec/domain/export/tabular/people/people_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let(:person) { people(:bulei) }
let(:simple_headers) do
%w(Vorname Nachname Pfadiname Firmenname Firma Haupt-E-Mail Adresse PLZ Ort Land
Hauptebene Rollen Titel Anrede Korrespondenzsprache Digitale\ Korrespondenz\ bevorzugt
Hauptebene Rollen Titel Anrede Sprache Digitale\ Korrespondenz\ bevorzugt
Kantonalverband Id) << 'Id der Hauptebene'
end
let(:list) { Person.where(id: person) }
Expand Down
2 changes: 0 additions & 2 deletions spec/domain/people/minimizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
town: 'Bern',
zip_code: '3007',
title: 'Herr',
correspondence_language: 'it',
language: 'it',
salutation: 'lieber_vorname',
grade_of_school: 8,
Expand Down Expand Up @@ -109,7 +108,6 @@ def nullify_attrs
:town,
:zip_code,
:title,
:correspondence_language,
:salutation,
:grade_of_school,
:entry_date,
Expand Down
59 changes: 59 additions & 0 deletions spec/migrations/replace_correspondence_language_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs 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_pbs.

require 'spec_helper'
require Rails.root.join('../hitobito_pbs/db/migrate/20230915105810_replace_correspondence_language_with_core_language.rb')

describe ReplaceCorrespondenceLanguageWithCoreLanguage do
subject(:migration) { described_class.new.tap { |migration| migration.verbose = false } }

describe '#infer_person_language' do
let(:person) { Fabricate(:person) }
let(:language) { nil }
let(:correspondence_language) { nil }
subject(:infer_person_language) { migration.infer_person_language(person) }

before do
allow(person).to receive(:language).and_return(language)
allow(person).to receive(:correspondence_language).and_return(correspondence_language)
end

context 'with existing language' do
let(:language) { :test }
it { expect(infer_person_language).to eq(language) }
end

context 'with existing correspondance_language' do
let(:correspondence_language) { :test }
it { expect(infer_person_language).to eq(:test) }
end

context 'with language from KV' do
let(:person) { Fabricate(Group::Kantonalverband::Coach.name, group: kv).person }
let(:kv) do
Fabricate(Group::Kantonalverband.name, parent: groups(:bund)).tap do |kv|
kv.kantonalverband_cantons.create!(canton: canton)
end
end

context 'with KV ti' do
let(:canton) { :ti }
it { expect(infer_person_language).to eq(:it) }
end

context 'with KV ju' do
let(:canton) { :ju }
it { expect(infer_person_language).to eq(:fr) }
end

context 'with KV be' do
let(:canton) { :be }
it { expect(infer_person_language).to eq(:de) }
end
end
end
end
Loading

0 comments on commit 7afcef4

Please sign in to comment.