summaryrefslogtreecommitdiff
path: root/app/models/notification_setting.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-07-07 12:41:48 +0100
committerSean McGivern <sean@gitlab.com>2016-07-07 20:49:17 +0100
commitea25e0918b77c2345585a968fbf5b73bb544aac7 (patch)
tree372a006af02dd94a7dcc958007e7c0335b4cac42 /app/models/notification_setting.rb
parent3c89a788c795fba2b050a0af0d8261e302d8cded (diff)
downloadgitlab-ce-ea25e0918b77c2345585a968fbf5b73bb544aac7.tar.gz
Exclude projects pending delete from notifications
If the Sidekiq job fails for some reason, a project can be 'stuck' pending deletion. The project can't be viewed, so it shouldn't be available through the notification settings association as this will throw an exception when we try to show the link.
Diffstat (limited to 'app/models/notification_setting.rb')
-rw-r--r--app/models/notification_setting.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index d41fc7073c6..121b598b8f3 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -5,6 +5,7 @@ class NotificationSetting < ActiveRecord::Base
belongs_to :user
belongs_to :source, polymorphic: true
+ belongs_to :project, foreign_key: 'source_id'
validates :user, presence: true
validates :level, presence: true
@@ -13,7 +14,13 @@ class NotificationSetting < ActiveRecord::Base
allow_nil: true }
scope :for_groups, -> { where(source_type: 'Namespace') }
- scope :for_projects, -> { where(source_type: 'Project') }
+
+ # Exclude projects not included by the Project model's default scope (those that are
+ # pending delete).
+ #
+ scope :for_projects, -> do
+ includes(:project).references(:projects).where(source_type: 'Project').where.not(projects: { id: nil })
+ end
EMAIL_EVENTS = [
:new_note,