diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index e698aa54eb..aa4ef2b00f 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -209,6 +209,10 @@ def update @person.comments.select(&:new_record?).each { |c| c.created_by = current_user; c.updated_by = current_user } @person.comments.select { |c| c.persisted? && c.body_changed? }.each { |c| c.updated_by = current_user } + # Inline-logged notifications are addressed to the person. + recipient_email = @person.preferred_email.presence || "n/a" + @person.notifications.select(&:new_record?).each { |n| n.recipient_email = recipient_email } + if @person.save assign_associations(@person) if params.dig(:person, :category_ids) redirect_to person_update_return_path, notice: "Person was successfully updated." @@ -488,6 +492,7 @@ def person_params :_destroy ], comments_attributes: [ :id, :topic, :body, :flagged, :_destroy ], + notifications_attributes: [ :channel, :sender_id, :email_subject, :email_body_text, :noticeable_type, :noticeable_id ] ) end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 34284acee7..a510936911 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -60,6 +60,7 @@ class Notification < ApplicationRecord NOTICEABLE_TYPES = %w[ EventRegistration FormSubmission + Person Report StoryIdea User diff --git a/app/models/person.rb b/app/models/person.rb index 424dd07d15..846ea260f9 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -17,6 +17,7 @@ class Person < ApplicationRecord has_many :comments, -> { newest_first }, as: :commentable, dependent: :destroy has_many :contact_methods, as: :contactable, dependent: :destroy has_many :categorizable_items, inverse_of: :categorizable, as: :categorizable, dependent: :destroy + has_many :notifications, as: :noticeable, dependent: :destroy has_many :sectorable_items, as: :sectorable, dependent: :destroy has_many :stories_as_spotlighted_facilitator, inverse_of: :spotlighted_facilitator, class_name: "Story", dependent: :restrict_with_error @@ -69,6 +70,7 @@ class Person < ApplicationRecord accepts_nested_attributes_for :affiliations, allow_destroy: true, reject_if: proc { |attrs| attrs["organization_id"].blank? } accepts_nested_attributes_for :comments, allow_destroy: true, reject_if: proc { |attrs| attrs["body"].blank? } + accepts_nested_attributes_for :notifications, reject_if: proc { |attrs| attrs["email_subject"].blank? } # Search Cop include SearchCop diff --git a/app/views/event_registrations/_notifications.html.erb b/app/views/event_registrations/_notifications.html.erb index c673c4a96a..0d1e3f2a84 100644 --- a/app/views/event_registrations/_notifications.html.erb +++ b/app/views/event_registrations/_notifications.html.erb @@ -48,11 +48,11 @@ <%# Inline add — manual log entries, saved with the registration form. %>
No notifications for this person yet.
+ <% end %> + + <%# Inline add — manual log entries, saved with the person form. %> +