about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-10-27 02:10:54 +0200
committerGitHub <noreply@github.com>2022-10-27 02:10:54 +0200
commitd2eb726962187226c85ef7f2ee1886cb0767bbd1 (patch)
tree95a80698929ee9d779491cbe6987e1ae2d87d5f5
parentf6bcf86caf6a88b020c435bfab4c1ba8d70dd6db (diff)
Fix notifications about deleted reports not being also deleted (#19475)
* Fix notifications about deleted reports not being also deleted

* Fix notification with empty report crashing web UI

Fix #18909
-rw-r--r--app/javascript/mastodon/features/notifications/components/notification.js4
-rw-r--r--app/models/report.rb1
2 files changed, 5 insertions, 0 deletions
diff --git a/app/javascript/mastodon/features/notifications/components/notification.js b/app/javascript/mastodon/features/notifications/components/notification.js
index 0af71418c..5974e378e 100644
--- a/app/javascript/mastodon/features/notifications/components/notification.js
+++ b/app/javascript/mastodon/features/notifications/components/notification.js
@@ -372,6 +372,10 @@ class Notification extends ImmutablePureComponent {
   renderAdminReport (notification, account, link) {
     const { intl, unread, report } = this.props;
 
+    if (!report) {
+      return null;
+    }
+
     const targetAccount = report.get('target_account');
     const targetDisplayNameHtml = { __html: targetAccount.get('display_name_html') };
     const targetLink = <bdi><Permalink className='notification__display-name' href={targetAccount.get('url')} title={targetAccount.get('acct')} to={`/@${targetAccount.get('acct')}`} dangerouslySetInnerHTML={targetDisplayNameHtml} /></bdi>;
diff --git a/app/models/report.rb b/app/models/report.rb
index 42c869dd4..525d22ad5 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -33,6 +33,7 @@ class Report < ApplicationRecord
   belongs_to :assigned_account, class_name: 'Account', optional: true
 
   has_many :notes, class_name: 'ReportNote', foreign_key: :report_id, inverse_of: :report, dependent: :destroy
+  has_many :notifications, as: :activity, dependent: :destroy
 
   scope :unresolved, -> { where(action_taken_at: nil) }
   scope :resolved,   -> { where.not(action_taken_at: nil) }