diff --git a/app/models/volunteer.rb b/app/models/volunteer.rb index d6b9fd3e278885e119020ece5d783b5b6b1c59e3..7b0eeede1518ea6e8070a412ae9d787b0088c008 100644 --- a/app/models/volunteer.rb +++ b/app/models/volunteer.rb @@ -106,6 +106,9 @@ class Volunteer < ApplicationRecord has_one_attached :avatar + has_many :relatives, as: :relativeable, dependent: :destroy + accepts_nested_attributes_for :relatives, allow_destroy: true, reject_if: :reject_relatives? # reject to skip validations + # Validations # validates :avatar, content_type: ext_mimes(:jpg, :gif, :png, :tif, :webp) @@ -793,4 +796,8 @@ class Volunteer < ApplicationRecord user.restore recursive: true if user_id.present? end end + + def reject_relatives? + !family_in_household? + end end diff --git a/app/policies/volunteer_policy.rb b/app/policies/volunteer_policy.rb index 405784cbc7eb864745d9501f5d94bf81c9607e95..d3b3faf7a76c37ce8ae4d52c781d157c3370060e 100644 --- a/app/policies/volunteer_policy.rb +++ b/app/policies/volunteer_policy.rb @@ -17,7 +17,8 @@ class VolunteerPolicy < ApplicationPolicy def permitted_attributes attributes = [volunteer_attributes, :bank, :iban, :waive, :acceptance, :take_more_assignments, - :external, :comments, :additional_comments, :working_percent] + :external, :comments, :additional_comments, :working_percent, :family_in_household, + relatives_attributes] attributes << [:department_id, :secondary_department_id] if superadmin_or_department_manager? attributes << [:entry_source] if superadmin? attributes << :staffomatic_user_id if superadmin? diff --git a/app/views/relatives/_form.html.slim b/app/views/relatives/_form.html.slim index 57bd1179ce5cfc8d24c4d303e59805c91846c915..1f3e33980172346359468fd64da7e82edba0ab6c 100644 --- a/app/views/relatives/_form.html.slim +++ b/app/views/relatives/_form.html.slim @@ -1,5 +1,5 @@ fieldset#relatives_fieldset - legend= t('relatives') + legend= defined?(title) ? title : t('relatives') = f.input :family_in_household, as: :radio_buttons, label: false, input_html: { class: 'client-family-in-household' } div.relatives-form - if defined?(subtitle) diff --git a/app/views/relatives/_show.html.slim b/app/views/relatives/_show.html.slim index 08d5916b78af43e30e4eff9bd1d148e86012cd67..0b2fcf0269fd466e1167162e6965e85685ba4466 100644 --- a/app/views/relatives/_show.html.slim +++ b/app/views/relatives/_show.html.slim @@ -1,5 +1,5 @@ tr - td= t('relatives') + td= defined?(title) ? title : t('relatives') td - if relative.relatives.any? dl.dl-horizontal diff --git a/app/views/volunteers/_form.html.slim b/app/views/volunteers/_form.html.slim index 9081893c7b60d71303b6afcf5027570ec5646aa3..b362462692aa461299ae3eec57d85f6a8c482b31 100644 --- a/app/views/volunteers/_form.html.slim +++ b/app/views/volunteers/_form.html.slim @@ -91,6 +91,9 @@ = checkbox_toggle_collapse(f, :experience, '#experience-desc', tabindex: 16) .col-xs-12.collapse#experience-desc = f.input :volunteer_experience_desc, input_html: { tabindex: 17 } + .row + .col-xs-12 + = render 'relatives/form', f: f, relative: f.object, title: t_attr(:family, Volunteer) .col-xs-12.col-md-6 = render 'contacts/phone_fields', f: c, tabindex_start: 6 diff --git a/app/views/volunteers/show.html.slim b/app/views/volunteers/show.html.slim index 3bb83bace76ede4228e2dfe5c6f5ffaef7681c99..9f14b38a7c6b008eab844ba411b992f7cdb92b89 100644 --- a/app/views/volunteers/show.html.slim +++ b/app/views/volunteers/show.html.slim @@ -54,6 +54,8 @@ h2.small Persönlicher Hintergrund = render 'language_skills/show', speaker: @volunteer + = render 'relatives/show', relative: @volunteer, title: t_attr(:family, Volunteer) + tr td= t_attr(:working_percent) td #{@volunteer.working_percent}% diff --git a/config/locales/de.yml b/config/locales/de.yml index f04334630454573d0ec5d6ca76fbc74aac8b69b7..9fc9da41df97910068821e13925ec4605a9b3b9f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1215,6 +1215,8 @@ de: inactive: Sucht neuen Einsatz registered: Interessiert resigned: Beendet + relatives: + relation: *id-relations placeholders: trial_period: notes: Notizen diff --git a/db/migrate/20220913105622_add_family_in_household_to_volunteers.rb b/db/migrate/20220913105622_add_family_in_household_to_volunteers.rb new file mode 100644 index 0000000000000000000000000000000000000000..2def90d38b0b8db359240845b699a913b6ac5678 --- /dev/null +++ b/db/migrate/20220913105622_add_family_in_household_to_volunteers.rb @@ -0,0 +1,5 @@ +class AddFamilyInHouseholdToVolunteers < ActiveRecord::Migration[6.1] + def change + add_column :volunteers, :family_in_household, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 5f87628227f3628ff6c07af93d086933202f639e..e5dab626adc8a5dd2635bf0ca64455bc640d946e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_09_13_072134) do +ActiveRecord::Schema.define(version: 2022_09_13_105622) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -928,6 +928,7 @@ ActiveRecord::Schema.define(version: 2022_09_13_072134) do t.boolean "staffomatic_update_required", default: true t.text "how_have_you_heard_of_aoz_flyer" t.text "how_have_you_heard_of_aoz_ds_other" + t.boolean "family_in_household", default: false t.index ["acceptance"], name: "index_volunteers_on_acceptance" t.index ["accepted_at"], name: "index_volunteers_on_accepted_at" t.index ["accepted_by_id"], name: "index_volunteers_on_accepted_by_id" diff --git a/test/system/volunteers_test.rb b/test/system/volunteers_test.rb index f97efb47be2adba55e9d0fd23731bbb6f93fe222..176535ec1413f3dfa842d0ddbd070a3b7c771ad1 100644 --- a/test/system/volunteers_test.rb +++ b/test/system/volunteers_test.rb @@ -48,6 +48,17 @@ class VolunteersTest < ApplicationSystemTestCase with: 'asdf' fill_in 'Welche sind Ihre wichtigsten Freizeitinteressen?', with: 'asdf' + + within '#relatives_fieldset' do + choose('Ja') + end + within '#relatives' do + fill_in 'Vorname', with: 'asdf' + fill_in 'Nachname', with: 'asdf' + select('2001', from: 'Geburtsdatum') + select('Onkel', from: 'Verwandtschaftsbeziehung') + end + check('Training') check('German Course') check('Other Offer')