diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-07 12:41:48 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-07-07 20:49:17 +0100 |
commit | ea25e0918b77c2345585a968fbf5b73bb544aac7 (patch) | |
tree | 372a006af02dd94a7dcc958007e7c0335b4cac42 /app | |
parent | 3c89a788c795fba2b050a0af0d8261e302d8cded (diff) | |
download | gitlab-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')
-rw-r--r-- | app/models/notification_setting.rb | 9 |
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, |