Skip to content

Commit

Permalink
replace wagon specific correspondence_language with core language
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Sep 15, 2023
1 parent 6dd53f6 commit 24fa7a7
Show file tree
Hide file tree
Showing 23 changed files with 32 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
Expand Up @@ -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
lang ? lang.upcase : 'DE'
# TBD: move to youth wagon? https://github.com/hitobito/hitobito_youth/blob/3322054e2d64db19f8b049773e61f68e7f614546/app/domain/export/tabular/people/participation_nds_row.rb#L70
def first_language_with_language
entry.language.presence&.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
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
21 changes: 0 additions & 21 deletions app/helpers/people_pbs_helper.rb

This file was deleted.

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 @@ -73,12 +73,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
3 changes: 2 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,8 @@ module Pbs::MailingListSubscriberSerializer

included do
schema do
property :correspondence_language, item.correspondence_language
# TBD: keep this fields name?
property :correspondence_language, item.language
property :kantonalverband_short_name, item.kantonalverband.short_name
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/pbs/person_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Pbs::PersonSerializer

included do
extension(:details) do |_|
map_properties :pbs_number, :salutation_value, :correspondence_language,
# TBD: keep fields name?
map_properties :pbs_number, :salutation_value, :language,
:prefers_digital_correspondence, :grade_of_school, :brother_and_sisters,
:entry_date, :leaving_date
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: true }, class: 'span6'
- if entry.show_attr?(:correspondence_language)
= f.labeled_collection_select(:correspondence_language,
Settings.application.languages.to_hash,
:first,
:last,
{ prompt: true },
class: 'span6')
- 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
2 changes: 1 addition & 1 deletion app/views/people/_details_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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,
= render_attrs(entry, :pbs_number, :salutation, :language,
:grade_of_school, :brother_and_sisters)

= render_attrs(entry, :entry_date, :leaving_date)
6 changes: 0 additions & 6 deletions app/views/people/_fields_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
= field_set_tag do
= f.labeled_input_field :title
= f.labeled_collection_select :salutation, Salutation.available, :first, :last, { include_blank: true }, class: 'span6'
= f.labeled_collection_select(:correspondence_language,
Settings.application.languages.to_hash,
:first,
:last,
{ prompt: true },
class: 'span6')

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

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 @@ -1200,7 +1200,6 @@ de:
entry_date: Eintrittsdatum
leaving_date: Austrittsdatum
j_s_number: J+S Personennummer
correspondence_language: Korrespondenzsprache
brother_and_sisters: Geschwister
relations_to_tails: Geschwister
kv: Kantonalverband
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 @@ -1178,7 +1178,6 @@ fr:
entry_date: Membre depuis
leaving_date: Date de départ
j_s_number: N° personnel J+S
correspondence_language: Langue de correspondance
brother_and_sisters: Frères et soeurs
relations_to_tails: fratrie
kv: Assocation cantonale
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 @@ -1192,7 +1192,6 @@ it:
entry_date: Data d'entrata
leaving_date: Data d'uscita
j_s_number: Numero personale G+S
correspondence_language: Lingua di corrispondenza
brother_and_sisters: Fratelli
relations_to_tails: Fratelli
kv: Associazione cantonale
Expand Down
4 changes: 4 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ groups:
enabled: true
statistics:
enabled: false

# Not needed
person_language:
enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ReplaceCorrespondanceLanguageWithCoreLanguage < ActiveRecord::Migration[6.1]
def change
Person.where(correspondence_language: nil).update_all(correspondence_language: :de)
Person.update_all("language = correspondence_language")
remove_column :people, :correspondence_language, :string, limit: 5
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 @@ -112,7 +112,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, :brother_and_sisters]
Event::KindsController.permitted_attrs += [:documents_text, :campy, :can_have_confirmations,
:confirmation_name]
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
let(:row) { described_class.new(participation) }

context 'with correspondence language' do
let(:person) { Fabricate(:person, correspondence_language: 'it') }
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) }
let(:person) { Fabricate(:person, language: nil) }
it { expect(row.fetch(:first_language)).to eq 'DE' }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
end

expect(dom).to have_selector("select#event_participation_contact_data_salutation")
expect(dom).to have_selector("select#event_participation_contact_data_correspondence_language")

end

Expand Down

0 comments on commit 24fa7a7

Please sign in to comment.