-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement phone number changes (#1563)
* in SAC wagon, Person and Group can have only two phone numbers with distinct labels * valid labels are "mobile" and "landline" * form fields are fixed, not dynamic as in core * public flag is not editable * OIDC claim contains both numbers * Sign-up wizards fill the phone_number with label "mobile"
- Loading branch information
1 parent
863a054
commit 01d5a53
Showing
40 changed files
with
557 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2025, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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_sac_cas | ||
|
||
module AssignsSacPhoneNumbers | ||
extend ActiveSupport::Concern | ||
|
||
private | ||
|
||
def assign_attributes | ||
super | ||
mark_phone_numbers_for_destroy(entry) if action_name == "update" | ||
end | ||
|
||
# Mark phone numbers for destruction if they have an empty number field. | ||
# This allows removing phone numbers by clearing the number field in the form. | ||
def mark_phone_numbers_for_destroy(contactable) | ||
PhoneNumber.predefined_labels.each do |label| | ||
phone_number_assoc = :"phone_number_#{label}" | ||
phone_number_params = model_params[:"#{phone_number_assoc}_attributes"] | ||
|
||
if phone_number_params && phone_number_params[:number].blank? | ||
contactable.send(phone_number_assoc)&.mark_for_destruction | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2025, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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_sac_cas | ||
|
||
module SacCas::GroupsController | ||
extend ActiveSupport::Concern | ||
prepend AssignsSacPhoneNumbers | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2025, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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_sac_cas | ||
|
||
# In the sac wagon, we allow only a predefined set of phone numbers with their distinct label. | ||
# For those we always show the form fields, even if the records don't exist yet. | ||
# To simplify the form handling, we define a `has_one` association for each predefined number. | ||
module SacPhoneNumbers | ||
def self.prepended(base) | ||
PhoneNumber.predefined_labels.each do |label| | ||
phone_number_assoc = :"phone_number_#{label}" | ||
# rubocop:disable Rails/HasManyOrHasOneDependent (handled on has_many :phone_numbers) | ||
# rubocop:disable Rails/InverseOf (association not defined on opposite side) | ||
base.has_one phone_number_assoc, -> { where(label: label) }, | ||
class_name: "PhoneNumber", as: :contactable | ||
# rubocop:enable Rails/HasManyOrHasOneDependent, Rails/InverseOf | ||
|
||
base.accepts_nested_attributes_for phone_number_assoc, allow_destroy: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
- # Copyright (c) 2025, Schweizer Alpen-Club. This file is part of | ||
- # hitobito_sac_cas 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_sac_cas. | ||
|
||
%div.d-flex.flex-wrap.w-100.align-items-center | ||
%div.col-11.col-md-5.me-3.mb-1 | ||
= f.input_field(:number, placeholder: PhoneNumber.human_attribute_name(:number)) | ||
%div.col-11.col-md-4.d-flex.flex-row.me-3 | ||
= f.label(:number, f.object.translated_label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- # Copyright (c) 2025, Schweizer Alpen-Club. This file is part of | ||
- # hitobito_sac_cas 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_sac_cas. | ||
|
||
= f.labeled :phone_numbers do | ||
- PhoneNumber.predefined_labels.each do |label| | ||
- assoc = "phone_number_#{label}" | ||
- number = entry.send(assoc) || entry.send("build_#{assoc}") | ||
= f.fields_for assoc, number do |fields| | ||
- render 'contactable/phone_number_fields', f: fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.