hitobito-kjv/app/domain/kjv/vorstand_email.rb
KJV Bautzen f301d72572 Nur Vorstandsadresse als Kontakt bei Kursen und Anlässen, Version 0.4.1 🤖
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 18:03:07 +02:00

40 lines
1.5 KiB
Ruby

# frozen_string_literal: true
# Copyright (c) 2026, Kreisjagdverband Bautzen e.V. This file is part of
# hitobito_kjv and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory.
# Öffentliche Vorstandsadresse einer Person: weitere E-Mail mit der Kategorie "Vorstand".
#
# Bei Kursen und Anlässen wird für die Kontaktperson ausschließlich diese Adresse
# angezeigt bzw. weitergegeben (Kursseite, externe Anmeldung, Kalender-Feed,
# Teilnahmebestätigung, Mails). Die private Haupt-E-Mail bleibt verborgen. Hat die
# Kontaktperson keine Vorstandsadresse, erscheint keine E-Mail.
module Kjv::VorstandEmail
CATEGORY_KEY = "vorstand"
module_function
def for(person)
return if person.nil?
person = person.object if person.respond_to?(:object) # Decorator
person.additional_emails.includes(:category)
.find { |email| email.category&.key == CATEGORY_KEY }&.email.presence
end
# Für Migration und Seed
def ensure_category!
ContactAccountCategory.find_or_create_by!(
key: CATEGORY_KEY,
contact_account_type: AdditionalEmail.sti_name,
contactable_type: Person.sti_name
) do |category|
category.name = "Vorstand"
category.unique_per_contactable = true
category.position = ContactAccountCategory
.where(contact_account_type: AdditionalEmail.sti_name, contactable_type: Person.sti_name)
.maximum(:position).to_i + 1
end
end
end