From b87dd4f1b2beeb07cc59411facc070f4cbc728f5 Mon Sep 17 00:00:00 2001 From: Jakub Motycka Date: Tue, 13 Sep 2022 15:10:10 +0200 Subject: [PATCH 1/2] feat: relatives for volunteers --- app/models/volunteer.rb | 7 +++++++ app/policies/volunteer_policy.rb | 3 ++- app/views/relatives/_form.html.slim | 2 +- app/views/relatives/_show.html.slim | 2 +- app/views/volunteers/_form.html.slim | 3 +++ app/views/volunteers/show.html.slim | 2 ++ config/locales/de.yml | 2 ++ ...913105622_add_family_in_household_to_volunteers.rb | 5 +++++ db/schema.rb | 9 ++++++--- test/system/volunteers_test.rb | 11 +++++++++++ 10 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20220913105622_add_family_in_household_to_volunteers.rb diff --git a/app/models/volunteer.rb b/app/models/volunteer.rb index d6b9fd3e2..7b0eeede1 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 405784cbc..d3b3faf7a 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 57bd1179c..1f3e33980 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 08d5916b7..0b2fcf026 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 9081893c7..b36246269 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 3bb83bace..9f14b38a7 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 6d9ed0c04..ad54dba35 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1199,6 +1199,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 000000000..2def90d38 --- /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 bedb84a15..8bb7d9395 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_07_21_113714) 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" @@ -140,7 +140,7 @@ ActiveRecord::Schema.define(version: 2022_07_21_113714) do t.string "trial_period_end" t.string "duration" t.string "special_agreement" - t.text "agreement_text", default: "Freiwillige beachten folgende Grundsätze während ihres Einsatzes in der AOZ:\n* Verhaltenskodex für Freiwillige\n* Rechte und Pflichten für Freiwillige\n* AOZ Leitlinien Praktische Integrationsarbeit\n\nAllenfalls auch\n* Verpflichtungserklärung zum Schutz der unbegleiteten minderjährigen Asylsuchenden (MNA)\n* Niederschwellige Gratis-Deutschkurse: Informationen für freiwillige Kursleitende\n" + t.text "agreement_text", default: "Freiwillige beachten folgende Grundsätze während ihres Einsatzes in der AOZ:\n* Verhaltenskodex für Freiwillige\n* Rechte und Pflichten für Freiwillige\n\nBei Zusammenarbeit mit Minderjährigen:\n* Verpflichtungserklärung zum Schutz der unbegleiteten minderjährigen Asylsuchenden (MNA)\n" t.string "pdf_file_name" t.string "pdf_content_type" t.integer "pdf_file_size" @@ -148,6 +148,8 @@ ActiveRecord::Schema.define(version: 2022_07_21_113714) do t.bigint "submitted_by_id" t.bigint "reactivated_by_id" t.datetime "reactivated_at" + t.integer "volunteer_constellation" + t.integer "client_constellation" t.index ["client_id"], name: "index_assignments_on_client_id" t.index ["creator_id"], name: "index_assignments_on_creator_id" t.index ["period_end"], name: "index_assignments_on_period_end" @@ -447,7 +449,7 @@ ActiveRecord::Schema.define(version: 2022_07_21_113714) do t.string "happens_at" t.string "frequency" t.string "trial_period_end" - t.text "agreement_text", default: "Freiwillige beachten folgende Grundsätze während ihres Einsatzes in der AOZ:\n* Verhaltenskodex für Freiwillige\n* Rechte und Pflichten für Freiwillige\n* AOZ Leitlinien Praktische Integrationsarbeit\n\nAllenfalls auch\n* Verpflichtungserklärung zum Schutz der unbegleiteten minderjährigen Asylsuchenden (MNA)\n* Niederschwellige Gratis-Deutschkurse: Informationen für freiwillige Kursleitende\n" + t.text "agreement_text", default: "Freiwillige beachten folgende Grundsätze während ihres Einsatzes in der AOZ:\n* Verhaltenskodex für Freiwillige\n* Rechte und Pflichten für Freiwillige\n\nBei Zusammenarbeit mit Minderjährigen:\n* Verpflichtungserklärung zum Schutz der unbegleiteten minderjährigen Asylsuchenden (MNA)\n" t.string "pdf_file_name" t.string "pdf_content_type" t.integer "pdf_file_size" @@ -924,6 +926,7 @@ ActiveRecord::Schema.define(version: 2022_07_21_113714) 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 f97efb47b..176535ec1 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') -- GitLab From 85f180263d0619d555a7d77658ae2fc7f381276b Mon Sep 17 00:00:00 2001 From: Jakub Motycka Date: Tue, 13 Sep 2022 17:55:04 +0200 Subject: [PATCH 2/2] fix: update schema.rb --- db/schema.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/schema.rb b/db/schema.rb index 8bb7d9395..e5dab626a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -86,6 +86,8 @@ ActiveRecord::Schema.define(version: 2022_09_13_105622) do t.bigint "submitted_by_id" t.bigint "reactivated_by_id" t.datetime "reactivated_at" + t.integer "volunteer_constellation" + t.integer "client_constellation" t.index ["assignment_id"], name: "index_assignment_logs_on_assignment_id" t.index ["client_id"], name: "index_assignment_logs_on_client_id" t.index ["creator_id"], name: "index_assignment_logs_on_creator_id" -- GitLab